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