Posted on January 28, 2014 · Posted in Windows Server 2012 R2

Dynamic Resizing of Virtual Disks in Windows Server 2012 R2

Hyper-V WindowsServer 2012 R2 came up with a new function Online VHDX Resize that allows dynamic VHDX resizing of the working virtual machine (i.e. online).  Online VHDX Resize allows both to extend and to compact a virtual disk. In this article we’ll deal with the features of this technology and its limitations.

Common Features of Online VHDX Resize

  • It is possible to change the disk size (including the system disk of the guest OS) on-wire with no need to turn off the virtual machine.
  • Online VHDX Resize works both on the first and the second generation of virtual machines Hyper-V.
  • Both Windows and Linux can act as a guest OS.
  • Both extension and shrinking of virtual disks are supported.

Requirements and Limitations of OnlineVHDXResize Function

First of all, we’ll consider the requirements to be observed to successfully resize the virtual disk on-the-fly.

  • Only VHDXs can be dynamically resized. VHDs are not supported and have to be converted into the VHDX format (How to convert VHD into VHDX in Windows Server 2012)
  • VHDX to be resized should be mounted to the virtual SCSI controller (not the IDE)
  • Resizing of shared VHDX files used in the cluster is not supported
  • Snapshots of the virtual machine do not allow VHDX resizing

How to Extend VHDX in Windows Server 2012 R2

Let’s describe the procedure of VHDX extension in detail.

  1. Choose the virtual machine in the virtual machine manager Hyper-V and go to its settings (Settings).
  2. Choose the virtual disk and click the Edit button.hyper-v  2012 r2 edit disk size
  3. In the appearing wizard choose Expandexpand disk hyper-v 2012 r2
  4. Specify the new size of the virtual hard disk (in our example we’ll expand the disk size to 170 GB).new vhdx size
  5. Then click Finish.
  6. Go to the console of the guest OS, which disk was extended. Open the console of the Disk Manager. As you can see, extra 42 GB of unallocated space appeared in the system.unallocated space on virtual disk inside virtual machine
  7. Right-click the partition you want to extend and choose Extend Volume, then specify the size of its extension due to the unallocated server - extend volume
  8. After completing the Extend procedure, the disk size will be increased.

How to Shrink VHDX in Hyper-V 2012 R2

Let’s move on to the description of the VHDX shrinking.

  1. Before shrinking the virtual disk, you should «cut a piece» from one of the volumes, thus making some space unallocated. To do it, open the Disk Manager of the guest OS, select a  volume and click Shrink shrink volume in windows

    Note.  Shrink Volume becomes available only if there is some free space on the disk.

  2. Specify the amount of space to shrink the partition by (in our example we specified 50GB).Shrink partition in guest windows os
  3. After the partition of the guest OS has been shrunk, go to the settings in the Hyper-V console and click the Edit button again.
  4. Click Shrink in the wizard and specify the amount of space to shrink the VHDX file.Online VHDX Resize windows server 2012 r2
  5. Done.

VHDX Resizing with Powershell

You can also change the size of the VHDX in Powershell with the cmdlet Resize-VirtualDisk. It looks as follows:

Resize-VirtualDisk -FriendlyName "ISCSIVHD1" -Size (30GB)

Note. Earlier the cmdlet resize-vhd was used to resize the virtual disks. However, the virtual machine had to be turned off.

You can change the size of the file system in the guest OS partition using the command:

resize-partition -driveletter C -size (30GB)
Related Articles