SHA256
1
0
forked from pool/grub2

Accepting request 214140 from home:michael-chang:branches:Base:System

- refresh 0001-script-provide-overridable-root-by-subvol.patch
* Introduce $boot_prefix for setting prefix on seeking other /boot
  directory.
- refresh 0002-script-create-menus-for-btrfs-snapshot.patch
* Support existing snapshots by creating their missing slave configs.
* Temporarily default to disable this feature until receiving more
  tests from QA.
* Introduce GRUB_ENABLE_CUSTOM_SNAPSHOT_SUBMENU to allow custom
  submenu for listing snapshots rather than the default one.

OBS-URL: https://build.opensuse.org/request/show/214140
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=67
This commit is contained in:
Marcus Meissner 2014-01-17 12:38:35 +00:00 committed by Git OBS Bridge
parent 0015f44766
commit 2b365a069c
3 changed files with 108 additions and 6 deletions

View File

@ -7,6 +7,10 @@ Patch-Mainline: no
This patch provides a environment variable $subvol that can be used This patch provides a environment variable $subvol that can be used
to override path relative to absolute root by specific $subvol. 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> Signed-off-by: Michael Chang <mchang@suse.com>
Index: grub-2.02~beta2/util/grub.d/10_linux.in Index: grub-2.02~beta2/util/grub.d/10_linux.in
@ -94,3 +98,17 @@ Index: grub-2.02~beta2/util/grub.d/10_linux.in
fi fi
fi fi
sed "s/^/$submenu_indentation/" << EOF 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

View File

