From 0dc1663a59b4a27df3b8d06aeaa863e0e80ca577 Mon Sep 17 00:00:00 2001 From: Leo Sandoval Date: Thu, 15 May 2025 13:59:51 -0600 Subject: [PATCH] Run grub2-install automatically on grub2-pc posttrans This proposed change would allow upgrades on PC archs to automatically execute 'grub2-install' on the corresponding disks without user intervention. Signed-off-by: Leo Sandoval Signed-off-by: Josue Hernandez --- grub2.spec | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/grub2.spec b/grub2.spec index b927cbf..125b4dc 100644 --- a/grub2.spec +++ b/grub2.spec @@ -16,7 +16,7 @@ Name: grub2 Epoch: 1 Version: 2.06 -Release: 132%{?dist} +Release: 133%{?dist} Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -376,6 +376,75 @@ if test -f ${EFI_HOME}/grubenv; then mv --force ${EFI_HOME}/grubenv ${GRUB_HOME}/grubenv fi +%if "%{platform}" == "pc" +%posttrans pc +set -eu +set -o pipefail + +SYS_FIRMWARE_EFI_DIR=/sys/firmware/efi +BOOT_DIR=/boot + +find_grub_devices() { + local boot_device + local component_devs=() + local block_devs=() + + # Exit if UEFI system running + if test -d $SYS_FIRMWARE_EFI_DIR ; then + exit 0 + fi + + # grub2-probe is required for device finding + if ! command -v grub2-probe &>/dev/null; then + exit 0; + fi + + # Get block devices where GRUB is located. We assume GRUB is on the same device + # as /boot partition is. In case that device is an md (Multiple Device) device, all + # of the component devices of such a device are considered. + boot_device=$(grub2-probe --target=device $BOOT_DIR) + + # Check if a given device is an md (Multiple Device) device + # It is expected that the "mdadm" command is available, + # if it's not it is assumed the device is not an md device. + if command -v mdadm &>/dev/null && \ + mdadm --detail --verbose --brief "$boot_device" &> /dev/null; then + out=$(mdadm --detail --verbose --brief "$boot_device") + # output would look like: + # ARRAY /dev/md0 level=raid1 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=c4acea6e:d56e1598:91822e3f:fb26832c disable=line-too-long devices=/dev/vda1,/dev/vdb1 + for d in $(echo "$out" | sed -n -e 's/.* devices=\([^ ]*\).*/\1/p' | sed 's/,/ /g'); do + component_devs+=("$d") + done + else + component_devs+=("$boot_device") + fi + + # Get blocks from partitions + for d in "${component_devs[@]}"; do + block_devs+=("$(lsblk -spnlo name "$d" | tail -1)") + done + + # Filter those GRUB blocks + for d in "${block_devs[@]}"; do + if dd if="$d" bs=446 count=1 status=none | grep -aq "GRUB"; then + echo "$d" + fi + done +} + +grub_install () { + if ! command -v grub2-install &>/dev/null; then + exit 0 + fi + for d in $(find_grub_devices); do + echo "Installing on $d" >&2 + grub2-install "$d" + done +} + +grub_install || : +%endif + %files common -f grub.lang %dir %{_libdir}/grub/ %dir %{_datarootdir}/grub/ @@ -546,6 +615,10 @@ fi %endif %changelog +* Fri Jul 24 2026 Leo Sandoval - 2.06-133 +- Run grub2-install automatically on grub2-pc posttrans +- Resolves: #RHEL-216339 + * Mon Jul 21 2026 Josue Hernandez - 2.06-132 - Remove creation of /boot/loader/entries - Resolves: #RHEL-212729