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