]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Fix typo in bootsize partition space
[forks/vmdebootstrap.git] / vmdebootstrap
index fafd78ab4c9ec6590a115026c763ac9a23e8bb05..24e38d0aad73e4db4e8d50dd7ce255c4d9c36d09 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 # Copyright 2011-2013  Lars Wirzenius
 # Copyright 2012  Codethink Limited
+# Copyright 2014 Neil Williams <codehelp@debian.org>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -26,7 +27,7 @@ import tempfile
 import time
 
 
-__version__ = '0.3'
+__version__ = '0.5'
 
 
 class VmDebootstrap(cliapp.Application):
@@ -53,16 +54,13 @@ class VmDebootstrap(cliapp.Application):
                              'set up foreign debootstrap environment using provided program (ie binfmt handler)')
         self.settings.string(['variant'],
                              'select debootstrap variant it not using the default')
-        self.settings.boolean(
-            ['extlinux'],
-            'install extlinux?',
-            default=True)
+        self.settings.boolean(['extlinux'], 'install extlinux?', default=True)
         self.settings.string(['tarball'], "tar up the disk's contents in FILE",
                              metavar='FILE')
         self.settings.string(['mirror'],
                              'use MIRROR as package source (%default)',
                              metavar='URL',
-                             default='http://cdn.debian.net/debian/')
+                             default='http://http.debian.net/debian/')
         self.settings.string(['arch'], 'architecture to use (%default)',
                              metavar='ARCH',
                              default=default_arch)
@@ -114,6 +112,9 @@ class VmDebootstrap(cliapp.Application):
         self.settings.boolean(['grub'],
                               'Install and configure grub2 - disables '
                               'extlinux.')
+        self.settings.boolean(['sparse'],
+                'Dont fill the image with zeros to keep a sparse disk image',
+                default=False)
 
     def process_args(self, args):
         if not self.settings['image'] and not self.settings['tarball']:
@@ -163,6 +164,8 @@ class VmDebootstrap(cliapp.Application):
             if self.settings['configure-apt']:
                 self.configure_apt(rootdir)
             self.customize(rootdir)
+            self.update_initramfs(rootdir)
+
             if self.settings['image']:
                 if self.settings['grub']:
                     self.install_grub2(rootdev, rootdir)
@@ -242,7 +245,7 @@ class VmDebootstrap(cliapp.Application):
         if self.settings['bootsize'] and self.settings['bootsize'] is not '0%':
             bootsize = str(self.settings['bootsize'] / (1024 * 1024))
             self.runcmd(['parted', '-s', self.settings['image'],
-                         'mkpart', 'primary', 'fat16', '0', bootsize])
+                         'mkpart', 'primary', 'fat16', '0%', bootsize])
         else:
             bootsize = '0%'
         self.runcmd(['parted', '-s', self.settings['image'],
@@ -250,6 +253,12 @@ class VmDebootstrap(cliapp.Application):
         self.runcmd(['parted', '-s', self.settings['image'],
                      'set', '1', 'boot', 'on'])
 
+    def update_initramfs(self, rootdir):
+        cmd = os.path.join('usr', 'sbin', 'update-initramfs')
+        if os.path.exists(os.path.join(rootdir, cmd)):
+            self.message("Updating the initramfs")
+            self.runcmd(['chroot', rootdir, cmd, '-u'])
+
     def install_mbr(self):
         if os.path.exists("/sbin/install-mbr"):
             self.message('Installing MBR')
@@ -477,7 +486,7 @@ class VmDebootstrap(cliapp.Application):
             self.runcmd(['chroot', rootdir, 'update-grub'])
             self.runcmd(['chroot', rootdir, 'grub-install', install_dev])
         except cliapp.AppException as e:
-            self.message("Failed to configure grub2. Using extlinux.")
+            self.message("Failed. Is grub2-common installed? Using extlinux.")
         self.runcmd(['umount', os.path.join(rootdir, 'sys')])
         self.runcmd(['umount', os.path.join(rootdir, 'proc')])
         self.runcmd(['umount', os.path.join(rootdir, 'dev')])
@@ -539,9 +548,10 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         """
         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])
+        if not self.settings['sparse']:
+            zeros = os.path.join(rootdir, 'ZEROS')
+            self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M'])
+            self.runcmd(['rm', '-f', zeros])
 
     def squash(self):
         """