X-Git-Url: https://git.siccegge.de//index.cgi?p=forks%2Fvmdebootstrap.git;a=blobdiff_plain;f=vmdebootstrap;h=8301bd5c6452ee333d232c412bf42e4efadebc91;hp=89739c59c0839a2ef9f1b98c6ce3635a89ca17fe;hb=41f88537a1fd6363a0b2da9796a176f5a727e279;hpb=55ebe9480253cef01c3c092a50659bf70f9abc2a diff --git a/vmdebootstrap b/vmdebootstrap index 89739c5..8301bd5 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -1,6 +1,7 @@ #!/usr/bin/python # Copyright 2011-2013 Lars Wirzenius # Copyright 2012 Codethink Limited +# Copyright 2014 Neil Williams # # 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,14 +27,14 @@ import tempfile import time -__version__ = '0.3' +__version__ = '0.4' class VmDebootstrap(cliapp.Application): def add_settings(self): default_arch = subprocess.check_output( - ["dpkg", "--print-architecture"]).strip() + ["dpkg", "--print-architecture"]).strip() self.settings.boolean(['verbose'], 'report what is going on') self.settings.string(['image'], 'put created disk image in FILE', @@ -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) @@ -163,6 +161,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) @@ -199,11 +199,11 @@ class VmDebootstrap(cliapp.Application): if self.settings['verbose']: print msg - def runcmd(self, argv, stdin='', ignore_fail=False, **kwargs): - logging.debug('runcmd: %s %s' % (argv, kwargs)) + def runcmd(self, argv, stdin='', ignore_fail=False, env=None, **kwargs): + logging.debug('runcmd: %s %s %s' % (argv, env, kwargs)) p = subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - **kwargs) + env=env, **kwargs) out, err = p.communicate(stdin) if p.returncode != 0: msg = 'command failed: %s\n%s\n%s' % (argv, out, err) @@ -250,6 +250,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') @@ -304,8 +310,9 @@ class VmDebootstrap(cliapp.Application): include.append('sudo') args = ['debootstrap', '--arch=%s' % self.settings['arch']] - args.append( - '--include=%s' % ','.join(necessary_packages + include)) + if self.settings['package'] and len(necessary_packages) > 0: + args.append( + '--include=%s' % ','.join(necessary_packages + include)) if self.settings['foreign']: args.append('--foreign') if self.settings['variant']: @@ -316,13 +323,22 @@ class VmDebootstrap(cliapp.Application): logging.debug(" ".join(args)) self.runcmd(args) if self.settings['foreign']: + # set a noninteractive debconf environment for secondstage + env = { + "DEBIAN_FRONTEND": "noninteractive", + "DEBCONF_NONINTERACTIVE_SEEN": "true", + "LC_ALL": "C" + } + # add the mapping to the complete environment. + env.update(os.environ) # First copy the binfmt handler over self.message('Setting up binfmt handler') shutil.copy(self.settings['foreign'], '%s/usr/bin/' % rootdir) # Next, run the package install scripts etc. self.message('Running debootstrap second stage') self.runcmd(['chroot', rootdir, - '/debootstrap/debootstrap', '--second-stage']) + '/debootstrap/debootstrap', '--second-stage'], + env=env) def set_hostname(self, rootdir): hostname = self.settings['hostname'] @@ -467,7 +483,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')]) @@ -488,8 +504,13 @@ class VmDebootstrap(cliapp.Application): return os.path.join('boot', basename) raise cliapp.AppException('Cannot find match: %s' % pattern) - kernel_image = find('vmlinuz-.*') - initrd_image = find('initrd.img-.*') + try: + kernel_image = find('vmlinuz-.*') + initrd_image = find('initrd.img-.*') + except cliapp.AppException as e: + self.message("Unable to find kernel. Not installing extlinux.") + logging.debug("No kernel found. %s. Skipping install of extlinux." % e) + return out = self.runcmd(['blkid', '-c', '/dev/null', '-o', 'value', '-s', 'UUID', rootdev])