vmware-zippedRecently I had to create a vmware image with Debian GNU/Linux that had to be as small as possible because people would have to download it. I started installing Debian “sid” by using debootstrap according to the following instructions: Installing Debian GNU/Linux from a Unix/Linux System. When I completed the installation and after I removed all the unnecessery packages I had a fully functional system that occupied 400MB of disk space. The problem was that the VMWare image size was 1.2GB although only 1/3 of it was actually being used.

I suppose this happens because VMWare preallocates space to improve the performance of IO operations. If I try to compress the image as it is the compression ratio will be really low. The reason is that the preallocated free space contains random data that is hard to compress. If we could fill this free space with a repeating pattern then we could achieve a much higher compression ratio.

The solution I found online is really simple and works. By running the following command we fill the extra space with zero bytes:

cat /dev/zero > zero.fill; sync; sleep 1; sync; rm -f zero.fill;

After running the command I used gzip to compress the image to 178MB from 1.2GB!

pixelstats trackingpixel
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
If you enjoyed this post, make sure you subscribe to my RSS feed!
Leave a Reply