]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
fix creation of extlinux configuration
[forks/vmdebootstrap.git] / vmdebootstrap
index aae437a9120e5ceaab66e7a18fab1913badd9eea..99ef25622f39e093bd5782cc632c55bb9b211151 100755 (executable)
@@ -292,17 +292,41 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
                      str(self.settings['size'])])
 
     def partition_image(self):
+        """
+        Uses fat16 (msdos) partitioning by default, use part-type to change.
+        If bootoffset is specified, the first actual partition
+        starts at that offset to allow customisation scripts to
+        put bootloader images into the space, e.g. u-boot.
+        """
         self.message('Creating partitions')
         self.runcmd(['parted', '-s', self.settings['image'],
-                     'mklabel', 'msdos'])
+                     'mklabel', self.settings['part-type']])
+        partoffset = 0
+        bootsize = 0
+        if self.settings['bootoffset'] and self.settings['bootoffset'] is not '0':
+            # turn v.small offsets into something at least possible to create.
+            if self.settings['bootoffset'] < 1048576:
+                partoffset = 1
+                logging.info(
+                    "Setting bootoffset %smib to allow for %s bytes",
+                    partoffset, self.settings['bootoffset'])
+            else:
+                partoffset = self.settings['bootoffset'] / (1024 * 1024)
+                self.message("Using bootoffset: %smib %s bytes" % (partoffset, self.settings['bootoffset']))
         if self.settings['bootsize'] and self.settings['bootsize'] is not '0%':
-            bootsize = str(self.settings['bootsize'] / (1024 * 1024))
+            bootsize = self.settings['bootsize'] / (1024 * 1024)
+            bootsize += partoffset
+            self.message("Using bootsize %smib: %s bytes" % (bootsize, self.settings['bootsize']))
+            logging.debug("Starting boot partition at %sMb", bootsize)
             self.runcmd(['parted', '-s', self.settings['image'],
-                         'mkpart', 'primary', 'fat16', '0%', bootsize])
+                         'mkpart', 'primary', 'fat16', str(partoffset), str(bootsize)])
+        if partoffset == 0:
+            self.runcmd(['parted', '-s', self.settings['image'],
+                         'mkpart', 'primary', '0%', '100%'])
         else:
-            bootsize = '0%'
-        self.runcmd(['parted', '-s', self.settings['image'],
-                     'mkpart', 'primary', bootsize, '100%'])
+            logging.debug("Starting root partition at %sMb", partoffset)
+            self.runcmd(['parted', '-s', self.settings['image'],
+                         'mkpart', 'primary', str(bootsize), '100%'])
         self.runcmd(['parted', '-s', self.settings['image'],
                      'set', '1', 'boot', 'on'])
 
@@ -346,15 +370,13 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         msg = "(%s)" % self.settings['variant'] if self.settings['variant'] else ''
         self.message('Debootstrapping %s %s' % (self.settings['distribution'], msg))
 
-        if self.settings['foreign']:
-            necessary_packages = []
-        else:
-            necessary_packages = ['acpid']
+        include = self.settings['package']
 
-        if self.settings['grub']:
-            necessary_packages.append('grub2')
+        if not self.settings['foreign']:
+            include.append('acpid')
 
-        include = self.settings['package']
+        if self.settings['grub']:
+            include.append('grub2')
 
         if not self.settings['no-kernel']:
             if self.settings['arch'] == 'i386':
@@ -368,12 +390,10 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             include.append('sudo')
 
         args = ['debootstrap', '--arch=%s' % self.settings['arch']]
+
         if self.settings['package']:
             args.append(
                 '--include=%s' % ','.join(include))
-            if len(necessary_packages) > 0:
-                args.append(
-                    '--include=%s' % ','.join(necessary_packages))
         if self.settings['foreign']:
             args.append('--foreign')
         if self.settings['variant']:
@@ -580,11 +600,9 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
 
         conf = os.path.join(rootdir, 'extlinux.conf')
         logging.debug('configure extlinux %s', conf)
-        # python multiline string substitution is just ugly.
-        # use an external file or live with the mangling, no point in
-        # mangling the string to remove spaces just to keep it pretty in source.
-        f = open(conf, 'w')
-        f.write('''
+        kserial = 'console=ttyS0,115200' if self.settings['serial-console'] else ''
+        extserial = 'serial 0 115200' if self.settings['serial-console'] else ''
+        msg = '''
 default linux
 timeout 1
 
@@ -596,11 +614,16 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
             'kernel': kernel_image,  # pylint: disable=bad-continuation
             'initrd': initrd_image,  # pylint: disable=bad-continuation
             'uuid': uuid,  # pylint: disable=bad-continuation
-            'kserial':  # pylint: disable=bad-continuation
-            'console=ttyS0,115200' if self.settings['serial-console'] else '',  # pylint: disable=bad-continuation
-            'extserial': 'serial 0 115200' if self.settings['serial-console'] else '',  # pylint: disable=bad-continuation
-        })  # pylint: disable=bad-continuation
-        f.close()  # pylint: disable=bad-continuation
+            'kserial': kserial,  # pylint: disable=bad-continuation
+            'extserial': extserial,  # pylint: disable=bad-continuation
+        }  # pylint: disable=bad-continuation
+        logging.debug("extlinux config:\n%s", msg)
+
+        # python multiline string substitution is just ugly.
+        # use an external file or live with the mangling, no point in
+        # mangling the string to remove spaces just to keep it pretty in source.
+        f = open(conf, 'w')
+        f.write(msg)
 
         self.runcmd(['extlinux', '--install', rootdir])
         self.runcmd(['sync'])
@@ -662,8 +685,9 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
                 return
             script = example
         self.message('Running customize script %s' % script)
+        logging.info("rootdir=%s image=%s", rootdir, self.settings['image'])
         with open('/dev/tty', 'w') as tty:
-            cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty)
+            cliapp.runcmd([script, rootdir, self.settings['image']], stdout=tty, stderr=tty)
 
     def create_tarball(self, rootdir):
         # Create a tarball of the disk's contents