Increase C: Azure virtual machine

Sometimes there is a need to increase C: volume. The supported maximum size for a disk in Azure is at the moment of writing 1TB. Although there are no commands or selections in the portal for expanding disks for servers created under the Resource Manager. This guide explains how to expand an existing Windows OS disk (default size 127GB) under a virtual machine which is created under Resource Manager (ARM).

Thanks to Karl for giving me the correct parameters to set the disk size! You can find his excellent work here https://github.com/KarlGW

DISCLAIMER. These operations are not officially supported by Microsoft and the steps although should work are done on own risk. Also the steps are tested and verified  on Windows 2003R2 and 2012R2.

1.  Gather Information

Create the server if not yet created through your favorite process. When it’s up and running, log in to the portal and write down the following:

  • Name of the VM
  • Name of the Resourcegroup
  • Name of the Subscription

2. Install latest Powershell Azure module

If not yet installed, get the latest powershell azure module from here: https://github.com/Azure/azure-powershell/releases/latest and install it.

3. Increase OS vhd

From the client you installed the powershell azure module from, start “powershell ISE”.

Copy the latest PS code from here: https://raw.githubusercontent.com/RedeployAB/Azure-ARM/master/ARMdisk/Resize-AzureArmOSDisk.ps1

$SUBname = "Subscription Name"
$VMname = "VM Name"
$RGname = "Resourcegroup Name"
$DiskSizeInGB = "1023"

Login-AzureRmAccount -SubscriptionName $SUBname
$VM = get-azurermvm -name $VMname -ResourceGroupName $RGname
$VM.StorageProfile[0].OSDisk[0].DiskSizeGB = $DiskSizeInGB
Write-Verbose "Stopping VM $($VM.Name)."
Stop-AzureRmVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName -Force
Write-Verbose "Updating VM $($VM.Name)."
Update-AzureRmVM -VM $VM -ResourceGroupName $VM.ResourceGroupName
Write-Verbose "Starting VM $($VM.Name)."
Start-AzureRmVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName

Paste that in to the script window and change the variables to match the correct VM, Resourcegroup and Subscriptionname as written down earlier.

Increase C: Azure

Increase C: Azure

Press the “Play” button and log in with your credentials (If you get unrecognized account, it could be that you have not marked “log in with Microsoft account”).

The script shuts down the VM, set the parameters and starts it up.

You should get “Success” on the output in the command window.

4. Verify virtual disk size

When the above script is complete, log in to the VM

You should see and similar output as below with the virtual disk having the size of 1023GB but C: volume still the same size.

Increase C: Azure

Increase C: Azure

5. Increase C: volume

We will use a third party tool to increase the volume for reasons explained later. Download the software to the VM here: http://www.aomeisoftware.com/download/pa/PAssist_Lite.exe and install it.

Start the AOMEI partition program. It should look something like this:

Increase C: Azure

Increase C: Azure

We need to move the system volume (the volume which is 350MB in this example) to the end of the virtual disk since you need the free space for C: to be in direct conjunction with it.

Mark the system volume, right click it and select “move partition”

Drag the slider to the furthest right as possible as below:

Increase C: Azure

Increase C: Azure

Click “OK”.

You should now have one pending operation in the left column.

Click “Apply” in the top left corner and then “Proceed”.

After the operation completed successfully it should look like this:

Increase C: Azure

Increase C: Azure

Mark C: and right click, select “Resize partition”

Move the slider to the furthest right so the maximum size available is selected:

Increase C: Azure

Increase C: Azure

Click “OK”.

You should now have one pending operation and the “Disk 1” should look like below:

Increase C: Azure

Increase C: Azure

Click “Apply” in the top left corner and then “Proceed”.

The server needs to be rebooted so click “Yes”.

The server reboots.

Once the server is up and running, log in and verify the C: is the new size.

It should look like this:

Increase C: Azure

Increase C: Azure

Now you’re done!

Feel free to uninstall the AOMEI partition software.

As said earlier, tested on Windows 2012R2 created under ARM. But could work for other Windows versions and probably Linux for the first powershell part.