redhat-upgrade-tool/SOURCES/0003-Fix-grub-conf-paths-du...

45 lines
1.9 KiB
Diff

From 0b9d8cea86f36174f419cd4dfb8df5e1ffd536dc Mon Sep 17 00:00:00 2001
From: Petr Stodulka <pstodulk@redhat.com>
Date: Tue, 21 Jul 2020 03:22:11 +0200
Subject: [PATCH] Fix grub conf paths during the rollback
---
redhat_upgrade_tool/rollback/bootloader.py | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/redhat_upgrade_tool/rollback/bootloader.py b/redhat_upgrade_tool/rollback/bootloader.py
index f0c384a..aff23f4 100644
--- a/redhat_upgrade_tool/rollback/bootloader.py
+++ b/redhat_upgrade_tool/rollback/bootloader.py
@@ -13,9 +13,25 @@ try:
from redhat_upgrade_tool import grub_conf_file
from redhat_upgrade_tool.util import check_call
except ImportError:
- grub_conf_file = "/boot/grub/grub.conf"
+ _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):
- grub_conf_file = "/boot/efi/EFI/redhat/grub.conf"
+ 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
def check_call(*popenargs, **kwargs):
retcode = call(*popenargs, **kwargs)
--
2.25.4