diff options
| author | Zuul <zuul@review.opendev.org> | 2020-07-02 10:37:04 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2020-07-02 10:37:04 +0000 |
| commit | de7d5affe7846151ae2d64c84e8617874c7a660a (patch) | |
| tree | 5c33ffc190812ce73d54e079cc31e7450a24fe59 /ironic_python_agent/extensions | |
| parent | c1c093fc2e56411bb9f677034b4925aaed624d6d (diff) | |
| parent | c5022790b3dca80c009e914aa07f3f879cd159b4 (diff) | |
| download | ironic-python-agent-de7d5affe7846151ae2d64c84e8617874c7a660a.tar.gz | |
Merge "Mount all vfat partitions before calling grub2"
Diffstat (limited to 'ironic_python_agent/extensions')
| -rw-r--r-- | ironic_python_agent/extensions/image.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index 7362ebe3..e0138a7c 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -497,6 +497,13 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None, return try: + # Add /bin to PATH variable as grub requires it to find efibootmgr + # when running in uefi boot mode. + # Add /usr/sbin to PATH variable to ensure it is there as we do + # not use full path to grub binary anymore. + path_variable = os.environ.get('PATH', '') + path_variable = '%s:/bin:/usr/sbin:/sbin' % path_variable + # Mount the partition and binds path = tempfile.mkdtemp() if efi_system_part_uuid: @@ -533,12 +540,13 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None, if os.path.exists(os.path.join(path, 'usr/sbin/grub2-install')): binary_name = "grub2" - # Add /bin to PATH variable as grub requires it to find efibootmgr - # when running in uefi boot mode. - # Add /usr/sbin to PATH variable to ensure it is there as we do - # not use full path to grub binary anymore. - path_variable = os.environ.get('PATH', '') - path_variable = '%s:/bin:/usr/sbin:/sbin' % path_variable + # Mount all vfat partitions listed in the fstab of the root partition. + # This is to make sure grub2 finds all files it needs, as some of them + # may not be inside the root partition but in the ESP (like grub2env). + LOG.debug("Mounting all partitions inside the image ...") + utils.execute('chroot %(path)s /bin/sh -c "mount -a -t vfat"' % + {'path': path}, shell=True, + env_variables={'PATH': path_variable}) if efi_partitions: if not os.path.exists(efi_partition_mount_point): @@ -658,6 +666,16 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None, LOG.error(error_msg) raise errors.CommandExecutionError(error_msg) + # Umount the vfat partitions we may have mounted + LOG.debug("Unmounting all partitions inside the image ...") + try: + utils.execute('chroot %(path)s /bin/sh -c "umount -a -t vfat"' % + {'path': path}, shell=True, + env_variables={'PATH': path_variable}) + except processutils.ProcessExecutionError as e: + LOG.warning("Unable to umount vfat partitions. Error: %(error)s", + {'error': e}) + for fs in BIND_MOUNTS: try: utils.execute('umount', path + fs, attempts=3, |
