From: Antonio Terceiro Date: Tue, 11 Jun 2013 14:44:04 +0000 (-0300) Subject: Optimize final image compression rate X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=83d5fb709c6f75557a0fc3511042205d2a722357;p=forks%2Fvmdebootstrap.git 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. --- 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.