The different ways to compact a disk

Today if you want to compact a virtual hard disk – you can use Virtual PC / Virtual Server / Hyper-V or Windows 7.  But not all methods are the same.  Under the covers there are two different approaches that are taken to compacting virtual hard disks:

Virtual PC / Virtual Server:

Perform a blind “block level” compaction.  Here the virtual hard disk is inspected at a block level, and when a block is found which is full of zeroes, the block is removed from the virtual hard disk.

More accurately, zeroed blocks are not copied.  Because when you compact a virtual hard disk with Virtual PC / Virtual Server – they do so by creating a new blank virtual hard disk and copying the data across – and then deleting the original virtual hard disk at the end.

Advantages:

  • Works with any file system inside the virtual hard disk.
  • Can compact differencing virtual hard disks (Windows Virtual PC only).

Disadvantages:

  • Requires that you run a pre-compaction tool that writes zeroes to unused space in the virtual hard disk.
  • May work better if you run a defragmentation program inside the virtual machine first.
  • Requires that you have enough free space on the physical disk for a second copy of the virtual hard disk.
  • Has to process all the data in the virtual hard disk – so can take a while.

Hyper-V / Windows 7:

Hyper-V and Windows 7 use a different approach to compacting virtual hard disks.  What they do is look for an NTFS file system on the virtual hard disk.  If they find one, they read this data directly and use it to identify zeroed blocks that can be removed from the virtual hard disk.

This operation is done “in place” which means that no second virtual hard disk is created.

Advantages:

  • No preparation needed - just point it at an offline virtual hard disk and it works.
  • No need for extra free space on the physical disk.
  • Faster than Virtual PC / Virtual Server.

Disadvantages:

  • Does not work with non-NTFS formatted virtual hard disks.

Cheers,
Ben