nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone
8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Fri, 9 Dec 2016 15:40:29 -0500
8631a2
Subject: [PATCH] Add BLS support to grub-mkconfig
8631a2
8631a2
GRUB now has BootLoaderSpec support, the user can choose to use this by
8631a2
setting GRUB_ENABLE_BLSCFG to true in /etc/default/grub. On this setup,
8631a2
the boot menu entries are not added to the grub.cfg, instead BLS config
8631a2
files are parsed by blscfg command and the entries created dynamically.
8631a2
---
8631a2
 util/grub-mkconfig.in     |  3 ++-
8631a2
 util/grub-mkconfig_lib.in | 29 +++++++++++++++++++----------
8631a2
 util/grub.d/10_linux.in   | 37 +++++++++++++++++++++++++++++++++++--
8631a2
 3 files changed, 56 insertions(+), 13 deletions(-)
8631a2
8631a2
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
b32e65
index 4248b9341..c20171919 100644
8631a2
--- a/util/grub-mkconfig.in
8631a2
+++ b/util/grub-mkconfig.in
8631a2
@@ -259,7 +259,8 @@ export GRUB_DEFAULT \
8631a2
   GRUB_OS_PROBER_SKIP_LIST \
8631a2
   GRUB_DISABLE_SUBMENU \
8631a2
   GRUB_DEFAULT_DTB \
8631a2
-  SUSE_BTRFS_SNAPSHOT_BOOTING
8631a2
+  SUSE_BTRFS_SNAPSHOT_BOOTING \
8631a2
+  GRUB_ENABLE_BLSCFG
8631a2
 
8631a2
 if test "x${grub_cfg}" != "x"; then
8631a2
   rm -f "${grub_cfg}.new"
8631a2
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
b32e65
index b3aae534d..1acc1d01c 100644
8631a2
--- a/util/grub-mkconfig_lib.in
8631a2
+++ b/util/grub-mkconfig_lib.in
8631a2
@@ -30,6 +30,9 @@ fi
8631a2
 if test "x$grub_file" = x; then
8631a2
   grub_file="${bindir}/@grub_file@"
8631a2
 fi
8631a2
+if test "x$grub_editenv" = x; then
8631a2
+  grub_editenv="${bindir}/@grub_editenv@"
8631a2
+fi
8631a2
 if test "x$grub_mkrelpath" = x; then
8631a2
   grub_mkrelpath="${bindir}/@grub_mkrelpath@"
8631a2
 fi
8631a2
@@ -127,10 +130,16 @@ EOF
8631a2
 
8631a2
 prepare_grub_to_access_device ()
8631a2
 {
8631a2
+  local device=$1 && shift
8631a2
+  if [ "$#" -gt 0 ]; then
8631a2
+    local variable=$1 && shift
8631a2
+  else
8631a2
+    local variable=root
8631a2
+  fi
8631a2
   old_ifs="$IFS"
8631a2
   IFS='
8631a2
 '
8631a2
-  partmap="`"${grub_probe}" --device $@ --target=partmap`"
8631a2
+  partmap="`"${grub_probe}" --device ${device} --target=partmap`"
8631a2
   for module in ${partmap} ; do
8631a2
     case "${module}" in
8631a2
       netbsd | openbsd)
8631a2
@@ -141,34 +150,34 @@ prepare_grub_to_access_device ()
8631a2
   done
8631a2
 
8631a2
   # Abstraction modules aren't auto-loaded.
8631a2
-  abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
8631a2
+  abstraction="`"${grub_probe}" --device ${device} --target=abstraction`"
8631a2
   for module in ${abstraction} ; do
8631a2
     echo "insmod ${module}"
8631a2
   done
8631a2
 
8631a2
-  fs="`"${grub_probe}" --device $@ --target=fs`"
8631a2
+  fs="`"${grub_probe}" --device ${device} --target=fs`"
8631a2
   for module in ${fs} ; do
8631a2
     echo "insmod ${module}"
8631a2
   done
8631a2
 
