Virtual PC and Virtual Server uses Virtual Hard Disk which may be dynamically sized, that is they don’t occupy the whole size of the disk on the host system. But they may take up much more than the guest operating system reports.

I will show you how to reduce the size of you dynamically expanding virtual disk, using the tools provided with Virtual PC 2007 beta 2 (it’s the same on VPC 2004).

I just created a VHD containing Windows XP SP2 and Visual Studio .NET 2003 SP1 and some other dev. tools so I can switch my main laptop to Windows Vista. As you know VS.NET 2003 does not run on Vista but I still have to do some .NET 1.1 development so a VPC will be just perfect. I also wanted this image to fit on a DVD and this is how I did it. I went from a VHD file size from 6.7 GB to 4.0 GB.

1. Prepare the guest OS

First of all I did a Disk Cleanup and removed all unnecessary files.

And to save me some more space I cleaned up the System Restore an removed all the backups of Windows Update (only do this if you are sure on how to do it!).

2. Defragment the guest OS

To get an effective compact of your VHD you must defragment the guest hard disk.

4. Run the Virtual Disk Pre-Compactor

Virtual PC contains a utility to prepare the disk before compacting it, called the Virtual Disk Pre-Compactor. This is run by mounting the Virtual Disk Precompactor.iso on the guest OS, found in the Virtual Macine Additions directory where Virtual PC is installed. Follow the instructions and wait while th VHD is being prepared…

5. Compact the Virtual Disc

Shut down your guest OS and launch the Virtual Disk Wizard from the Virtual PC Console. Follow the instructions;

a) choose to edit a diskb) choose your VHDc) hoose to compact itd) optionally choose to create a new one (I normally choose this in case of any trouble - I’m using VPC 2007 beta here)

Then wait while the disc is compacted…

6. You’re done

Now you are all set and done and you should have saved a lot of space.

7. Next?

You can sometime save some more space doing it all over again once again, at least I did.