Add to My Yahoo! | Google Reader or Homepage | Add to Windows Live | Add to Windows Live Alerts

Wictor Wilén

Microsoft Certified Master (MCM) - SharePoint 2010 | Microsoft Most Valuable Professional (MVP) - SharePoint Server MVP | Author

Compacting a Virtual Hard Disk

Posted at 2007-02-03 11:34 by Wictor Wilén in Windows XP , Windows Vista , Virtual Server with 8 comments.

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 disk
b) choose your VHD
c) hoose to compact it
d) 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.

Comments and trackbacks

#  Boot CD by Rob
After I have created the Virtual Hard Disk(VHD), It's possible to create a boot CD using it?
#  Re: Boot CD by Wictor Wilén
Screenshot from websnpr Heya Rob, can you explain why you would like to make a boot CD of the VHD?
#  step 5 by ahhow@chiuyi.vn
Screenshot from websnpr when i shut down the guest os according your instruction , do i choose the "save the changes" and check the commit options?
#  step 5 by ahhow@chiuyi.vn
Screenshot from websnpr when i shut down the guest os according your instruction , do i choose the "save the changes" and check the commit options?
#  Re: step 5 by Wictor
Screenshot from websnpr Yes, you must commit your changes, otherwise you will loose everything.
#  step 5 by ahhow@chiuyi.vn
Screenshot from websnpr when i shut down the guest os according your instruction , do i choose the "save the changes" and check the commit options?
#  Re: step 5 again by Wictor
Screenshot from websnpr Heya again. Yes make sure that you check the commit checkbox so that your changes are committed and saved.
#  Hyper-V virtual disk compaction does not release empty virtual drive space by Trackback
Screenshot from websnpr <p>You attempt to run Hyper-V disk compaction but no space is released from the virtual hard drive (dynamic).</p> <p>&#160;</p> ...
Make a comment on this post:
Subject:  

Your name:  
Your Url:  
Note: submissions may have to be approved before being visible, so don't submit your comment multiple times.