8631a2
   if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
8631a2
-      for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do
8631a2
+      for uuid in `"${grub_probe}" --device ${device} --target=cryptodisk_uuid`; do
8631a2
 	  echo "cryptomount -u $uuid"
8631a2
       done
8631a2
   fi
8631a2
 
8631a2
   # If there's a filesystem UUID that GRUB is capable of identifying, use it;
8631a2
   # otherwise set root as per value in device.map.
8631a2
-  fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`"
8631a2
+  fs_hint="`"${grub_probe}" --device ${device} --target=compatibility_hint`"
8631a2
   if [ "x$fs_hint" != x ]; then
8631a2
-    echo "set root='$fs_hint'"
8631a2
+    echo "set ${variable}='$fs_hint'"
8631a2
   fi
8631a2
-  if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
8631a2
-    hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints=
8631a2
+  if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then
8631a2
+    hints="`"${grub_probe}" --device ${device} --target=hints_string 2> /dev/null`" || hints=
8631a2
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
8631a2
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
8631a2
+    echo "  search --no-floppy --fs-uuid --set=${variable} ${hints} ${fs_uuid}"
8631a2
     echo "else"
8631a2
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
8631a2
+    echo "  search --no-floppy --fs-uuid --set=${variable} ${fs_uuid}"
8631a2
     echo "fi"
8631a2
   fi
8631a2
   IFS="$old_ifs"
8631a2
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
b32e65
index d9a05937e..839f1fdb6 100644
8631a2
--- a/util/grub.d/10_linux.in
8631a2
+++ b/util/grub.d/10_linux.in
8631a2
@@ -121,6 +121,34 @@ linux_entry ()
8631a2
   if [ -z "$boot_device_id" ]; then
8631a2
       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
8631a2
   fi
8631a2
+
8631a2
+  if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
8631a2
+    if [ x$dirname = x/ ]; then
8631a2
+      if [ -z "${prepare_root_cache}" ]; then
8631a2
+        prepare_grub_to_access_device ${GRUB_DEVICE}
8631a2
+      fi
8631a2
+    else
8631a2
+      if [ -z "${prepare_boot_cache}" ]; then
8631a2
+        prepare_grub_to_access_device ${GRUB_DEVICE_BOOT}
8631a2
+      fi
8631a2
+    fi
8631a2
+
8631a2
+    bootefi_device="`${grub_probe} --target=device /boot/efi/`"
8631a2
+    prepare_grub_to_access_device ${bootefi_device} boot
8631a2
+
8631a2
+    cat << EOF
8631a2
+insmod blscfg
8631a2
+blscfg
8631a2
+if [ -s \$prefix/grubenv ]; then
8631a2
+  load_env
8631a2
+fi
8631a2
+EOF
8631a2
+
8631a2
+    ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
8631a2
+
8631a2
+    exit 0
8631a2
+  fi
8631a2
+
8631a2
   if [ x$type != xsimple ] ; then
8631a2
       title=$(mktitle "$type" "$version")
8631a2
       if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
8631a2
@@ -223,7 +251,10 @@ submenu_indentation=""
8631a2
 is_top_level=true
8631a2
 while [ "x$list" != "x" ] ; do
8631a2
   linux=`version_find_latest $list`
8631a2
-  gettext_printf "Found linux image: %s\n" "$linux" >&2
8631a2
+  if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
8631a2
+    gettext_printf "Found linux image: %s\n" "$linux" >&2
8631a2
+  fi
8631a2
+
8631a2
   basename=`basename $linux`
8631a2
   dirname=`dirname $linux`
8631a2
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
8631a2
@@ -262,7 +293,9 @@ while [ "x$list" != "x" ] ; do
8631a2
     for i in ${initrd}; do
8631a2
       initrd_display="${initrd_display} ${dirname}/${i}"
8631a2
     done
8631a2
-    gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
8631a2
+    if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
8631a2
+      gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
8631a2
+    fi
8631a2
   fi
8631a2
 
8631a2
   fdt=