X-Git-Url: https://git.siccegge.de//index.cgi?a=blobdiff_plain;f=vmdebootstrap;h=546742985f7ec6d936f8ddab8d258618a22ba1f5;hb=cd21365ff16bb2a7224bd4815a7616a2aa639825;hp=5fd2a096c04fe189da1a96d482fcbee2e4af1057;hpb=df8518ebe4a429d68e814a7daae2621db132c61d;p=forks%2Fvmdebootstrap.git diff --git a/vmdebootstrap b/vmdebootstrap index 5fd2a09..5467429 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -33,7 +33,9 @@ __version__ = '0.3' class VmDebootstrap(cliapp.Application): def add_settings(self): - default_arch = 'amd64' + default_arch = self.runcmd( + ["dpkg", "--print-architecture"], + ignore_fail=False).strip() self.settings.boolean(['verbose'], 'report what is going on') self.settings.string(['image'], 'put created disk image in FILE', @@ -109,6 +111,11 @@ class VmDebootstrap(cliapp.Application): self.settings.boolean(['configure-apt'], 'Create an apt source based on the distribution ' 'and mirror selected.') + self.settings.boolean(['mbr'], + 'Run install-mbr (no longer done by default)') + self.settings.boolean(['grub'], + 'Install and configure grub2 - disables ' + 'extlinux.') def process_args(self, args): if not self.settings['image'] and not self.settings['tarball']: @@ -130,7 +137,8 @@ class VmDebootstrap(cliapp.Application): if self.settings['image']: self.create_empty_image() self.partition_image() - self.install_mbr() + if self.settings['mbr']: + self.install_mbr() (rootdev, bootdev) = self.setup_kpartx() self.mkfs(rootdev, type=roottype) rootdir = self.mount(rootdev) @@ -154,10 +162,13 @@ class VmDebootstrap(cliapp.Application): self.create_users(rootdir) self.remove_udev_persistent_rules(rootdir) self.setup_networking(rootdir) - self.configure_apt(rootdir) + if self.settings['configure-apt']: + self.configure_apt(rootdir) self.customize(rootdir) if self.settings['image']: - if self.settings['extlinux']: + if self.settings['grub']: + self.install_grub2(rootdev, rootdir) + elif self.settings['extlinux']: self.install_extlinux(rootdev, rootdir) self.append_serial_console(rootdir) self.optimize_image(rootdir) @@ -278,6 +289,9 @@ class VmDebootstrap(cliapp.Application): else: necessary_packages = ['acpid'] + if self.settings['grub']: + necessary_packages.append('grub2') + include = self.settings['package'] if not self.settings['no-kernel']: @@ -440,6 +454,26 @@ class VmDebootstrap(cliapp.Application): with open(inittab, 'a') as f: f.write('\nS0:23:respawn:%s\n' % serial_command) + def install_grub2(self, rootdev, rootdir): + self.message("Configuring grub2") + # rely on kpartx using consistent naming to map loop0p1 to loop0 + install_dev = os.path.join('/dev', os.path.basename(rootdev)[:-2]) + self.runcmd(['mount', '/dev', '-t', 'devfs', '-obind', + '%s' % os.path.join(rootdir, 'dev')]) + self.runcmd(['mount', '/proc', '-t', 'proc', '-obind', + '%s' % os.path.join(rootdir, 'proc')]) + self.runcmd(['mount', '/sys', '-t', 'sysfs', '-obind', + '%s' % os.path.join(rootdir, 'sys')]) + try: + 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.runcmd(['umount', os.path.join(rootdir, 'sys')]) + self.runcmd(['umount', os.path.join(rootdir, 'proc')]) + self.runcmd(['umount', os.path.join(rootdir, 'dev')]) + self.install_extlinux(rootdev, rootdir) + def install_extlinux(self, rootdev, rootdir): if not os.path.exists("/usr/bin/extlinux"): self.message("extlinux not installed, skipping.") @@ -533,10 +567,17 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s def customize(self, rootdir): script = self.settings['customize'] - if script: - self.message('Running customize script %s' % script) - with open('/dev/tty', 'w') as tty: - cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty) + if not script: + return + if not os.path.exists(script): + example = os.path.join("/usr/share/vmdebootstrap/examples/", script) + if not os.path.exists(example): + self.message("Unable to find %s" % script) + return + script = example + self.message('Running customize script %s' % script) + with open('/dev/tty', 'w') as tty: + cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty) def create_tarball(self, rootdir): # Create a tarball of the disk's contents @@ -558,9 +599,9 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s logging.debug('configure apt %s' % conf) f = open(conf, 'w') f.write(''' - deb %(mirror)s %(distribution)s main - #deb-src %(mirror)s %(distribution)s main - ''' % { +deb %(mirror)s %(distribution)s main +#deb-src %(mirror)s %(distribution)s main +''' % { 'mirror': self.settings['mirror'], 'distribution': self.settings['distribution'] })