Monday, January 05, 2009

compacting VPC free space

when one of my XP Virtual PC (VPC) images reached 17GB, I knew it was time to compress it. however, the main reason the virtual hard drive got so large was due to space that was now empty. to get the VPC to compress back down to just the space it was using, I found that I needed to follow the steps from a blog tip. after this process, my VPC went down to 7GB.

note: you'll need substantial free space on your host machine to complete this process. my 17GB hard drive needed 22GB of free space. the process also takes a long time--at least 2-3 hours in my case.

1) Inside the VM, run the special disk defragmenter that works on empty space
2) Inside the VM, run Virtual Disk Precompactor or other disk utility program to "zero out" deleted data (this comes as an ISO in the VPC additions folder)
3) Shutdown the VM, run "Virtual Disk Wizard" from the VPC console to compact the VHD.

here are the details:
instead of using the defragmenter comes with Windows, you should use the defrag tool created by Dave Whitney.

install the defrag tool:
- log in as a machine administrator (this is necessary to install the service).
- copy bootdfrg.exe to your windows\system32 directory.
- from a command prompt, navigate to the dir where you have the new derag tool and type: defrag -i
you should get back: "The Disk Defragmenter service was successfully installed."The service is now installed.
to uninstall, type: net stop defragsvc & defrag -u

run the defrag:
to run the tool on the C: drive type: defrag -d c

from MS support on the Virtual Disk Precompactor:
"Capture the .iso from (C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso). If your virtual machine is running when you capture Virtual Disk Precompactor.iso, Virtual Disk Precompactor starts automatically. If you click Yes when prompted, Virtual Disk Precompactor precompacts all virtual hard disks for this virtual machine. If Virtual Disk Precompactor does not start automatically, you can start it by navigating to the CD drive of the guest operating system and double-clicking Precompact.exe.

Alternatively, you can also run Virtual Disk Precompactor from the command line by navigating to the CD drive of the guest operating system and typing Precompact. The available parameters are:-Help - Displays help for the precompactor.-Silent - Runs the precompactor in unattended mode.-SetDisks - Specifies the disks to be precompacted. If this parameter isn't specified, then all virtual hard disks for this virtual machine are compacted. For example, the following command will precompact your C, D, and E drives in unattended mode: Precompact -Silent -SetDisks:CDE"

Virtual Disk Wizard:
the virtual disk wizard is an option in the VPC console. remember to shut down your VPC and then run this option. you should select "Compact existing virtual hard drive."

1 comment:

Sam said...

I also have some problems with free space with vhd images. Like SvOlli I think the best method is using imaging - its very good!! I have image vhd file 7GB of size! after imaging and restoring the system this file was only 1.2 GB in size.