How to reduce the size of VHD files in Virtual PC

by Ron Bertino on November 12, 2008

I’m currently running Virtual PC 2007 on one of my systems in order to run a virtual machine.

I noticed that the VHD file was 28.4 GB in size, yet the virtual hard drive itself seemed to be much smaller when looking at the used space from within the virtual machine.

I did some digging and found that VHD files can bloat in size after some use.

After running through the steps below, my VHD file reduced from a size of 28.4 GB down to 17.1 GB (almost a 40% reduction).

Here are the steps I went though:

  1. Clear out the machine of filler
    I recommend installing CCLEANER.EXE from http://ccleaner.com which deletes all temporary files from the Windows installation, Internet Explorer cache, the Recycle Bin, and any number of other “garbage”/”temp” directories in the VPC.
  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 file.
  3. Defragment the hard disk
    From within the virtual machine, right-click on the hard disk, choose Properties, then the Tools tab, and then Defragment Now.
  4. Capture the Virtual Disk Precompactor .ISO
    In the menu of Virtual PC windows for your machine, capture the Virtual Disk Precompactor .ISO file which is located at:
    c:\program files\microsoft virtual pc\virtual machine additions\virtual disk precompactor.iso
  5. Run the Precompactor
    Go to My Computer and double click on the mounted disk.  It will begin to run the precompactor software which will essentially zero out all the free space on the disk, making it available for elimination from the file by the Virtual Disk Wizard, which we will use later.  This process may take upwards of 15 minutes
  6. Shutdown the Virtual PC
  7. Run the VPC2007 Virtual Disk Wizard
    From the Virtual PC console, click File-Virtual Disk Wizard and “Edit an existing virtual disk”.  It will ask you to identify the .VHD file to reduce in size – select it.
  8. Compact the .VHD
    Select the “Compact” option then select “Replacing the original file”.  This will take a few minutes.

Share

{ 5 comments… read them below or add one }

Andy January 15, 2009 at 5:07 pm

Very nice. I was running eraser but still searching around for other ways of shrinking the vhd and found this. Pretty cool microsoft included this though why their support site is not the first to come up in a google search is beyond me.
Thanks again.

Reply

Ron Bertino January 15, 2009 at 5:27 pm

Hi Andy.

Happy to hear it helped.

Reply

Yusuf June 9, 2011 at 7:31 am

Yes, it works! Thx

Reply

Chris September 5, 2011 at 12:44 am

That worked great, thanks very much.

Reduced a 30GB VHD down to 11GB, so a sizeable reduction!

Reply

Vinayak April 14, 2012 at 3:16 pm

Thank you so much. This works like charm…

Reply

Leave a Comment


5 + = fourteen