How to shrink Windows 7 XP Mode VHD files?
Here's how I do it:
1) Make sure the VHD is shutdown (status should be Powered down)
2) In the Virtual Machines folder, right-click the Virtual Machine
3) Click Settings on the menu
4) Select the HD in question and click Modify
5) Select the option to Compact
Using Windows 7 to compact a VHD (using i:\ as an example):
Prior to compacting the VHD run cleanmgr /d c
within the VM to delete any temporary files.
- Load up computer management -> disk management
- Mount the VHD from the actions menu using
Attach VHD
Extract precompact.exe from
C:\Program Files (x86)\Windows Virtual PC\Integration Components\Precompact.iso
Run the following, where the
i
refers to the drive letter the VHD is attached to:precompact.exe -SetDisks:i
Defrag the drive. This will require admin privileges so use
runas
to opencommand prompt
or entercommand prompt
into the search box and select context item 'run as administrator'defrag i: /H /U /X
Within disk management select action
Detach VHD
.Compact the drive inside Virtual PC settings.
Precompact.exe
zeros the VHD – that way using the compactor actually works. Note that in some cases this process can increase the VHD size!