dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0153-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Javier Martinez Canillas <javierm@redhat.com>
8631a2
Date: Mon, 4 Jun 2018 16:10:22 +0200
8631a2
Subject: [PATCH] Add relative path to the kernel and initrds BLS fields if
8631a2
 needed
8631a2
8631a2
The static BLS config file shipped with the kernel package assumes that
8631a2
the /boot directory is a mount point, and that the kernel and initramfs
8631a2
images relative path is to the root of a boot partition.
8631a2
8631a2
But there are cases in which this isn't true, for example if a user has
8631a2
its /boot in a btrfs subvolume or if /boot isn't a mount point at all.
8631a2
8631a2
So instead of always using the BLS fragment file as distributed by the
8631a2
package, check the relative path that GRUB 2 has to use for the images.
8631a2
8631a2
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
8631a2
---
8631a2
 util/grub-switch-to-blscfg.in | 20 +++++++++++++++++---
8631a2
 1 file changed, 17 insertions(+), 3 deletions(-)
8631a2
8631a2
diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in
8631a2
index 89487ad611c..2482483a437 100644
8631a2
--- a/util/grub-switch-to-blscfg.in
8631a2
+++ b/util/grub-switch-to-blscfg.in
8631a2
@@ -188,6 +188,7 @@ fi
8631a2
 mkbls() {
8631a2
     local kernelver=$1 && shift
8631a2
     local datetime=$1 && shift
8631a2
+    local bootprefix=$1 && shift
8631a2
 
8631a2
     local debugname=""
8631a2
     local debugid=""
8631a2
@@ -206,8 +207,8 @@ mkbls() {
8631a2
         cat <
8631a2
 title ${NAME} (${kernelver}) ${VERSION}${debugname}
8631a2
 version ${kernelver}${debugid}
8631a2
-linux /vmlinuz-${kernelver}
8631a2
-initrd /initramfs-${kernelver}.img
8631a2
+linux ${bootprefix}/vmlinuz-${kernelver}
8631a2
+initrd ${bootprefix}/initramfs-${kernelver}.img
8631a2
 options \$kernelopts
8631a2
 id ${ID}-${datetime}-${kernelver}
8631a2
 grub_users \$grub_users
8631a2
@@ -234,6 +235,16 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
8631a2
             >"${bls_target}"
8631a2
     fi
8631a2
 
8631a2
+    linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')"
8631a2
+    initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')"
8631a2
+    linux_relpath="$("${grub_mkrelpath}" /boot/$linux)"
8631a2
+    initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)"
8631a2
+
8631a2
+    if [[ $linux != $linux_relpath ]]; then
8631a2
+        sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}"
8631a2
+        sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}"
8631a2
+    fi
8631a2
+
8631a2
     if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
8631a2
         arch="$(uname -m)"
8631a2
         bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")"
8631a2
@@ -247,7 +258,10 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do
8631a2
 done
8631a2
 
8631a2
 if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then
8631a2
-    mkbls "0-rescue-${MACHINE_ID}" "0" >"${blsdir}/${MACHINE_ID}-0-rescue.conf"
8631a2
+    if [[ $linux != $linux_relpath ]]; then
8631a2
+        bootprefix="$(dirname ${linux_relpath})"
8631a2
+    fi
8631a2
+    mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf"
8631a2
 fi
8631a2
 
8631a2
 GENERATE=0