grub2-mkconfig: Prevent mkconfig from overwriting grub cfg stub

Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
This commit is contained in:
Nicolas Frayer 2024-07-16 15:19:37 +02:00
parent ce5e45b505
commit f28d50ee44
3 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nicolas Frayer <nfrayer@redhat.com>
Date: Tue, 16 Jul 2024 11:11:43 +0200
Subject: [PATCH] grub2-mkconfig: Ensure grub cfg stub is not overwritten
/boot/efi/EFI/$os_name/grub.cfg contains a grub cfg stub
that should not be overwritten by grub2-mkconfig.
Ensure that we prevent this from happening.
Signed-off-by: Marta Lewandowska <mlewando@redhat.com>
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
---
util/grub-mkconfig.in | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index fb382b648b87..efa36cc45a69 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -109,6 +109,20 @@ do
esac
done
+os_name=$(grep '^ID=' /etc/os-release | sed 's/ID=//')
+if test "$os_name" = '"rhel"'; then
+ os_name=redhat
+elif test "$os_name" = '"centos"'; then
+ os_name=centos
+fi
+if test "x${grub_cfg}" = "x/boot/efi/EFI/$os_name/grub.cfg" &&\
+ mountpoint -q /boot/efi; then
+ gettext_printf "Running \`grub2-mkconfig -o %s' will overwrite the GRUB wrapper.\n" "$grub_cfg" 1>&2
+ gettext_printf "Please run \`grub2-mkconfig -o /boot/grub2/grub.cfg' instead to update grub.cfg.\n" 1>&2
+ gettext_printf "GRUB configuration file was not updated.\n" 1>&2
+ exit 1
+fi
+
if [ "x$EUID" = "x" ] ; then
EUID=`id -u`
fi

View file

@ -361,3 +361,4 @@ Patch0360: 0360-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch
Patch0361: 0361-cmd-search-Rework-of-CVE-2023-4001-fix.patch Patch0361: 0361-cmd-search-Rework-of-CVE-2023-4001-fix.patch
Patch0362: 0362-grub-mkconfig.in-turn-off-executable-owner-bit.patch Patch0362: 0362-grub-mkconfig.in-turn-off-executable-owner-bit.patch
Patch0363: 0363-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch Patch0363: 0363-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch
Patch0364: 0364-grub2-mkconfig-Ensure-grub-cfg-stub-is-not-overwritt.patch

View file

@ -17,7 +17,7 @@
Name: grub2 Name: grub2
Epoch: 1 Epoch: 1
Version: 2.06 Version: 2.06
Release: 124%{?dist} Release: 125%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more Summary: Bootloader with support for Linux, Multiboot and more
License: GPL-3.0-or-later License: GPL-3.0-or-later
URL: http://www.gnu.org/software/grub/ URL: http://www.gnu.org/software/grub/
@ -555,6 +555,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%endif %endif
%changelog %changelog
* Tue Jul 16 2024 Nicolas Frayer <nfrayer@redhat.com> - 2.06-125
- grub2-mkconfig: Prevent mkconfig from overwriting grub cfg stub
* Tue Jul 2 2024 Nicolas Frayer <nfrayer@redhat.com> - 2.06-124 * Tue Jul 2 2024 Nicolas Frayer <nfrayer@redhat.com> - 2.06-124
- KVM/PowerVM: Add support for KVM on PowerVM - KVM/PowerVM: Add support for KVM on PowerVM
- Resolved: #2294883 - Resolved: #2294883