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:
- Open Disk Management
- Locate the last partition on the disk
- Right click on the partition and select Shrink Volume
- Enter the amount that you want to shrink by and click Shrink
Once you have done this – you will need to open the Edit Virtual Hard Disk Wizard and:
- Locate the virtual hard disk that you want to shrink
- Select Shrink
- Note – the option to shrink will only be available if we detect that there is available, unpartitioned space at the end of the disk
- Enter new size that you want
- Note – you will be limited to shrinking down to the available, unpartitioned space
- Click Finish
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