]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
add mbr back to support extlinux and check for installation of mbr.
[forks/vmdebootstrap.git] / vmdebootstrap
index e736c604ce108422bcc6e8dfb68c54c910516111..500fa77e30a0d4e0d3fe86e2150f85fe5fe76906 100755 (executable)
@@ -158,7 +158,7 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             'Create an apt source based on the distribution and mirror selected.')
         self.settings.boolean(
             ['mbr'],
-            'Run install-mbr (no longer done by default)')
+            'Run install-mbr (default if extlinux used)')
         self.settings.boolean(
             ['grub'],
             'Install and configure grub2 - disables extlinux.')
@@ -187,7 +187,7 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             if self.settings['image']:
                 self.create_empty_image()
                 self.partition_image()
-                if self.settings['mbr']:
+                if self.settings['mbr'] or self.settings['extlinux']:
                     self.install_mbr()
                 (rootdev, bootdev) = self.setup_kpartx()
                 self.mkfs(rootdev, fstype=roottype)
@@ -340,6 +340,10 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         if os.path.exists("/sbin/install-mbr"):
             self.message('Installing MBR')
             self.runcmd(['install-mbr', self.settings['image']])
+        else:
+            msg = "mbr enabled but /sbin/install-mbr not found" 
+            " - please install the mbr package."
+            raise cliapp.AppException(msg)
 
     def setup_kpartx(self):
         bootindex = None
@@ -600,11 +604,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
 
@@ -616,11 +618,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'])