How to expand virtual hard disks attached to a Windows virtual machine

Applies to: ✔️ Windows VMs ✔️ Flexible scale sets

When you create a new virtual machine (VM) in a resource group by deploying an image from Azure Marketplace, the default operating system (OS) drive is often 127 GB (some images have smaller OS disk sizes by default). Even though it's possible to add data disks to the VM (the number depends on the SKU you chose) and we recommend installing applications and CPU-intensive workloads on these addendum disks, often, customers need to expand the OS drive to support specific scenarios:

  • To support legacy applications that install components on the OS drive.
  • To migrate a physical PC or VM from on-premises with a larger OS drive.

Important

Unless you use Resize without downtime (preview), resizing an OS or data disk of an Azure VM requires the VM to be deallocated.

Shrinking an existing disk isn’t supported, and can potentially result in data loss.

After expanding the disks, you need to Expand the volume in the operating system to take advantage of the larger disk.

Resize without downtime (preview)

You can now resize your managed disks without deallocating your VM.

The preview for this has the following limitations:

To register for the feature, use the following command:

Register-AzProviderFeature -FeatureName "LiveResize" -ProviderNamespace "Microsoft.Compute"

It may take a few minutes for registration to complete. To confirm that you've registered, use the following command:

Get-AzProviderFeature -FeatureName "LiveResize" -ProviderNamespace "Microsoft.Compute"

Resize a managed disk in the Azure portal

Important

If you've enabled LiveResize and your disk meets the requirements in Resize without downtime (preview), you can skip step 1. To resize a disk without downtime in the Azure portal, you must use the following link: https://aka.ms/iaasexp/DiskLiveResize

  1. In the Azure portal, go to the virtual machine in which you want to expand the disk. Select Stop to deallocate the VM.

  2. In the left menu under Settings, select Disks.

    Screenshot that shows the Disks option selected in the Settings section of the menu.

  3. Under Disk name, select the disk you want to resize.

    Screenshot that shows the Disks pane with a disk name selected.

  4. In the left menu under Settings, select Size + performance.

    Screenshot that shows the Size and performance option selected in the Settings section of the menu.

  5. In Size + performance, select the disk size you want.

    Warning

    The new size should be greater than the existing disk size. The maximum allowed is 4,095 GB for OS disks. (It's possible to expand the VHD blob beyond that size, but the OS works only with the first 4,095 GB of space.)

    Screenshot that shows the Size and performance pane with the disk size selected.

  6. Select Resize at the bottom of the page.

    Screenshot that shows the Size and performance pane with the Resize button selected.

Resize a managed disk by using PowerShell

Open your PowerShell ISE or PowerShell window in administrative mode and follow the steps below:

Sign in to your Microsoft Azure account in resource management mode and select your subscription:

Connect-AzAccount
Select-AzSubscription –SubscriptionName 'my-subscription-name'

Set your resource group name and VM name:

$rgName = 'my-resource-group-name'
$vmName = 'my-vm-name'
$diskName = 'my-disk-name'

Obtain a reference to your VM:

$vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName

Important

If you've enabled LiveResize and your disk meets the requirements in Resize without downtime (preview), you can skip step 4 and 6.

Stop the VM before resizing the disk:

Stop-AzVM -ResourceGroupName $rgName -Name $vmName

Obtain a reference to the managed OS disk. Set the size of the managed OS disk to the desired value and update the Disk:

$disk= Get-AzDisk -ResourceGroupName $rgName -DiskName $diskName
$disk.DiskSizeGB = 1023
Update-AzDisk -ResourceGroupName $rgName -Disk $disk -DiskName $disk.Name

Warning

The new size should be greater than the existing disk size. The maximum allowed is 4,095 GB for OS disks. (It is possible to expand the VHD blob beyond that size, but the OS works only with the first 4,095 GB of space.)

Updating the VM might take a few seconds. When the command finishes executing, restart the VM:

Start-AzVM -ResourceGroupName $rgName -Name $vmName

Remote into the VM, open Computer Management (or Disk Management) and expand the drive using the newly allocated space.

Expand the volume in the operating system

When you have expanded the disk for the VM, you need to go into the OS and expand the volume to encompass the new space. There are several methods for expanding a partition. This section covers connecting the VM using an RDP connection to expand the partition using Using Diskpart or Using Disk Manager.

Using DiskPart

When you have expanded the disk for the VM, you need to go into the OS and expand the volume to encompass the new space. There are several methods for expanding a partition. This section covers connecting the VM using an RDP connection to expand the partition using DiskPart.

  1. Open an RDP connection to your VM.

  2. Open a command prompt and type diskpart.

  3. At the DISKPART prompt, type list volume. Make note of the volume you want to extend.

  4. At the DISKPART prompt, type select volume <volumenumber>. This selects the volume volumenumber that you want to extend into contiguous, empty space on the same disk.

  5. At the DISKPART prompt, type extend [size=<size>]. This extends the selected volume by size in megabytes (MB).

Using Disk Manager

  1. Start a remote desktop session with the VM.

  2. Open Disk Management.

    Screenshot showing Disk Management.

  3. Right-click on existing C: drive partition -> Extend Volume.

    Screenshot showing how to extend the volume.

  4. Follow the steps you should be able to see the disk with updated capacity:

    Screenshot showing the larger C: volume in Disk Manager.

Next steps

You can also attach disks using the Azure portal.