Compressing a VMWare image file
Posted on July 10th, 2009 by Haris Andrianakis in Linux Notes, tags: compress, linux, vmware
Recently 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!
If you enjoyed this post, make sure you subscribe to my RSS feed!
Entries (RSS)
You’re a Really Professional Blogger, You either have got quality knowledge of what your discussing or you did some great research. Thanks for this excellent post.
Hi there could I reference some of the information from this post if I reference you with a link back to your site?
I was simply browsing for relevant blog content intended for a project research and My partner and i happened to stumble upon yours. Many thanks for the helpful information!
Tired of obtaining low numbers of useless visitors to your site? Well i want to tell you about a brand new underground tactic that produces myself $900 daily on 100% AUTOPILOT. I possibly could be here all day and going into detail but why dont you simply check their site out? There is really a excellent video that explains everything. So if your seriously interested in making simple cash this is the site for you. Auto Traffic Avalanche