Wednesday, December 7, 2011

How-To: Compact Hyper-V Dynamic Expanding VHD

When you do housekeeping on your target VM which using 'Dynamic Disk', the free space that you free up in your VM will not added back to your Hyper-V host. If space is the concern for you Hyper-V host, then you may have to manually compact the VM's VHD.

To compact a Dynamic Expanding VHD:

Step 1: Right-click the target VM. Select 'Settings...'. Highlight the target Hadr Drive. Click 'Edit'
 Step 2: Select 'Compact'.
Compact - Applies to dynamically expanding virtual hard disks and differencing virtual hard disks. Reduces the size of the .vhd file by removing blank space that is left behind when data is deleted from the virtual hard disk. If the virtual hard disk is not NTFS formatted, the blank space must be overwritten with zeroes so that the compact action can reduce the file size by removing sectors that contain only zeroes.
If the virtual hard disk is not NTFS formatted, you must prepare the virtual hard disk for compacting by using a non-Microsoft disk utility program to replace the blank space with zeroes.
Step 3: Click 'Finish'

Wait for the compacting process to finish.

Below show the size of before and after VHD compacting process.