diff options
author | Neil Williams <codehelp@debian.org> | 2015-08-17 13:16:35 +0200 |
---|---|---|
committer | Neil Williams <codehelp@debian.org> | 2015-08-18 11:12:41 +0200 |
commit | bc7ef0f9a3df88424ab594fe13a4322b408f6718 (patch) | |
tree | df2f1f0a7b8fe661a083e059eb923e8a280080bd | |
parent | 54212e6812319e288a9ecd1a4d032b23ea9ae4ea (diff) | |
download | vmdebootstrap-bc7ef0f9a3df88424ab594fe13a4322b408f6718.tar.gz |
check that the ESP is mounted before trying to configure
-rwxr-xr-x | bin/vmdebootstrap | 12 | ||||
-rw-r--r-- | vmdebootstrap/grub.py | 18 | ||||
-rw-r--r-- | vmdebootstrap/uefi.py | 19 |
3 files changed, 38 insertions, 11 deletions
diff --git a/bin/vmdebootstrap b/bin/vmdebootstrap index b13d976..2dc46a4 100755 --- a/bin/vmdebootstrap +++ b/bin/vmdebootstrap @@ -260,11 +260,15 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth rootdir = self.mount(rootdev) filesystem.devices['rootdir'] = rootdir if self.settings['use-uefi']: - self.mount(bootdev, uefi.prepare_esp(rootdir, bootdev)) + self.bootdir = uefi.prepare_esp(rootdir, bootdev) + logging.debug("mounting %s", self.bootdir) + self.mount(bootdev, self.bootdir) + logging.debug(runcmd(['mount'])) elif bootdev: boottype = self.settings['boottype'] filesystem.mkfs(bootdev, fstype=boottype) self.bootdir = '%s/%s' % (rootdir, 'boot/') + filesystem.devices['bootdir'] = self.bootdir os.mkdir(self.bootdir) self.mount(bootdev, self.bootdir) @@ -278,6 +282,12 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth uefi = self.handlers[Uefi.name] filesystem = self.handlers[Filesystem.name] if self.settings['use-uefi']: + bootdir = self.bootdir + logging.debug("rootdir=%s rootdev=%s bootdir=%s", rootdir, rootdev, bootdir) + logging.debug(runcmd(['mount'])) + if not os.path.ismount(bootdir): + self.logging.warning("%s had to be remounted", bootdir) + self.mount(bootdir) grub.install_grub_uefi(rootdir) uefi.configure_efi(rootdir) grub.install_extra_grub_uefi(rootdir) diff --git a/vmdebootstrap/grub.py b/vmdebootstrap/grub.py index e348a53..909c2d1 100644 --- a/vmdebootstrap/grub.py +++ b/vmdebootstrap/grub.py @@ -75,6 +75,7 @@ class GrubHandler(Base): return True def install_grub_uefi(self, rootdir): + ret = True self.message("Configuring grub-uefi") target = arch_table[self.settings['arch']]['target'] grub_opts = "--target=%s" % target @@ -85,22 +86,33 @@ class GrubHandler(Base): runcmd(['chroot', rootdir, 'grub-install', grub_opts]) except cliapp.AppException as exc: logging.warning(exc) + ret = False self.message( "Failed to configure grub-uefi for %s" % self.settings['arch']) - umount_wrapper(rootdir) + finally: + umount_wrapper(rootdir) + if not ret: + raise cliapp.AppException("Failed to install grub uefi") def install_extra_grub_uefi(self, rootdir): - extra = str(arch_table[self.settings['arch']]['extra']) + ret = True + extra = arch_table[self.settings['arch']]['extra'] if extra: + logging.debug("Installing extra grub support for %s", extra) mount_wrapper(rootdir) target = arch_table[extra]['target'] grub_opts = "--target=%s" % target + self.message("Adding grub target %s" % grub_opts) try: runcmd(['chroot', rootdir, 'update-grub']) runcmd(['chroot', rootdir, 'grub-install', grub_opts]) except cliapp.AppException as exc: logging.warning(exc) + ret = False self.message( "Failed to configure grub-uefi for %s" % extra) - umount_wrapper(rootdir) + finally: + umount_wrapper(rootdir) + if not ret: + raise cliapp.AppException("Failed to install extra grub uefi") diff --git a/vmdebootstrap/uefi.py b/vmdebootstrap/uefi.py index 6f4b3bf..2a8bc2a 100644 --- a/vmdebootstrap/uefi.py +++ b/vmdebootstrap/uefi.py @@ -58,16 +58,16 @@ class Uefi(Base): def copy_efi_binary(self, efi_removable, efi_install): logging.debug("using bootdir=%s", self.bootdir) - logging.debug("moving %s to %s", efi_removable, efi_install) if efi_removable.startswith('/'): efi_removable = efi_removable[1:] if efi_install.startswith('/'): efi_install = efi_install[1:] efi_output = os.path.join(self.bootdir, efi_removable) efi_input = os.path.join(self.bootdir, efi_install) + logging.debug("moving %s to %s", efi_output, efi_input) if not os.path.exists(efi_input): logging.warning("%s does not exist (%s)", efi_input, efi_install) - raise cliapp.AppException("Missing %s" % efi_install) + raise cliapp.AppException("Missing %s" % efi_input) if not os.path.exists(os.path.dirname(efi_output)): os.makedirs(os.path.dirname(efi_output)) logging.debug( @@ -86,18 +86,23 @@ class Uefi(Base): efi_removable = str(arch_table[self.settings['arch']]['removable']) efi_install = str(arch_table[self.settings['arch']]['install']) self.message('Installing UEFI support binary') - self.copy_efi_binary(efi_removable, efi_install) - umount_wrapper(rootdir) + logging.debug("moving %s to %s", efi_removable, efi_install) + try: + self.copy_efi_binary(efi_removable, efi_install) + finally: + umount_wrapper(rootdir) def configure_extra_efi(self, rootdir): - extra = str(arch_table[self.settings['arch']]['extra']) + extra = arch_table[self.settings['arch']]['extra'] if extra: mount_wrapper(rootdir) efi_removable = str(arch_table[extra]['removable']) efi_install = str(arch_table[extra]['install']) self.message('Copying UEFI support binary for %s' % extra) - self.copy_efi_binary(efi_removable, efi_install) - umount_wrapper(rootdir) + try: + self.copy_efi_binary(efi_removable, efi_install) + finally: + umount_wrapper(rootdir) def partition_esp(self): espsize = self.settings['esp-size'] / (1024 * 1024) |