From 83d5fb709c6f75557a0fc3511042205d2a722357 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 11 Jun 2013 11:44:04 -0300 Subject: [PATCH] Optimize final image compression rate Filling up the image with zeros makes its compression rate a lot higher. Together with running `apt-get clean`, I got an 1GB image compressed down to 106M, against to 210M without these 2 changes. --- vmdebootstrap | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vmdebootstrap b/vmdebootstrap index 5b4fa96..7327414 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -115,6 +115,7 @@ class VmDebootstrap(cliapp.Application): self.customize(rootdir) if self.settings['image']: self.install_extlinux(rootdev, rootdir) + self.optimize_image(rootdir) if self.settings['tarball']: self.create_tarball(rootdir) except BaseException, e: @@ -364,7 +365,16 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s self.runcmd(['extlinux', '--install', rootdir]) self.runcmd(['sync']) import time; time.sleep(2) - + + def optimize_image(self, rootdir): + """ + Filing up the image with zeros will increase its compression rate + """ + zeros = os.path.join(rootdir, 'ZEROS') + self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M']) + self.runcmd(['rm', '-f', zeros]) + + def cleanup_system(self): # Clean up after any errors. -- 2.39.2