X-Git-Url: https://git.siccegge.de//index.cgi?a=blobdiff_plain;ds=sidebyside;f=vmdebootstrap;h=67ea2c867ca785d24e2b2a1d8204ceaa9280126c;hb=5413ccc44b905facd55fbb0812b7c9e350deb44f;hp=e44fe1e5a5ca2f10434c786fa89bf8846b1ed34a;hpb=c8fd9ca4ba4e8877bc5d073c4b238e7f0af299b0;p=forks%2Fvmdebootstrap.git diff --git a/vmdebootstrap b/vmdebootstrap index e44fe1e..67ea2c8 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -30,7 +30,7 @@ import time from distro_info import DebianDistroInfo, UbuntuDistroInfo -__version__ = '0.9' +__version__ = '0.11' # pylint: disable=invalid-name,line-too-long,missing-docstring,too-many-branches @@ -125,7 +125,10 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth 'set up foreign debootstrap environment using provided program (ie binfmt handler)') self.settings.string( ['variant'], - 'select debootstrap variant it not using the default') + 'select debootstrap variant if not using the default [deprecated]') + self.settings.string_list( + ['debootstrapopts'], + 'pass additional options to debootstrap'), self.settings.boolean( ['extlinux'], 'install extlinux?', @@ -243,7 +246,8 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth if not self.settings['use-uefi'] and self.settings['esp-size'] != 5242880: raise cliapp.AppException( 'You must specify use-uefi for esp-size to have effect') - if self.efi_arch_table[self.settings['arch']]['exclusive'] and\ + if self.settings['arch'] in self.efi_arch_table and\ + self.efi_arch_table[self.settings['arch']]['exclusive'] and\ not self.settings['use-uefi']: raise cliapp.AppException( 'Only UEFI is supported on %s' % self.settings['arch']) @@ -262,7 +266,7 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth # wheezy (which became oldstable on 04/25/2015) only had amd64 uefi if self.was_oldstable(datetime.date(2015, 4, 26)): - if self.settings['arch'] != 'amd64': + if self.settings['use-uefi'] and self.settings['arch'] != 'amd64': raise cliapp.AppException( 'Only amd64 supports UEFI in Wheezy') @@ -640,7 +644,11 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth '--include=%s' % ','.join(include)) if self.settings['foreign']: args.append('--foreign') - if self.settings['variant']: + if self.settings['debootstrapopts']: + for opt in self.settings['debootstrapopts']: + for part in opt.split(' '): + args.append('--%s' % part) + elif self.settings['variant']: args.append('--variant') args.append(self.settings['variant']) args += [self.settings['distribution'], @@ -776,20 +784,34 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth else: logging.debug('not removing non-existent %s', pathname) + def mask_udev_predictable_rules(self, rootdir): + """ + This can be reset later but to get networking working immediately + on boot, the interface we're going to use must be known without + reference to the eventual machine. + http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ + """ + self.message('Disabling systemd predictable interface names') + udev_path = os.path.join( + 'etc', 'udev', 'rules.d', '80-net-setup-link.rules') + self.runcmd(['chroot', rootdir, 'ln', '-s', '/dev/null', udev_path]) + def setup_networking(self, rootdir): self.message('Setting up networking') + ifc_file = os.path.join(rootdir, 'etc', 'network', 'interfaces') + ifc_d = os.path.join(rootdir, 'etc', 'network', 'interfaces.d') - # unconditionally write for wheezy (which became oldstable on 04/25/2015) + # unconditionally write for wheezy (which became oldstable 2015.04.25) if self.was_oldstable(datetime.date(2015, 4, 26)): - with open(os.path.join(rootdir, 'etc', 'network', 'interfaces'), 'w') as netfile: + with open(ifc_file, 'w') as netfile: netfile.write('source /etc/network/interfaces.d/*\n') - os.mkdir(os.path.join(rootdir, 'etc', 'network', 'interfaces.d')) - - elif not os.path.exists(os.path.join(rootdir, 'etc', 'network', 'interfaces')): - iface_path = os.path.join(rootdir, 'etc', 'network', 'interfaces') - with open(iface_path, 'w') as netfile: + elif not os.path.exists(ifc_file): + with open(ifc_file, 'a') as netfile: netfile.write('source-directory /etc/network/interfaces.d\n') - ethpath = os.path.join(rootdir, 'etc', 'network', 'interfaces.d', 'setup') + + if not os.path.exists(ifc_d): + os.mkdir(ifc_d) + ethpath = os.path.join(ifc_d, 'setup') with open(ethpath, 'w') as eth: eth.write('auto lo\n') eth.write('iface lo inet loopback\n') @@ -798,6 +820,8 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth eth.write('\n') eth.write('auto eth0\n') eth.write('iface eth0 inet dhcp\n') + # force predictable interface names + self.mask_udev_predictable_rules(rootdir) def append_serial_console(self, rootdir): if self.settings['serial-console']: @@ -1016,14 +1040,12 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s logging.debug( "%s usage: %s", self.settings['image'], self.runcmd(['du', self.settings['image']])) - with open('/dev/tty', 'w') as tty: - try: + try: + with open('/dev/tty', 'w') as tty: cliapp.runcmd([script, rootdir, self.settings['image']], stdout=tty, stderr=tty) - except IOError: - subprocess.call([script, rootdir, self.settings['image']]) - logging.debug( - "%s usage: %s", self.settings['image'], - self.runcmd(['du', self.settings['image']])) + except IOError: + logging.debug('tty unavailable, trying in headless mode.') + subprocess.call([script, rootdir, self.settings['image']]) def create_tarball(self, rootdir): # Create a tarball of the disk's contents