[VPC] Compressing VHD files

As mentioned some time ago, we're shuttling VHD files around the office to share preconfigured developer environments. Even precompacted, VHD files are still pretty huge - 5 to 10 GB. They can compress down quite a bit, though - as much as 70% or so.

The built in "compressed file" support in Windows can choke on files this size. I've been using 7-zip, a free compression program, to shrink mine. It includes support for ZIP, but self-extracting SFX's can cut a few hundred more MB's off the file size. That can save several minutes on a network file copy, or make the difference between whether the file will fit on a DVD. For example:

VHD - 5.4GB
Zipped VHD - 2.1GB (38%)
SFX VHD - 1.7GB (31%)

Here are some batch files which I'm using to compress the images. They use the command line version of 7-Zip.  I'm sure these batch files can be improved, or I could add a right click option to VHD files or something - I'm open to suggestions. The main thing I wanted to share, though, is the command line settings for max compression SFX and ZIP compression:

SFX (Self Extracting EXE):

d:\
cd "d:\virtual machines\VS2005\"
c:\Utils\File\7zip\7za.exe a -sfx -mx=9 VS2005Beta2.exe VS2005Beta2.vhd

Zip:

d:\
cd "d:\virtual machines\VS2005\"
c:\Utils\File\7zip\7za.exe a -tzip VS2005.zip VS2005.vhd -mx=9

3 Comments

  • Great post! I was facing the same issue! :)

  • 7-Zip can be very fast OR very slow. If you try and push it, especially with large dictionary sizes which add to its memory needs, it can crawl.

    I've found its "Fastest" setting though is competitive with the pay tools out there, but for that extra couple of compression bytes, it can bog.

  • Yes it's worked for me. Mine vhd was 9.5GB and am not able to write to any dvd. As per above command my vhd size has been reduced to 4.2GB which I can write to a DVD.

    Thanks a lot

Comments have been disabled for this content.