@ -7,6 +7,13 @@ Patch-Mainline: no
This patch adds a new script that will create the menus used for This patch adds a new script that will create the menus used for
booting btrfs snapshots. booting btrfs snapshots.
v1:
* Support existing snapshots by creating their missing slave configs.
* Temporarily default to disable this feature until receiving more
tests from QA.
* Introduce GRUB_ENABLE_CUSTOM_SNAPSHOT_SUBMENU to allow custom
submenu for listing snapshots rather than the default one.
Signed-off-by: Michael Chang <mchang@suse.com> Signed-off-by: Michael Chang <mchang@suse.com>
Index: grub-2.02~beta2/Makefile.util.def Index: grub-2.02~beta2/Makefile.util.def
@ -31,14 +38,15 @@ Index: grub-2.02~beta2/util/grub-mkconfig.in
=================================================================== ===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig.in --- grub-2.02~beta2.orig/util/grub-mkconfig.in
+++ grub-2.02~beta2/util/grub-mkconfig.in +++ grub-2.02~beta2/util/grub-mkconfig.in
@@ -250,7 +250,9 @@ export GRUB_DEFAULT \ @@ -250,7 +250,10 @@ export GRUB_DEFAULT \
GRUB_OS_PROBER_SKIP_LIST \ GRUB_OS_PROBER_SKIP_LIST \
GRUB_DISABLE_SUBMENU \ GRUB_DISABLE_SUBMENU \
GRUB_CMDLINE_LINUX_RECOVERY \ GRUB_CMDLINE_LINUX_RECOVERY \
- GRUB_USE_LINUXEFI - GRUB_USE_LINUXEFI
+ GRUB_USE_LINUXEFI \ + GRUB_USE_LINUXEFI \
+ GRUB_DISABLE_BOOTING_SNAPSHOT \ + GRUB_DISABLE_BOOTING_SNAPSHOT \
+ GRUB_DISABLE_BOOTING_SNAPSHOT_SUBMENU + GRUB_DISABLE_BOOTING_SNAPSHOT_SUBMENU \
+ GRUB_ENABLE_CUSTOM_SNAPSHOT_SUBMENU
if test "x${grub_cfg}" != "x"; then if test "x${grub_cfg}" != "x"; then
rm -f "${grub_cfg}.new" rm -f "${grub_cfg}.new"
@ -46,7 +54,7 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
=================================================================== ===================================================================
--- /dev/null --- /dev/null
+++ grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in +++ grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
@@ -0,0 +1,111 @@ @@ -0,0 +1,174 @@
+#! /bin/sh +#! /bin/sh
+set -e +set -e
+ +
@ -86,7 +94,8 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+# The slave config path in btrfs snapshot that will be sourced by master config +# The slave config path in btrfs snapshot that will be sourced by master config
+# The menu entries in slave config will have it's root overridable by specified +# The menu entries in slave config will have it's root overridable by specified
+# subvolume name +# subvolume name
+slave_cfg="boot/grub2/snapshot_menuentry.cfg" +slave_cfg_name="snapshot_menuentry.cfg"
+slave_cfg="boot/grub2/${slave_cfg_name}"
+ +
+# The current config which is being outputted by grub-mkconfig +# The current config which is being outputted by grub-mkconfig
+output_cfg=`readlink /proc/$PPID/fd/1 | sed s/.new$//` +output_cfg=`readlink /proc/$PPID/fd/1 | sed s/.new$//`
@ -94,11 +103,20 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+grub_mkconfig_dir=`dirname $0` +grub_mkconfig_dir=`dirname $0`
+grub_script_check="${bindir}/grub2-script-check" +grub_script_check="${bindir}/grub2-script-check"
+ +
+# Stockpile directory for created slave config for snapshots without it
+scanned_snapshot_cfg_dir="/boot/grub2/scanned_snapshot_cfg"
+
+# Remove any slave config if booting snapshot gets disabled, in case it will become +# Remove any slave config if booting snapshot gets disabled, in case it will become
+# inconsistent on further updates, note this also removes master_snapshot_cfg +# inconsistent on further updates, note this also removes master_snapshot_cfg
+if [ "x${GRUB_DISABLE_BOOTING_SNAPSHOT}" = "xtrue" ]; then +
+# Temporarily we disable this as it is quite new and still in developing
+# It's subjected to be enabled by default in future as the option name
+# GRUB_DISABLE_BOOTING_SNAPSHOT suggests. So for new you'll need to explicit
+# specify GRUB_DISABLE_BOOTING_SNAPSHOT=false the update the config
+if [ "x${GRUB_DISABLE_BOOTING_SNAPSHOT}" != "xfalse" ]; then
+ rm -f "/${slave_cfg}" + rm -f "/${slave_cfg}"
+ rm -f "${master_snapshot_cfg}" + rm -f "${master_snapshot_cfg}"
+ rm -rf "${scanned_snapshot_cfg_dir}"
+ exit 0 + exit 0
+fi +fi
+ +
@ -112,6 +130,45 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+ if ${grub_script_check} "/${slave_cfg}.new"; then + if ${grub_script_check} "/${slave_cfg}.new"; then
+ mv -f "/${slave_cfg}.new" "/${slave_cfg}" + mv -f "/${slave_cfg}.new" "/${slave_cfg}"
+ fi + fi
+
+ # Scan existing snapshots to create their missing slave configs
+ # This should only be done once
+ if [ ! -d "$scanned_snapshot_cfg_dir" ]; then
+
+ mkdir -p "$scanned_snapshot_cfg_dir"
+
+ for snapshot in /.snapshots/*/snapshot; do
+ config="${snapshot}/etc/default/grub"
+
+ bootdir="${snapshot}/boot"
+ outdir="${scanned_snapshot_cfg_dir}${snapshot}"
+
+ # skip if slave config already exists in snapshot
+ if [ -f "${snapshot}/${slave_cfg}" ]; then
+ continue
+ fi
+
+ (
+ # source config for kernel command lines .. etc
+ if [ -f "$config" ]; then
+ . "$config"
+ else
+ # skip when no config
+ continue
+ fi
+
+ overridable_root_by_subvol=true boot_prefix="$bootdir" ${grub_mkconfig_dir}/10_linux > "/${slave_cfg}.new"
+ )
+
+ # Check if the config is sane to use
+ if ${grub_script_check} "/${slave_cfg}.new"; then
+ mkdir -p "$outdir"
+ mv -f "/${slave_cfg}.new" "${outdir}/${slave_cfg_name}"
+ fi
+ done
+
+ fi
+
+fi +fi
+ +
+# Create the bootable snapshots submenus in master config, use the ${OS} to indicate +# Create the bootable snapshots submenus in master config, use the ${OS} to indicate
@ -140,7 +197,11 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+# could be source to run as a backup +# could be source to run as a backup
+# Here we search and list snapshots created by snapper by using it's convention on +# Here we search and list snapshots created by snapper by using it's convention on
+# naming snapshots +# naming snapshots
+cat <<EOF >"${master_snapshot_cfg}" +
+if [ "x${GRUB_ENABLE_CUSTOM_SNAPSHOT_SUBMENU}" != "xtrue" ]; then
+
+# Write default config if custom one not in use
+ cat <<EOF >"${master_snapshot_cfg}"
+insmod regexp +insmod regexp
+submenu "Bootable snapshots for ${OS}" { +submenu "Bootable snapshots for ${OS}" {
+ for x in /.snapshots/*; do + for x in /.snapshots/*; do
@ -151,6 +212,13 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+ export subvol + export subvol
+ source "\${subvol}/${slave_cfg}" + source "\${subvol}/${slave_cfg}"
+ } + }
+ elif [ -f "${scanned_snapshot_cfg_dir}\$x/snapshot/${slave_cfg_name}" ]; then
+ snapshot_found=true
+ submenu "\$x" "\$x" {
+ set subvol="\$2/snapshot"
+ export subvol
+ source "${scanned_snapshot_cfg_dir}\${subvol}/${slave_cfg_name}"
+ }
+ fi + fi
+ done + done
+ if [ x\$snapshot_found != xtrue ]; then + if [ x\$snapshot_found != xtrue ]; then
@ -158,3 +226,6 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
+ fi + fi
+} +}
+EOF +EOF
+
+fi
+

View File

@ -1,3 +1,16 @@
-------------------------------------------------------------------
Fri Jan 17 06:23:04 UTC 2014 - mchang@suse.com
- refresh 0001-script-provide-overridable-root-by-subvol.patch
* Introduce $boot_prefix for setting prefix on seeking other /boot
directory.
- refresh 0002-script-create-menus-for-btrfs-snapshot.patch
* Support existing snapshots by creating their missing slave configs.
* Temporarily default to disable this feature until receiving more
tests from QA.
* Introduce GRUB_ENABLE_CUSTOM_SNAPSHOT_SUBMENU to allow custom
submenu for listing snapshots rather than the default one.
------------------------------------------------------------------- -------------------------------------------------------------------
Wed Jan 15 15:46:31 UTC 2014 - arvidjaar@gmail.com Wed Jan 15 15:46:31 UTC 2014 - arvidjaar@gmail.com