Blame SOURCES/0092-grub2-btrfs-05-grub2-mkconfig.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Michael Chang <mchang@suse.com>
d9d99f
Date: Thu, 21 Aug 2014 03:39:11 +0000
d9d99f
Subject: [PATCH] grub2-btrfs-05-grub2-mkconfig
d9d99f
d9d99f
---
d9d99f
 util/grub-mkconfig.in       |  3 ++-
d9d99f
 util/grub-mkconfig_lib.in   |  4 ++++
d9d99f
 util/grub.d/00_header.in    | 24 +++++++++++++++++++++++-
d9d99f
 util/grub.d/10_linux.in     |  4 ++++
d9d99f
 util/grub.d/20_linux_xen.in |  4 ++++
d9d99f
 5 files changed, 37 insertions(+), 2 deletions(-)
d9d99f
d9d99f
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
d9d99f
index 8218f3d477f..4248b9341ab 100644
d9d99f
--- a/util/grub-mkconfig.in
d9d99f
+++ b/util/grub-mkconfig.in
d9d99f
@@ -258,7 +258,8 @@ export GRUB_DEFAULT \
d9d99f
   GRUB_BADRAM \
d9d99f
   GRUB_OS_PROBER_SKIP_LIST \
d9d99f
   GRUB_DISABLE_SUBMENU \
d9d99f
-  GRUB_DEFAULT_DTB
d9d99f
+  GRUB_DEFAULT_DTB \
d9d99f
+  SUSE_BTRFS_SNAPSHOT_BOOTING
d9d99f
 
d9d99f
 if test "x${grub_cfg}" != "x"; then
d9d99f
   rm -f "${grub_cfg}.new"
d9d99f
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
d9d99f
index 113a41f9409..b3aae534ddc 100644
d9d99f
--- a/util/grub-mkconfig_lib.in
d9d99f
+++ b/util/grub-mkconfig_lib.in
d9d99f
@@ -52,7 +52,11 @@ grub_warn ()
d9d99f
 
d9d99f
 make_system_path_relative_to_its_root ()
d9d99f
 {
d9d99f
+  if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
d9d99f
+  "${grub_mkrelpath}" -r "$1"
d9d99f
+  else
d9d99f
   "${grub_mkrelpath}" "$1"
d9d99f
+  fi
d9d99f
 }
d9d99f
 
d9d99f
 is_path_readable_by_grub ()
d9d99f
diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
d9d99f
index 858b526c925..e2a53300126 100644
d9d99f
--- a/util/grub.d/00_header.in
d9d99f
+++ b/util/grub.d/00_header.in
d9d99f
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
d9d99f
 
d9d99f
 . "$pkgdatadir/grub-mkconfig_lib"
d9d99f
 
d9d99f
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
d9d99f
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
d9d99f
+    cat <
d9d99f
+set btrfs_relative_path="y"
d9d99f
+export btrfs_relative_path
d9d99f
+EOF
d9d99f
+fi
d9d99f
+
d9d99f
 # Do this as early as possible, since other commands might depend on it.
d9d99f
 # (e.g. the `loadfont' command might need lvm or raid modules)
d9d99f
 for i in ${GRUB_PRELOAD_MODULES} ; do
d9d99f
@@ -45,7 +53,9 @@ if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT
d9d99f
 cat << EOF
d9d99f
 set pager=1
d9d99f
 
d9d99f
-if [ -s \$prefix/grubenv ]; then
d9d99f
+if [ -f \${config_directory}/grubenv ]; then
d9d99f
+  load_env -f \${config_directory}/grubenv
d9d99f
+elif [ -s \$prefix/grubenv ]; then
d9d99f
   load_env
d9d99f
 fi
d9d99f
 EOF
d9d99f
@@ -356,3 +366,15 @@ fi
d9d99f
 if [ "x${GRUB_BADRAM}" != "x" ] ; then
d9d99f
   echo "badram ${GRUB_BADRAM}"
d9d99f
 fi
d9d99f
+
d9d99f
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
d9d99f
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
d9d99f
+    # Note: No $snapshot_num on *read-only* rollback!  (bsc#901487)
d9d99f
+    cat <
d9d99f
+if [ -n "\$extra_cmdline" ]; then
d9d99f
+  submenu "Bootable snapshot #\$snapshot_num" {
d9d99f
+    menuentry "If OK, run 'snapper rollback' and reboot." { true; }
d9d99f
+  }
d9d99f
+fi
d9d99f
+EOF
d9d99f
+fi
d9d99f
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
d9d99f
index 4e49ccdf742..d9a05937e46 100644
d9d99f
--- a/util/grub.d/10_linux.in
d9d99f
+++ b/util/grub.d/10_linux.in
d9d99f
@@ -66,10 +66,14 @@ fi
d9d99f
 
d9d99f
 case x"$GRUB_FS" in
d9d99f
     xbtrfs)
d9d99f
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
d9d99f
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
d9d99f
+	else
d9d99f
 	rootsubvol="`make_system_path_relative_to_its_root /`"
d9d99f
 	rootsubvol="${rootsubvol#/}"
d9d99f
 	if [ "x${rootsubvol}" != x ]; then
d9d99f
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
d9d99f
+	fi
d9d99f
 	fi;;
d9d99f
     xzfs)
d9d99f
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
d9d99f
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
d9d99f
index 972a4b5a03d..bcdc3ceac02 100644
d9d99f
--- a/util/grub.d/20_linux_xen.in
d9d99f
+++ b/util/grub.d/20_linux_xen.in
d9d99f
@@ -73,10 +73,14 @@ fi
d9d99f
 
d9d99f
 case x"$GRUB_FS" in
d9d99f
     xbtrfs)
d9d99f
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
d9d99f
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
d9d99f
+	else
d9d99f
 	rootsubvol="`make_system_path_relative_to_its_root /`"
d9d99f
 	rootsubvol="${rootsubvol#/}"
d9d99f
 	if [ "x${rootsubvol}" != x ]; then
d9d99f
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
d9d99f
+	fi
d9d99f
 	fi;;
d9d99f
     xzfs)
d9d99f
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`