Increase Microsoft Azure virtual machine system disk size

I have recently had the pleasure of extending the system disk of our Azure VM that was provisioned in 2013. Back then the Azure VM system disks could only be 30GIG. Fast forward 3 years and the windows folder reached 29GIG it was time to do something about it.

I found various solutions our there, some suggesting creating a new VM with a larger disk and then somehow allocating that to your existing VM, but thankfully before disappearing too deep into that rabbit hole, I found that you can accomplish the disk resize using Azure Powershell.

Before you start

Make backups of everything your possibly can before starting this. You are using these instructions at your own risk, and I suggest you make a dummy VM in azure and try it out on that first before doing it on anything in production.

You are going to need Powershell 5. I also recommend getting the latest version of Azure Powershell tools.Powershell version 5

You can download it from here If you have version 4 there seems to be a bug regarding selecting the VM from azure storage using the script I’m sharing below.

I used (along with a lot of stack overflow posts) this link as my main source. However it didn’t work out of the box, and I had to make some tweaks to get it working. I’m also going to advocate running the script line by line instead of as a whole. My reasons are mostly risk related, if you take care with each line you are less likely that a typo will result in you making a mistake doing such a “delicate” operation.

Here we go

Load all the required bits into the console

  • Open ‘Windows PowerShell ISE’. This is the default editor for PS1 files, so right clicking on any .ps1 file and clicking edit should open it.
  • Check your azure version using:
c:\> $PSVersionTable

command, and confirm you have version 5 as the PSVersion.

  • Use the following command to use a nice convenient gui to connect your Azure PowerShell console to your azure account:
c:\> Add-AzureAccount

You will see some output in PowerShell showing the account selected when you finished logging in.Select Azure Account

  • Next you want to select your azure subscription. Run :
c:\> $subscription = (Get-AzureSubscription).SubscriptionName | Out-GridView -Title "Select Azure Subscription" -PassThru

to get hold of your subscription object in the variable $subscription. It will bring up a gui list of your subscriptions, click OK at the bottom after selecting the relevant subscription.

  • Now we need to add the subscription to our current PowerShell console session. Run:
c:\> Select-AzureSubscription -SubscriptionName $subscription -Current

The console does not output anything, but you shouldn’t see an error 😉

  • Next you need to identify the storage account that your VM’s disk is associated with. You can do this in the Azure portal, on your VM’s dashboard, look at the disks section at the bottom in the VHD url for your disk, the first part of the url will be your storage account name.
  • We need to get hold of the storage account as a variable so we can add it to our console. Run :
c:\> $storageAccount = (Get-AzureStorageAccount).Label | Out-GridView -Title "Select Azure Storage Account" -PassThru

which will give you a list of your storage accounts to select so you can select the one you identified above, and click OK. (be patient it might take a couple of seconds). You may see a deprecation warning.

  • And then add it to your console session using :
c:\> Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $storageAccount
  • We also need a variable identifying the Azure vm. Run:
c:\> $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru

and select the relevant VM from the list and click OK.

Getting a reference to the disk

  • OK so we should have everything we need now. I’ve not been able to get the Out-GridView (this thing that lets you select things in the gui) to work for disks. So getting a little more manual here. Run:
c:\> Get-AzureDisk | Get-AzureDisk | Format-list  DiskName, AttachedTo, DiskSizeInGB, OS

which will output a list of all your disks into the console window.

  • You need to pick the one to resize. You need to make selection based on disk size AND RoleName, so you may have to remote into your VM if you have multiple disks connected to check this. Copy the DiskName (good old Cntrl+C).
  • Put it in a variable for later use: Run
c:\>  $disk = Get-AzureDisk -DiskName "PASTE YOUR VM NAME HERE"

Lets do this thing

  • You need to have your VM stopped(Deallocated) for this to work i.e. shut it down. I saved this till now so your VM could remain up and running as long as possible.
  • Here is the one little bit I run as a script. So click new in ‘Windows PowerShell ISE’ to create a blank file and copy the following script into it. Save it as ‘resize-azure-disk.ps1’
    # Specify new Data Disk size – must be larger than current size
    $diskName = $disk.DiskName
    do {

        $size = 
            Read-Host `
                -Prompt "New size in GB"

    } 

    until ( $size -gt $disk.LogicalDiskSizeInGB )

    # Stop and Deallocate VM prior to resizing data disk

    $vm `
        | Stop-AzureVM `
             -Force

    # Resize Data Disk to Larger Size

    Update-AzureDisk `
        -Label "$diskName" `
        -DiskName "$diskName" `
        -ResizedSizeInGB $size
  • Before the next step it is good to note that Azure notes the max size for operating system disks are 127GB. I made one of mine 200GB so the rule doesn’t seem to be enforced very strongly but regardless, it is good to be aware of. See this link.
  • If you risk averse like me with these kind of things, highlight the script in the editor and click press F8 to run the selection. The alternative is to click the green run button and letting it run whatever it thinks is the correct thing to run 😐
  • The script will prompt you for the new size in GB. Enter it and press enter.
  • When the above step is finished processing, you can go and restart your VM. But we are not done yet, so don’t worry if your disk isn’t bigger yet 😉

Scary bit is over, now for the last bit

  • Remote desktop into your VM.
  • Open the Server manager
  • Click on the File and Storage Services tab
  • Click on Volumes -> Disks
  • In the Volumes you will see your disk with it’s old small size. Right click on it and select ‘Extend Volume’.
  • In the New size box. Type in the value listed under Maximum Size on the same little popup.

AND WE ARE DONE!!!

Hope this helps, if anybody has any feedback, please let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *