155 lines
6.2 KiB
Diff
155 lines
6.2 KiB
Diff
From b00bd293df4703378dfe31b9e2402628db35cefa Mon Sep 17 00:00:00 2001
|
|
From: Petr Stodulka <pstodulk@redhat.com>
|
|
Date: Mon, 8 Mar 2021 23:09:12 +0100
|
|
Subject: [PATCH 1/2] UEFI fix [1/2]: Fix the broken bootloader when upgrade
|
|
without --cleanup-post
|
|
|
|
In case r-u-t is called without the --cleaup-post option, the
|
|
postupgrade script recovering the EFI (bin and config) files do not
|
|
recover the files because the legacy grub is still installed.
|
|
|
|
This is the first part of the fix that splits the original script
|
|
(used for pre & post upgrade actions) into the pre-upgrade and
|
|
post-upgrade scripts.
|
|
|
|
In the pre-upgrade script:
|
|
* fix backup of the EFI configuration file (originally switched order
|
|
target & source for the cp command, so the backup didn't happen
|
|
|
|
* stops upgrade (& log error) when the efibin does not exist
|
|
(but it has to exist as the EFI has been detected). There is no way
|
|
we could see the EFI binary is missing on a supported RHEL system.
|
|
However I've seen a system without mounted EFI partition and still
|
|
working by miracle. So putting this double-seatbelt just for sure.
|
|
Not any testing is expected for this particular case as such a system
|
|
is not supported at all for the upgrade.
|
|
|
|
In the post-upgrade script:
|
|
* Removed condition in the post-upgrade script checking whether EFI
|
|
binary exists or not as the recover of original files is always
|
|
expected.
|
|
- original bug is still present. this is just preparation to better
|
|
reflect the real problem in the post-upgrade script
|
|
|
|
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1915393
|
|
---
|
|
RHEL6_7/system/uefi/check | 8 +--
|
|
RHEL6_7/system/uefi/efibootorder_fix_post.sh | 53 +++++++++++++++++++
|
|
...otorder_fix.sh => efibootorder_fix_pre.sh} | 16 +++---
|
|
3 files changed, 64 insertions(+), 13 deletions(-)
|
|
create mode 100755 RHEL6_7/system/uefi/efibootorder_fix_post.sh
|
|
rename RHEL6_7/system/uefi/{efibootorder_fix.sh => efibootorder_fix_pre.sh} (76%)
|
|
|
|
diff --git a/RHEL6_7/system/uefi/check b/RHEL6_7/system/uefi/check
|
|
index 44cd542..3bb722a 100755
|
|
--- a/RHEL6_7/system/uefi/check
|
|
+++ b/RHEL6_7/system/uefi/check
|
|
@@ -24,10 +24,10 @@ command -v efibootmgr >/dev/null || {
|
|
}
|
|
|
|
# create pre-upgrade and post-upgrade scripts
|
|
-cp -a "efibootorder_fix.sh" "$PREUPGRADE_SCRIPT_DIR/"
|
|
-cp -a "efibootorder_fix.sh" "$POSTUPGRADE_DIR/"
|
|
-chmod +x "$PREUPGRADE_SCRIPT_DIR/efibootorder_fix.sh"
|
|
-chmod +x "$POSTUPGRADE_DIR/efibootorder_fix.sh"
|
|
+cp -a "efibootorder_fix_pre.sh" "$PREUPGRADE_SCRIPT_DIR/"
|
|
+cp -a "efibootorder_fix_post.sh" "$POSTUPGRADE_DIR/"
|
|
+chmod +x "$PREUPGRADE_SCRIPT_DIR/efibootorder_fix_pre.sh"
|
|
+chmod +x "$POSTUPGRADE_DIR/efibootorder_fix_post.sh"
|
|
|
|
log_medium_risk "The Legacy GRUB has to be migrated to GRUB 2 after the upgrade manually"
|
|
exit_fail
|
|
diff --git a/RHEL6_7/system/uefi/efibootorder_fix_post.sh b/RHEL6_7/system/uefi/efibootorder_fix_post.sh
|
|
new file mode 100755
|
|
index 0000000..27b29b5
|
|
--- /dev/null
|
|
+++ b/RHEL6_7/system/uefi/efibootorder_fix_post.sh
|
|
@@ -0,0 +1,53 @@
|
|
+#!/bin/bash
|
|
+
|
|
+log_info() {
|
|
+ echo >&2 "Info: $@"
|
|
+}
|
|
+
|
|
+log_error() {
|
|
+ echo >&2 "Error: $@"
|
|
+}
|
|
+
|
|
+log_info "Check the EFI:"
|
|
+efibootmgr || {
|
|
+ log_error "Something is wrong. Cannot use the efibootmgr utility"
|
|
+ exit 1
|
|
+}
|
|
+
|
|
+# the $efibin_path is removed during the upgrade as it is provided by the grub
|
|
+# rpm which is removed during the upgrade
|
|
+efibin_path="/boot/efi/EFI/redhat/grub.efi"
|
|
+eficonf_path="/boot/efi/EFI/redhat/grub.conf"
|
|
+
|
|
+# restore the files from the backup
|
|
+log_info "Restoring EFI files."
|
|
+cp -a ${efibin_path}{.preupg,}
|
|
+# we do not want to apply the backup of the configuration file,
|
|
+# as the backup will not contain probably working configuration; however,
|
|
+# in case the configuration file is already missing, it could be in some
|
|
+# rare cases better than nothing
|
|
+[ -e "$eficonf_path" ] || cp -a ${eficonf_path}{.preupg,}
|
|
+
|
|
+
|
|
+# e.g.: BootCurrent: 0001
|
|
+current_boot=$(efibootmgr | grep "^BootCurrent:" | cut -d ":" -f 2- | sed -r "s/^\s*(.*)\s*$/\1/" | grep -o "^[0-9A-F]*")
|
|
+[ -z "$current_boot" ] && {
|
|
+ log_error "Cannot detect the current EFI boot using the efibootmgr"
|
|
+ exit 1
|
|
+}
|
|
+log_info "The current EFI boot is: $current_boot"
|
|
+
|
|
+# e.g. BootNext: 0001
|
|
+next_boot=$(efibootmgr | grep "^BootNext:" | cut -d ":" -f 2- | sed -r "s/^\s*(.*)\s*$/\1/" | grep -o "^[0-9A-F]*")
|
|
+[ -z "$next_boot" ] && {
|
|
+ # We set BootNext to CurrentBoot only if BootNext wasn't previously set
|
|
+ log_info "Setting the next boot to: $current_boot"
|
|
+ efibootmgr -n "$current_boot" || {
|
|
+ log_error "Cannot set the next boot properly using the efibootmgr utility"
|
|
+ exit 1
|
|
+ }
|
|
+ exit 0
|
|
+}
|
|
+
|
|
+log_info "The next boot is already set to: ${next_boot}. Nothing to do"
|
|
+exit 0
|
|
diff --git a/RHEL6_7/system/uefi/efibootorder_fix.sh b/RHEL6_7/system/uefi/efibootorder_fix_pre.sh
|
|
similarity index 76%
|
|
rename from RHEL6_7/system/uefi/efibootorder_fix.sh
|
|
rename to RHEL6_7/system/uefi/efibootorder_fix_pre.sh
|
|
index d69ee5c..b483f55 100755
|
|
--- a/RHEL6_7/system/uefi/efibootorder_fix.sh
|
|
+++ b/RHEL6_7/system/uefi/efibootorder_fix_pre.sh
|
|
@@ -25,16 +25,14 @@ if [ -e "$efibin_path" ] ; then
|
|
cp -a ${efibin_path}{,.preupg}
|
|
# back up the file only in case there is not any other backup
|
|
# - the backup can be created by redhat-upgrade-tool
|
|
- [ -e "${eficonf_path}.preupg" ] || cp -a ${eficonf_path}{.preupg,}
|
|
+ [ -e "${eficonf_path}.preupg" ] || cp -a ${eficonf_path}{,.preupg}
|
|
else
|
|
- # restore the files from the backup
|
|
- log_info "Restoring EFI files."
|
|
- cp -a ${efibin_path}{.preupg,}
|
|
- # we do not want to apply the backup of the configuration file,
|
|
- # as the backup will not contain probably working configuration; however,
|
|
- # in case the configuration file is already missing, it could be in some
|
|
- # rare cases better than nothing
|
|
- [ -e "$eficonf_path" ] || cp -a ${eficonf_path}{.preupg,}
|
|
+ # This is not expected at all, but let's call it a lock for a seatbelt
|
|
+ # - The script is applied only when EFI is detected; however it's possible
|
|
+ # the system could be deployed already broken and still working by
|
|
+ # a miracle (unsupported of course, but why not to prevent more damage?)
|
|
+ log_error "Cannot find the $eficonf_path file but EFI has been detected. Cannot proceed the upgrade."
|
|
+ exit 1
|
|
fi
|
|
|
|
|
|
--
|
|
2.30.2
|
|
|