X-Git-Url: https://git.siccegge.de//index.cgi?a=blobdiff_plain;f=vmdebootstrap;h=b66a84ed182a87706ebd7fb786f130d4395f1815;hb=cb04e42938bb06d3168072729382e0ad692aef47;hp=6f104da5ea487aa824b3673e013ecfb34c644e23;hpb=41ebf61957c1c3d168b5e048e465c6a7b0b57a1c;p=forks%2Fvmdebootstrap.git diff --git a/vmdebootstrap b/vmdebootstrap index 6f104da..b66a84e 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -158,13 +158,13 @@ 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.') self.settings.boolean( ['sparse'], - 'Dont fill the image with zeros to keep a sparse disk image', + 'Do not fill the image with zeros to keep a sparse disk image', default=False) self.settings.boolean( ['pkglist'], @@ -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 @@ -356,7 +360,9 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth for line in out.splitlines() if line.startswith('add map ')] if len(devices) != parts: - raise cliapp.AppException('Surprising number of partitions') + msg = 'Surprising number of partitions' + logging.debug("%s: devices=%s parts=%s", msg, devices, parts) + raise cliapp.AppException(msg) root = '/dev/mapper/%s' % devices[rootindex] if self.settings['bootsize']: boot = '/dev/mapper/%s' % devices[bootindex] @@ -370,15 +376,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': @@ -392,12 +396,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']: @@ -604,11 +606,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 @@ -620,11 +620,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']) @@ -698,16 +703,20 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s def chown(self): # Change image owner after completed build + if self.settings['image']: + filename = self.settings['image'] + elif self.settings['tarball']: + filename = self.settings['tarball'] + else: + return self.message("Changing owner to %s" % self.settings["owner"]) - subprocess.call(["chown", - self.settings["owner"], - self.settings["image"]]) + subprocess.call(["chown", self.settings["owner"], filename]) def list_installed_pkgs(self, rootdir): # output the list of installed packages for sources identification self.message("Creating a list of installed binary package names") out = self.runcmd(['chroot', rootdir, - 'dpkg-query', '-W' "-f='${Package}.deb\n'"]) + 'dpkg-query', '-W', "-f='${Package}.deb\n'"]) with open('dpkg.list', 'w') as dpkg: dpkg.write(out) @@ -727,6 +736,8 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s line = '#deb-src %s %s main\n' % (mirror, self.settings['distribution']) f.write(line) f.close() + # ensure the apt sources have valid lists + self.runcmd(['chroot', rootdir, 'apt-get', 'update']) if __name__ == '__main__': VmDebootstrap(version=__version__).run()