Freigeben über


Shrinking a VHDX on a Running Virtual Machine

This week I have been talking about how to resize a VHDX on a virtual machine that is currently running.  It is easy to think that you can only increase a VHDX of a running virtual machine, but you can also shrink the VHDX of a running virtual machine.  The first thing that you need to do is to free up some space at the end of the virtual hard disk that you want to shrink.  To do this – you will need to login to the guest operating system and:

  1. Open Disk Management
  2. Locate the last partition on the disk
  3. Right click on the partition and select Shrink Volume
  4. Enter the amount that you want to shrink by and click Shrink

image

Once you have done this – you will need to open the Edit Virtual Hard Disk Wizard and:

  1. Locate the virtual hard disk that you want to shrink
  2. Select Shrink
    1. Note – the option to shrink will only be available if we detect that there is available, unpartitioned space at the end of the disk
  3. Enter new size that you want
    1. Note – you will be limited to shrinking down to the available, unpartitioned space
  4. Click Finish

image

You can also do this using PowerShell

Get-VM "Windows Server - Resize" | Get-VMHardDiskDrive -ControllerType SCSI | Resize-VHD -SizeBytes 100GB

One nice option that you get with PowerShell is that you can also ask to just resize the virtual hard disk to the smallest possible size:

Get-VM "Windows Server - Resize" | Get-VMHardDiskDrive -ControllerType SCSI | Resize-VHD –ToMinimumSize

Cheers,
Ben