128 lines
5.6 KiB
Diff
128 lines
5.6 KiB
Diff
From 58762e6f2bd9a6e42933aafbfc073de28c9918d2 Mon Sep 17 00:00:00 2001
|
|
From: Petr Stodulka <pstodulk@redhat.com>
|
|
Date: Fri, 31 Jul 2020 14:47:57 +0200
|
|
Subject: [PATCH] Fix detection of the grub configuration path
|
|
|
|
Previos solution was still buggy. Discussed with the bootloader team,
|
|
the solution has been updated for redhat-upgrade-tool (not for boom!).
|
|
When the redhat-upgrade-tool is executed, only one configuration file
|
|
will remain.
|
|
---
|
|
redhat_upgrade_tool/__init__.py | 45 ++++++++++++++++++++--
|
|
redhat_upgrade_tool/rollback/bootloader.py | 43 +++++++++++++--------
|
|
2 files changed, 69 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/redhat_upgrade_tool/__init__.py b/redhat_upgrade_tool/__init__.py
|
|
index 1e0b1b3..9e1fecd 100644
|
|
--- a/redhat_upgrade_tool/__init__.py
|
|
+++ b/redhat_upgrade_tool/__init__.py
|
|
@@ -67,8 +67,47 @@ rhel_gpgkey_path = 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release'
|
|
preupgrade_dir = "/root/preupgrade"
|
|
preupgrade_script_path = os.path.join(preupgrade_dir, 'preupgrade-scripts')
|
|
release_version_file = os.path.join(preupgrade_dir, preupgrade_script_path, 'release_version')
|
|
-grub_conf_file = "/boot/grub/grub.conf"
|
|
-if not os.path.exists(grub_conf_file):
|
|
- grub_conf_file = "/boot/efi/EFI/redhat/grub.conf"
|
|
+
|
|
+def detect_grub_conf():
|
|
+ """
|
|
+ Detect the right path of the grub configuration file and shot the another
|
|
+ one if exist.
|
|
+
|
|
+ This is really needed.
|
|
+ """
|
|
+ _BIOS_GRUB_CONF_PATH = "/boot/grub/grub.conf"
|
|
+ _EFI_GRUB_CONF_PATH = "/boot/efi/EFI/redhat/grub.conf"
|
|
+
|
|
+ # regarding https://access.redhat.com/solutions/3781221 - this should
|
|
+ # be enough for RHEL 6
|
|
+ if os.path.exists("/sys/firmware/efi"):
|
|
+ # we should be on EFI
|
|
+ grub_conf_file = _EFI_GRUB_CONF_PATH
|
|
+ _non_grub_file = _BIOS_GRUB_CONF_PATH
|
|
+ else:
|
|
+ # we are on BIOS
|
|
+ grub_conf_file = _BIOS_GRUB_CONF_PATH
|
|
+ _non_grub_file = _EFI_GRUB_CONF_PATH
|
|
+ if not os.path.exists(grub_conf_file) or not os.path.getsize(grub_conf_file):
|
|
+ # that's fatal error. It shouldn't happened
|
|
+ raise Exception(
|
|
+ "The expected grub configuration file doesn't exist or it is empty: %s" % grub_conf_file)
|
|
+
|
|
+ if os.path.exists(_non_grub_file):
|
|
+ # it's wrong that both files exist, if it's empty, remove it,
|
|
+ # otherwise rename it
|
|
+ if not os.path.getsize(_non_grub_file):
|
|
+ # Note: this is typical case after IPU 6 -> 7 for EFI
|
|
+ # remove the empty file
|
|
+ os.remove(_non_grub_file)
|
|
+ else:
|
|
+ # this is really weird when it happens
|
|
+ print "WARNING: Detected two grub configuration files, but only one can exist"
|
|
+ print "WARNING: Moving {fname} to {fname}.preupg_rollback_backup".format(fname=_non_grub_file)
|
|
+ shutil.move(_non_grub_file, "{}.preupg_rollback_backup".format(_non_grub_file))
|
|
+ return grub_conf_file
|
|
+
|
|
+
|
|
+grub_conf_file = detect_grub_conf()
|
|
|
|
MIN_AVAIL_BYTES_FOR_BOOT = 50 * 2**20 # 50 MiB
|
|
diff --git a/redhat_upgrade_tool/rollback/bootloader.py b/redhat_upgrade_tool/rollback/bootloader.py
|
|
index aff23f4..2f605ff 100644
|
|
--- a/redhat_upgrade_tool/rollback/bootloader.py
|
|
+++ b/redhat_upgrade_tool/rollback/bootloader.py
|
|
@@ -15,23 +15,34 @@ try:
|
|
except ImportError:
|
|
_BIOS_GRUB_CONF_PATH = "/boot/grub/grub.conf"
|
|
_EFI_GRUB_CONF_PATH = "/boot/efi/EFI/redhat/grub.conf"
|
|
- grub_conf_file = _BIOS_GRUB_CONF_PATH
|
|
- if not os.path.exists(grub_conf_file):
|
|
+
|
|
+ # regarding https://access.redhat.com/solutions/3781221 - this should
|
|
+ # be enough for RHEL 6
|
|
+ if os.path.exists("/sys/firmware/efi"):
|
|
+ # we should be on EFI
|
|
grub_conf_file = _EFI_GRUB_CONF_PATH
|
|
- elif os.path.exists(_EFI_GRUB_CONF_PATH):
|
|
- if not os.path.getsize(grub_conf_file):
|
|
- # it can happen that both files (usually on EFI systems) exists,
|
|
- # but the BIOS one is empty in such a case
|
|
- os.remove(grub_conf_file)
|
|
- grub_conf_file = _EFI_GRUB_CONF_PATH
|
|
- elif os.path.exists("/sys/firmware/efi"):
|
|
- # ok, the 'bios' file is not empty
|
|
- # rather move it instead of real remove, as this is weird
|
|
- shutil.move(grub_conf_file, "{}.preupg_rollback_backup".format(grub_conf_file))
|
|
- grub_conf_file = _EFI_GRUB_CONF_PATH
|
|
- # else:
|
|
- # regarding https://access.redhat.com/solutions/3781221 - we can consider
|
|
- # the system is booted in BIOS mode; do nothing
|
|
+ _non_grub_file = _BIOS_GRUB_CONF_PATH
|
|
+ else:
|
|
+ # we are on BIOS
|
|
+ grub_conf_file = _BIOS_GRUB_CONF_PATH
|
|
+ _non_grub_file = _EFI_GRUB_CONF_PATH
|
|
+ if not os.path.exists(grub_conf_file) or not os.path.getsize(grub_conf_file):
|
|
+ # that's fatal error. It shouldn't happened
|
|
+ raise Exception(
|
|
+ "The expected grub configuration file doesn't exist or it is empty: %s" % grub_conf_file)
|
|
+
|
|
+ if os.path.exists(_non_grub_file):
|
|
+ # it's wrong that both files exist, if it's empty, remove it,
|
|
+ # otherwise rename it
|
|
+ if not os.path.getsize(_non_grub_file):
|
|
+ # Note: this is typical case after IPU 6 -> 7 for EFI
|
|
+ # remove the empty file
|
|
+ os.remove(_non_grub_file)
|
|
+ else:
|
|
+ # this is really weird when it happens
|
|
+ print "WARNING: Detected two grub configuration files, but only one can exist"
|
|
+ print "WARNING: Moving {fname} to {fname}.preupg_rollback_backup".format(fname=_non_grub_file)
|
|
+ shutil.move(_non_grub_file, "{}.preupg_rollback_backup".format(_non_grub_file))
|
|
|
|
def check_call(*popenargs, **kwargs):
|
|
retcode = call(*popenargs, **kwargs)
|
|
--
|
|
2.25.4
|
|
|