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',
'is complete.')
self.settings.boolean(['squash'],
'use squashfs on the final image.')
+ self.settings.boolean(['configure-apt'],
+ 'Create an apt source based on the distribution '
+ 'and mirror selected.')
def process_args(self, args):
if not self.settings['image'] and not self.settings['tarball']:
roottype = 'ext4'
bootdev = None
boottype = None
+ rootdir = None
if self.settings['image']:
self.create_empty_image()
self.partition_image()
self.create_users(rootdir)
self.remove_udev_persistent_rules(rootdir)
self.setup_networking(rootdir)
+ if self.settings['configure-apt']:
+ self.configure_apt(rootdir)
self.customize(rootdir)
if self.settings['image']:
if self.settings['extlinux']:
self.chown(rootdir)
except BaseException, e:
self.message('EEEK! Something bad happened...')
+ if rootdir:
+ db_log = os.path.join(rootdir, 'debootstrap', 'debootstrap.log')
+ if os.path.exists(db_log):
+ shutil.copy(db_log, os.getcwd())
self.message(e)
self.cleanup_system()
raise
'set', '1', 'boot', 'on'])
def install_mbr(self):
- self.message('Installing MBR')
- self.runcmd(['install-mbr', self.settings['image']])
+ if os.path.exists("/sbin/install-mbr"):
+ self.message('Installing MBR')
+ self.runcmd(['install-mbr', self.settings['image']])
def setup_kpartx(self):
out = self.runcmd(['kpartx', '-avs', self.settings['image']])
args.append(self.settings['variant'])
args += [self.settings['distribution'],
rootdir, self.settings['mirror']]
+ logging.debug(" ".join(args))
self.runcmd(args)
if self.settings['foreign']:
# First copy the binfmt handler over
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'])
f.write('\nS0:23:respawn:%s\n' % serial_command)
def install_extlinux(self, rootdev, rootdir):
+ if not os.path.exists("/usr/bin/extlinux"):
+ self.message("extlinux not installed, skipping.")
+ return
self.message('Installing extlinux')
def find(pattern):
self.settings["owner"],
self.settings["image"]])
+ def configure_apt(self, rootdir):
+ # use the distribution and mirror to create an apt source
+ self.message("Configuring apt to use distribution and mirror")
+ conf = os.path.join(rootdir, 'etc', 'apt', 'sources.list.d', 'base.list')
+ 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
+''' % {
+ 'mirror': self.settings['mirror'],
+ 'distribution': self.settings['distribution']
+ })
+ f.close()
+
if __name__ == '__main__':
VmDebootstrap(version=__version__).run()