Compacting Virtual Hard Disks with Hyper-V

When you choose to compact a virtual hard disk with Hyper-V a very interesting process is used.  The virtual hard disk is actually connected to the parent partition (but it is not mounted).  Windows then inspects the virtual hard disk.  If the virtual hard disk is NTFS formatted, the NTFS data structures are analyzed to determine how to compact the virtual hard disk.  If the virtual hard disk is not NTFS formatted it is analyzed as a raw device and zeroed out blocks are compacted.

This means that if you have a NTFS formatted virtual hard disk you do not need to prepare the virtual hard disk for compaction.  If you have a virtual hard disk that is formatted with a different file system you will still need to use an application to zero out free space on the virtual hard disk before attempting to compact it.

Cheers,
Ben