Thursday, November 6, 2008

Compact Virtual PC virtual hard disks (.VHDs)

If you use Virtual PC 2007 you know that the virtual hard drive files (.VHDs) can grow quite large. This is due to the fact that .VHD files dynamically expand when software is installed inside the Virtual PC.

After the installation, the original setup files are deleted and no longer take up space in the .VHD, however the .VHD does not dynamically shrink. Once a .VHD file expands - it doesn't shrink.

So here's a HOWTO to shrink the size of a .VHD file:

1) Clean the machine for any temp files etc. - If you're lazy, you can use a program like CCLEANER (http://ccleaner.com), which deletes all temporary files from the Windows installation, Internet Explorer cache, the Recycle Bin, etc.

2) Disable hibernation
If you have hiberation turned on, there's a colossal sized file called hiberfil.sys in the root of the .VHD. Go into Power options in Control Panel and disable hiberation to get rid of this.

3) Capture the Virtual Disk Precompactor .ISO file
In the menu of Virtual PC, capture the Virtual Disk Precompactor .ISO file which is located at: "c:\program files\microsoft virtual pc\virtual machine additions\virtual disk precompactor.iso". The Precompactor should run automatic.

4) Run the VPC2007 Virtual Disk Wizard
Shutdown the Virtual PC and from the Virtual PC console, click File-> Virtual Disk Wizard and "Edit an existing virtual disk". Browse to the .VHD file and select it. Select the "Compact" option and "Replacing the original file". This will take a few minutes depending on the size of your .VHD file.

No comments: