Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

migrated from stackoverflow.com Aug 7 '09 at 8:11

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

7 Answers

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
2  
+1 for "you didn't read the help file hard enough" –  Tiberiu Ana Aug 7 '09 at 8:09
add comment

You could follow the steps described here.

share|improve this answer
add comment

Put it in the dryer.

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

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
add comment

Ignore all of the suggestions that require you to run through long lists of complicated steps (such as the one at http://kb.dutchalps.com/microsoftvirtualpc.htm). 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
add comment

I've always used this: http://vmtoolkit.com/files/folders/converters/entry87.aspx

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
add comment

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
add comment

Your Answer

 
discard

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