A client accidentally copied a 200GB file to a Hyper-V guest OS server and inflated the dynamically expanding VHDX of the server drive. I’ve heard rumor that Server 2012 Hyper-V is supposed to automatically resize these back. It didn’t. But whatever, here is what I had to do to shrink it back after removing that big file
Oh, and the Hyper-V GUI “condense” didn’t do anything. No progress bar, just flashed and went away – but it’s an easy powershell comandlet.
- Shutdown the guest OS
- Open powershell
- In the powershell run this to mount the VHDX in read-only mode. Mount-Vhd -path <THE FULL PATH TO THE VHDX FILE> -readonly
- Then run this to start the optimize
Optimize-Vhd -path <THE FULL PATH TO THE VHDX FILE> -Mode quick
- Unmount it by running
Dismount-Vhd -path<THE FULL PATH TO THE VHDX FILE>
Remember to put quotes or apostrophes around your filepath if it contains spaces.
The official commandlet documentation on Technet: