How to compact a Virtual PC image

Most Sharepoint developers use Virtual PC for their development tasks. The VPC images has a tendency to grow very large, and the size of the VHD file is not reduced when you delete files.

Here are a few tips on how to reduce the image size by compacting the VHD file. To save space and reduce the size of a VPC image (several gigs depending on the setup) you can perform the following tasks:


Note!

If you do this you might not be able to install additional services for windows that require the service pack files. Also, you will not be able to uninstall service packs and patches that have been installed.

  1. Make a backup of the VHD you want to compact 
  2. Enable "Show hidden files and folders" in Windows Explorer
  3. Delete all patch/service pack installation files from the c:\windows folder. This is the files beginning with $NtServicePack.. and $NtUninstall.. Do not delete $hf_mig
  4. Delete folder c:\windows\ServicePackFiles
  5. Delete files and folders inside C:\WINDOWS\SoftwareDistribution\Download
  6. Delete any other unwanted files like the IE cache, temp files etc.
  7. Reduce SQL logs
  8. Delete unwanted SQL databases
  9. Defragment the disk by using the Defrag tool
  10. Start the VPC and Capture the following ISO-image to add the PreCompact tool: C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso
  11. Run the tool in the CD image. This can take anywhere from 5 mins to several hours. Typicall around 10 min for a 5 gig image.
  12. Shut down the VPC
  13. Run the Virtual Disk Wizard from the VPC console
  14. Select "Edit an existing disk"
  15. Locate the VHD file you want to compact
  16. Select "Compact it"
  17. Wait for several minutes until the process is finished
  18. The vhd size is now reduced. Start the VPC.