nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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