Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Mar 25 '10 at 1:00

This question came from our site for professional and enthusiast programmers.

2  
Shouldn't this be a Super User question? –  Ritsaert Hornstra Mar 24 '10 at 7:44
    
Not sure if the best place for this is Serverfault, or Supeuser, but Stackoverflow it isn't ... you'll get a better answer at one of the two above places :) –  Rob Mar 24 '10 at 7:44
    
I realise that it not directly programming related, but my VHDs are for software development and I'm sure there are a lot of people on here doing something similar, and this subject is of general interest to the programming community. –  A_M Mar 24 '10 at 7:51

3 Answers 3

up vote 4 down vote accepted

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

share|improve this answer
    
Brilliant - thanks - this is what I've been looking for. I'd seen articles about the compact tool when using Virtual PC, but I couldn't figure out how to use it on the version shipped with Windows 7. I'll give this a go. –  A_M Mar 24 '10 at 8:04
1  
You may want to zero the non-used sectors of the VHD in the guest OS first, otherwise compacting might not do much. –  Joey Mar 25 '10 at 1:54

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!

share|improve this answer

In fact, Michael's answer is about how to compact the vhd, while the original question was how to shrink the .vhd, which can (or not) be the same thing, depending on what the original user wanted. At the end of a compactation, the size of the virtual hard disk is the same (from the guest point of view), but it has been reorganized so that the .vhd file is smaller (from the host point of view).

However, if you need to shrink a dynamic VHD (from the guest point of view), so that at the end of the process your virtual machine has a smaller virtual hard drive (because you oversized them during the installation, or any other reason), please have a look at http://jagbarcelo.blogspot.com/2011/11/how-to-shrink-vhd-virtual-hard-disk.html

I hope it helps someone. Regards.

share|improve this answer
    
I see you host the site you link to – could you explain the most important steps here? Having links is great, but we'd encourage answers to provide the solution on-site, if possible. Thanks! –  slhck Nov 13 '11 at 22:05
    
I spent quite a long time figuring out how to do it, then repeating the steps to check they worked and for taking snapshots, then writing everything down. A summary of all that in only a couple of paragraphs is not easy either. I hope you understand. –  J.A. García Barceló Nov 15 '11 at 23:05
    
Sure, no obligation! It's just that we're worried about links going down – if you understand. –  slhck Nov 15 '11 at 23:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.