7

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)?

quack quixote
  • 43,504
A_M
  • 285

3 Answers3

6

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

5

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.

  1. Load up computer management -> disk management
  2. Mount the VHD from the actions menu using Attach VHD
  3. Extract precompact.exe from

    C:\Program Files (x86)\Windows Virtual PC\Integration Components\Precompact.iso

  4. Run the following, where the i refers to the drive letter the VHD is attached to:

    precompact.exe -SetDisks:i
    
  5. Defrag the drive. This will require admin privileges so use runas to open command prompt or enter command prompt into the search box and select context item 'run as administrator'

    defrag i: /H /U /X
    
  6. Within disk management select action Detach VHD.

  7. 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!

slhck
  • 235,242
Kvad
  • 551
-1

The other options didn't work for me (attaching the vhd to disk managment didn't work, compacting didn't work), so here is what I did.

  1. Run cleanmgr /d c in the VM
  2. Disable the swap file
  3. Run disk defragmentation in the VM
  4. Resize the system partition of the VM:

  5. Resize the vhd file with vhd resizer (which can be downloaded from https://www.considerednormal.com/2014/09/resizing-vhd-files-the-easy-way/)

Be sure to backup your vhd file before!

user1251007
  • 1,175