The Problem
You have a 250GB VHD Dynamic VHD file which has eaten too much of your Hyper-V host’s drive space (WSUS Instances come to mind). You have accessed the virtual machine and deleted/removed the unwanted bloat that occurs over time. But, you still can’t shrink the .VHD file on the host server.
The Solution
Simply deleting or otherwise removing files from your virtual machine’s drive does not allow the VHD to be shrunk. You must “Zero Out” the unused sectors so Hyper-V can reclaim the space.
The How To
- Download Secure Delete from Microsoft onto the Virtual Machine
http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
Important: Remember to unzip the file to an easy to access location. - Open a Command Prompt
Important: Remember to launch as Administrator! - Execute SDelete as follows (where [path] is the located you unzipped the file)
[PATH]sdelete –c -z - Accept the terms and let it run
- Wait….
- Shutdown the virtual instance
- Launch Hyper-V Manager on the host server
- Open up the setting panel for the Hyper-V instance you wish to perform a VHD shrink for.
- Select the drive you wish to compact and click Edit
- Select Compact and click Finish
- Wait…
That is it! Your done!