Pages

Tuesday, January 20, 2009

How To Compact Virtual Hard Drives


I have spent some time researching for the best way to compact a Virtual Hard Drive. The key for me was finding a way to do an offline defrag on the VHD. I found a program called VHDMount that will allow you to mount your VHD drive on a Windows XP system. Unfortunately it does not come with VPC. Following are the steps to install VHDMount.

Installing VHDMount
  1. Download the Virtual Server 2005 R2 SP1 installation. (free download)
  2. Launch the setup program and select to install Virtual Server 2005 R2 SP1.
  3. Accept the EULA, enter your details, and then select Custom for your setup type.
  4. Now you can unselect every feature except VHD Mount.
Completing the installation will get you a copy of VHDMount without any other Virtual Server stuff.

Compacting The Virtual Hard Drive

Following are my recommendations on how to compact a Virtual Hard Drive.
  1. Start your VHD and Remove all temporary files. I use CCleaner and ATF Cleaner to remove all unwanted files. When it's finished, shut down the guest OS.
  2. Mount the VHD using VHDMount.
    Example: "C:\Program Files\Microsoft Virtual Server\vhdmount\vhdmount.exe" /p /f "C:\VHDs\OPC_MOSS_SB3.vhd"
  3. Do an offline defrag on the mounted VHD. Most the time I use the "Disk Defragmenter" that comes with Windows. If I have some rogue files that will not move nearer to the data pack then I use JkDefrag. Note, do not use JkDefrag in the guest OS because it will grow the VHD file size by about 4 gigs everytime you run it.
  4. Dismount the VHD.
    Example: "C:\Program Files\Microsoft Virtual Server\vhdmount\vhdmount.exe" /u "C:\VHDs\OPC_MOSS_SB3.vhd"
  5. Do a Virtual Disk Precompaction. Start the VHD. Under the CD menu, select Capture ISO Image and browse to the Virtual PC additions directory, which is "C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions". Mount Virtual Disk Precompactor.iso. The precompactor will start automatically. When it's finished, shut down the guest OS.
  6. Open the Virtual PC console and select the Virtual Disk Wizard. Select Edit existing disk, then select the ”Compact it” option. Next select "Saving the file as". I think the option "Replacing the original file" is a waste of time since all it does is make a copy of the compacted disk then deletes the old one. For me it is better to have the option to test the compacted VHD before deleting the old one. If you do not have room on your computer then You can use a shared drive on a second computer. Make sure the shared drive has Write access. This compaction will take about 2 - 3 hour.

No comments: