File 0001-script-provide-overridable-root-by-subvol.patch of Package grub2.3460

From: Michael Chang <mchang@suse.com>
Subject: provide overridable root by subvol 

References: fate#316522, fate#316232
Patch-Mainline: no

This patch provides a environment variable $subvol that can be used
to override path relative to absolute root by specific $subvol.

v1:
Introduce $boot_prefix for setting prefix on seeking other /boot
directory.

v2:
Refresh for s390x-emu.

Signed-off-by: Michael Chang <mchang@suse.com>

---
 util/grub.d/10_linux.in |   57 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 9 deletions(-)

--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -55,7 +55,9 @@ case x"$GRUB_FS" in
     xbtrfs)
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
-	if [ "x${rootsubvol}" != x ]; then
+	if [ "x$overridable_root_by_subvol" = "xtrue" ]; then
+	    GRUB_CMDLINE_LINUX="\${rootflags} ${GRUB_CMDLINE_LINUX}"
+	elif [ "x${rootsubvol}" != x ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
 	fi;;
     xzfs)
@@ -145,17 +147,43 @@ linux_entry ()
     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   fi
  fi
+
+  if [ "x$overridable_root_by_subvol" = "xtrue" -a "x$GRUB_FS" = "xbtrfs" ]; then
+    sed "s/^/$submenu_indentation/" << EOF
+	if [ "x\$subvol" = "x" ]; then
+		bootdir="${rel_dirname}"
+		rootdir="${rootsubvol}"
+	else
+		bootdir="\${subvol}${dirname}"
+		rootdir="\${subvol}"
+	fi
+	if [ "x\${rootdir}" != "x" ]; then
+		rootflags="rootflags=subvol=\${rootdir}"
+	else
+		rootflags=""
+	fi
+EOF
+  fi
+
   message="$(gettext_printf "Loading Linux %s ..." ${version})"
   if [ -d /sys/firmware/efi ] && [ "x${GRUB_USE_LINUXEFI}" = "xtrue" ]; then
     sed "s/^/$submenu_indentation/" << EOF
 	echo	'$message'
-	linuxefi ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
 EOF
+    if [ "x$overridable_root_by_subvol" = "xtrue" -a "x$GRUB_FS" = "xbtrfs" ]; then
+        echo "	linuxefi \${bootdir}/${basename} root=${linux_root_device_thisversion} ro ${args}" | sed "s/^/$submenu_indentation/"
+    else
+        echo "	linuxefi ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}" | sed "s/^/$submenu_indentation/"
+    fi
   else
     sed "s/^/$submenu_indentation/" << EOF
 	echo	'$(echo "$message" | grub_quote)'
-	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ${args}
 EOF
+    if [ "x$overridable_root_by_subvol" = "xtrue" -a "x$GRUB_FS" = "xbtrfs" ]; then
+        echo "	linux	\${bootdir}/${basename} root=${linux_root_device_thisversion} ${args}" | sed "s/^/$submenu_indentation/"
+    else
+        echo "	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ${args}" | sed "s/^/$submenu_indentation/"
+    fi
   fi
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
@@ -163,13 +191,21 @@ EOF
     if [ -d /sys/firmware/efi ] && [ "x${GRUB_USE_LINUXEFI}" = "xtrue" ]; then
       sed "s/^/$submenu_indentation/" << EOF
 	echo	'$message'
-	initrdefi ${rel_dirname}/${initrd}
 EOF
+      if [ "x$overridable_root_by_subvol" = "xtrue" -a "x$GRUB_FS" = "xbtrfs" ]; then
+        echo "	initrdefi \${bootdir}/${initrd}" | sed "s/^/$submenu_indentation/"
+      else
+        echo "	initrdefi ${rel_dirname}/${initrd}" | sed "s/^/$submenu_indentation/"
+      fi
     else
       sed "s/^/$submenu_indentation/" << EOF
 	echo	'$(echo "$message" | grub_quote)'
-	initrd	${rel_dirname}/${initrd}
 EOF
+      if [ "x$overridable_root_by_subvol" = "xtrue" -a "x$GRUB_FS" = "xbtrfs" ]; then
+        echo "	initrd \${bootdir}/${initrd}" | sed "s/^/$submenu_indentation/"
+      else
+        echo "	initrd ${rel_dirname}/${initrd}" | sed "s/^/$submenu_indentation/"
+      fi
     fi
   fi
   sed "s/^/$submenu_indentation/" << EOF
@@ -179,10 +215,13 @@ EOF
 
 machine=`uname -m`
 case "$machine" in
-    i?86 | x86_64) klist="/boot/vmlinuz-* /vmlinuz-* /boot/kernel-*" ;;
-    s390 | s390x)  klist="/boot/image-* /boot/kernel-*" ;;
-    *) klist="/boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* \
-		/boot/kernel-*" ;;
+    i?86 | x86_64) klist="${boot_prefix}/boot/vmlinuz-* \
+		${boot_prefix}/vmlinuz-* ${boot_prefix}/boot/kernel-*" ;;
+    s390 | s390x)  klist="${boot_prefix}/boot/image-* \
+		${boot_prefix}/boot/kernel-*" ;;
+    *) klist="${boot_prefix}/boot/vmlinuz-* \
+		${boot_prefix}/boot/vmlinux-* ${boot_prefix}/vmlinuz-* \
+		${boot_prefix}/vmlinux-* /boot/kernel-*" ;;
 esac
 list=`for i in $klist; do
     if grub_file_is_not_garbage "$i" ; then
openSUSE Build Service is sponsored by