Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Virtual machine hard disk over 20GB in size. But there are only about 8-10GB of files inside.

I need to shrink this vhd file to a more manageable (actual) file size. I've tried using the virtual PC wizard and it doesn't do anything with the file size.

Is there any other solutions or tools that I can use to shrink the vhd file size?

share|improve this question

migrated from Aug 7 '09 at 8:11

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

Actually, Microsoft Virtual PC already has an option called "Compact virtual disk". Read about it in the help file. However, to achieve the best reduction you will need to zero-fill the empty parts of the disk. For that you will need a third party tool - but there are plenty of those. Just google.

Sorry, misread your post. You already tried that. In that case you didn't read the help file hard enough. I quote:

Before compacting the disk, we recommend that you use a disk utility to zero out blank space, which should result in a smaller compacted virtual hard disk.

I use a utility called Eraser. I think it was recommended in some Microsoft TechNet posting or MSDN. And it's totally free.

share|improve this answer
+1 for "you didn't read the help file hard enough" – Tiberiu Ana Aug 7 '09 at 8:09

You could follow the steps described here.

share|improve this answer

Put it in the dryer.

share|improve this answer
-1 Oh so funny. – balpha Aug 7 '09 at 7:53
It's Friday man, smile! – Max Aug 7 '09 at 8:03

If your disk is dynamic sized :

  1. Defragment (you could use the Whitney defragmenter).
  2. Compact the disk with Virtual PC (more information here).

If you have a fixed size disk, I guess you could create another smaller disk and backup/restore the first one on the second one (using a ghost utility like Clonezilla). You would have to defragment first in this case too.

To create smaller disks in the first place, follow Jeff's advice.

share|improve this answer

Ignore all of the suggestions that require you to run through long lists of complicated steps (such as the one at Ignore all of the suggestions that require you to use a third-party tool (such as the suggestion to use Eraser).

All you need to do is defrag the VHD and then run the Virtual Disk Precompactor from Microsoft. It is an ISO image that you can mount in the virtual machine and can be found in the Virtual Machine Additons directory. After running the Virtual Disk Precompactor you can let Virtual PC compact the VHD.

Note that these comments apply to Virtual PC 2007.

share|improve this answer

I've always used this:

Make sure you have shrunk the partition in the vhd first using the tools you've already used, the resizer should then allow you to shrink the vhd file itself to match the partition size.

share|improve this answer

Applicable only on sparse disk images, you need to zero out the empty space and then use the shrink utility. That will perform a zero-de-dup on the image.

Preallocated images are preallocated, no way to shrink them.

share|improve this answer

Your Answer


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