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