How to shrink Windows 7 XP Mode VHD files?
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!
A_M
Updated on September 17, 2022Comments
-
A_M over 1 year
I'm trying to shrink a Windows 7 XP Mode VHD file with VhdResizer with little success.
When I select my VHD file, it says "VhdExpand only supports fixed and dynamic VHD files". My XP Mode VHDs are dynamic files.
Does anyone have any idea why it is failing?
Failing that, does anyone have a process that I can use to shrink my XP mode VHD files on Windows 7 (64 bit)?
-
Admin about 14 yearsYou may want to zero the non-used sectors of the VHD in the guest OS first, otherwise compacting might not do much.
-
David Balažic about 9 yearsShouldn't defragging be done before precompacting?
-
Kvad about 9 yearsLooking back now. Probably! YMMV.
-
user1251007 about 6 yearsCould someone explain the downvote?