How to Resize Online Virtual Machine Hard Disks in Hyper-V 2012 R2

Starting with Windows Server 2012 R2, it is possible to re-size a Virtual Hard Disk for a running Virtual Machine on Hyper-V! It was not possible to do so before for an online Virtual Machine running on Windows Server 2012 and earlier Hyper-V versions.

How to resize online virtual machine hard disks in Hyper-V

Let’s have a look at some of the benefits this feature offers and requirements before you dive in and use it.

[thrive_leads id=’16356′]

Benefits

The re-sizing feature allows expanding or shrinking a Virtual Machine hard disk while the Virtual Machine is running. Storage administrators can avoid downtime to perform virtual hard disk maintenance tasks and there is no impact to end users. Users can still access Virtual Machine and its volumes. This feature reduces the maintenance costs associated with downtime of critical Virtual Machines.

There is also a Resize-VirtualDisk PowerShell cmdlet available which can be used to script the re size operation on multiple virtual hard disks quickly. There is no need to use or enable any component to use this feature. This functionality is available out of the box using “Edit Virtual Hard Disk” wizard.

Requirements

Since it is a feature of Hyper-V running on Windows Server 2012 R2, make sure to perform this task on a Windows Server 2012 R2 Hyper-V Server. You must also be using a VHDX format and this must be connected to a SCSI controller before you can expand or shrink a Virtual Hard Disk. However, Disk type can be fixed, differencing or dynamic.

So, let’s see how you actually Expand and Shrink virtual hard disks without powering off Virtual Machines. I’m not going to explain the step-by-step process but provide you the necessary screenshots for your understanding.

How to Expand?

To expand, Right Click on the Virtual Machine and then click on “Settings”. Click on the Virtual Hard Drive you want to extend in the “Settings” page. Note: You cannot extend/compact a Virtual Machine hard drive if a snapshot exists. A warning message will be shown stating that “Edit is not available because checkpoints exist for this Virtual Machine”. This is also shown in the red circle of the below screenshot.

Next click on “Edit” button to launch the “Edit Virtual Hard Disk” wizard as shown below:

Click “Next” to select “Expand” action as shown below:

Specify the size of the virtual hard drive to expand and then click on Finish.

At this point, Virtual Machine hard disk size has been expanded, now you need to launch “Disk Manager” in  Virtual Machine and then use the “Extend the Volume” wizard to make un-allocated space available to the Virtual Machine. When you open “Disk Manager”, you will see the expanded size as un-allocated space as shown in the below screenshot of the Virtual Machine:

Right Click on the volume you want to extend and then select “Extend Volume” wizard as shown in the below screenshot and then follow the on-screen steps to complete the process.

 

 

How to Shrink?

To shrink the storage capacity, you must first initiate the “shrink” action from within the Operating System of Virtual Machine using “Disk Manager”. Using the “Disk Manager”, Right Click on the volume you want to shrink and then select “Shrink Volume” action as shown in the below the screenshot:

Note: Extend Volume” action is available only if you have un-allocated space available in the Operating System. Next, specify the amount of space you want to shrink as shown below and then hit “Shrink” button:

Once shrunk from within the Operating System of Virtual Machine, initiate the final shrink action using the “Edit Virtual Machine” wizard. Click on “Edit” button on the Virtual Machine’s setting page to specify the new size for the virtual hard disk as shown in the below screenshot. “Edit Virtual Machine” wizard will not allow you to specify the new size value lesser than the size being used by the Operating System inside the Virtual Machine. As you can see in the below screenshot, the C: volume is about 58.6 GB in size and “Edit Virtual Hard Disk” wizard also specifies the minimum required size which is 60 GB. This is shown in the red circles in the below screenshots:

Once you have specified the size to shrink, click “Finish” button for VMWP.exeto process the change and reduce the size of the VHDX file on the Host storage.

Limitations

  • Does not work on virtual hard disks using VHD format.
  • The re-sizing feature does not work on Virtual Hard Disks which are attached to IDE Controllers.
  • Does not work for Virtual Hard Disks which have snapshots/checkpoints associated.
  • Expanding and Shrinking process is not visible to the Virtual Machine Operating System. You must take some extra steps.
  • Once the virtual hard disk has been expanded, the extra space is shown as un-allocated in the Disk Manager in the Operating System of the Virtual Machine. You must make the extra space available to Virtual Machine by using the “Extend Volume Wizard” within the Disk Manager of the Virtual Machine.
  • Shrinking reduces the storage capacity of the Virtual Hard Disk. If you want to shrink the size, you must use the “Disk Manager” in Operating System of the Virtual Machine. Finally, use the “Edit Virtual Hard Disk” wizard to reduce the size of the virtual hard disk.

 

Altaro Hyper-V Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

13 thoughts on "How to Resize Online Virtual Machine Hard Disks in Hyper-V 2012 R2"

  • Andy says:

    I was on your blog for sbs 2011 backups failing which was great! Thanks for that.
    Hyper-v seems to be pretty bad at virtual disks. I upgraded 2008 R2 host to 2012 R2 hoping it would be better. Previous admin chose to virtualize a sbs 2011 install and keep the 146GB C: drive and ~500GB D: drive with gobs of free space as well as snapshots. I got the snapshots cleaned up and then went to work trying to shrink the disks. I learned very quickly of unmovable files that keep you from shrinking much at all. In all my time of working with vmware I have never run into unmovable files and if I had I would have simply run converter on them to clean them up. I have tried all the free suggestions and tools to fix the issue but none have worked.
    For now it looks like I will have to live with a 500GB vhdx for this vm even though only ~200GB is in use.
    So shrinking is good but limited by unmovable files which in most cases needs a third party tool to fix $$

  • Jahncm says:

    These limitations are ridiculous. VMware can do it. I prefer Hyper-V, but this is pretty dumb on MS’ part to not address a key feature that VMware has had forever…

  • Jeff says:

    You should note that this is a Generation 2 vm under limitations,

  • Jamie says:

    Thanks for the post, good instructions on how to perform the shrink on the volume however I also wanted to shrink the virtual machines disk itself to remove the unallocated space, I found these extra steps here hope they help someone else too: http://www.rootusers.com/decreasing-disk-space-in-windows-server-2012-r2/

  • Knut Petter says:

    I done that, but get a error all the time that sat that the file are in use of a other process. and a error code 0x80070020 ???

    What am i doing wrong

    • Hi Knut,

      There’s not really enough context here to understand why you’re getting this error. However, a couple of things I would check are if you have snapshots / checkpoints? If so, I’d delete or merge them before attempting the resize. Also, I would check if the resize works when the VM is turned off?
      Do you run Antimalware on the Hyper-V host? That might interfere with the resizing operation. Or is there a backup job running?
      Here’s the official documentation for online VHDX resizing.

      Good luck!

      Paul Schnackenburg, Altaro DOJO Technical Editor

Leave a comment or ask a question

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

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

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.