SHA256
1
0
forked from pool/grub2
grub2/0001-script-provide-overridable-root-by-subvol.patch

115 lines
4.5 KiB
Diff

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.
Signed-off-by: Michael Chang <mchang@suse.com>
Index: grub-2.02~beta2/util/grub.d/10_linux.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/10_linux.in
+++ grub-2.02~beta2/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)
@@ -126,17 +128,43 @@ linux_entry ()
fi
printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
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.
@@ -144,13 +172,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
@@ -161,11 +197,11 @@ EOF
machine=`uname -m`
case "x$machine" in
xi?86 | xx86_64)
- list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
+ list=`for i in ${boot_prefix}/boot/vmlinuz-* ${boot_prefix}/vmlinuz-* ${boot_prefix}/boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
*)
- list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
+ list=`for i in ${boot_prefix}/boot/vmlinuz-* ${boot_prefix}/boot/vmlinux-* ${boot_prefix}/vmlinuz-* ${boot_prefix}/vmlinux-* ${boot_prefix}/boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
esac