nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0036-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Thu, 23 Jun 2016 11:01:39 -0400
8e15ce
Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux
8e15ce
8e15ce
This patch adds grub-get-kernel-settings, which reads the system kernel
8e15ce
installation configuration from /etc/sysconfig/kernel, and outputs
8e15ce
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
8e15ce
variables are then used by 10_linux to choose whether or not to create
8e15ce
debug stanzas.
8e15ce
8e15ce
Resolves: rhbz#1226325
b35c50
[rharwood: migrate man page to h2m]
8e15ce
---
b35c50
 configure.ac                                   |  1 +
8e15ce
 Makefile.util.def                              |  7 ++
b35c50
 docs/man/grub-get-kernel-settings.h2m          |  2 +
8e15ce
 util/bash-completion.d/grub-completion.bash.in | 22 +++++++
8e15ce
 util/grub-get-kernel-settings.in               | 88 ++++++++++++++++++++++++++
8e15ce
 util/grub-mkconfig.in                          |  3 +
8e15ce
 util/grub.d/10_linux.in                        | 23 +++++--
b35c50
 7 files changed, 141 insertions(+), 5 deletions(-)
b35c50
 create mode 100644 docs/man/grub-get-kernel-settings.h2m
8e15ce
 create mode 100644 util/grub-get-kernel-settings.in
8e15ce
8e15ce
diff --git a/configure.ac b/configure.ac
b35c50
index 7f59ad788f..0d0e6782a1 100644
8e15ce
--- a/configure.ac
8e15ce
+++ b/configure.ac
8e15ce
@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-install])
8e15ce
 grub_TRANSFORM([grub-mkconfig])
8e15ce
 grub_TRANSFORM([grub-mkfont])
8e15ce
 grub_TRANSFORM([grub-mkimage])
8e15ce
+grub_TRANSFORM([grub-get-kernel-settings])
8e15ce
 grub_TRANSFORM([grub-glue-efi])
8e15ce
 grub_TRANSFORM([grub-mklayout])
8e15ce
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
8e15ce
diff --git a/Makefile.util.def b/Makefile.util.def
b35c50
index 4ee22c5daa..18a9242776 100644
8e15ce
--- a/Makefile.util.def
8e15ce
+++ b/Makefile.util.def
b35c50
@@ -716,6 +716,13 @@ script = {
8e15ce
   installdir = sbin;
8e15ce
 };
8e15ce
 
8e15ce
+script = {
8e15ce
+  name = grub-get-kernel-settings;
8e15ce
+  common = util/grub-get-kernel-settings.in;
8e15ce
+  mansection = 3;
8e15ce
+  installdir = sbin;
8e15ce
+};
8e15ce
+
8e15ce
 script = {
8e15ce
   name = grub-set-default;
8e15ce
   common = util/grub-set-default.in;
b35c50
diff --git a/docs/man/grub-get-kernel-settings.h2m b/docs/man/grub-get-kernel-settings.h2m
b35c50
new file mode 100644
b35c50
index 0000000000..b8051f01f3
b35c50
--- /dev/null
b35c50
+++ b/docs/man/grub-get-kernel-settings.h2m
b35c50
@@ -0,0 +1,2 @@
b35c50
+[NAME]
b35c50
+grub-get-kernel-settings \- Evaluate the system's kernel installation settings for use while making a grub configuration file
8e15ce
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
b35c50
index 44bf135b9f..5c4acd496d 100644
8e15ce
--- a/util/bash-completion.d/grub-completion.bash.in
8e15ce
+++ b/util/bash-completion.d/grub-completion.bash.in
8e15ce
@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \
8e15ce
 unset __grub_sparc64_setup_program
8e15ce
 
8e15ce
 
8e15ce
+#
8e15ce
+# grub-get-kernel-settings
8e15ce
+#
8e15ce
+_grub_get_kernel_settings () {
8e15ce
+    local cur
8e15ce
+
8e15ce
+    COMPREPLY=()
8e15ce
+    cur=`_get_cword`
8e15ce
+
8e15ce
+    if [[ "$cur" == -* ]]; then
8e15ce
+        __grubcomp "$(__grub_get_options_from_help)"
8e15ce
+    else
8e15ce
+        # Default complete with a filename
8e15ce
+        _filedir
8e15ce
+    fi
8e15ce
+}
8e15ce
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
8e15ce
+have ${__grub_get_kernel_settings_program} && \
8e15ce
+ complete -F _grub_get_kernel_settings -o filenames ${__grub_get_kernel_settings_program}
8e15ce
+unset __grub_get_kernel_settings_program
8e15ce
+
8e15ce
+
8e15ce
 #
8e15ce
 # grub-install
8e15ce
 #
8e15ce
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
8e15ce
new file mode 100644
b35c50
index 0000000000..7e87dfccc0
8e15ce
--- /dev/null
8e15ce
+++ b/util/grub-get-kernel-settings.in
8e15ce
@@ -0,0 +1,88 @@
8e15ce
+#!/bin/sh
8e15ce
+set -e
8e15ce
+
8e15ce
+# Evaluate new-kernel-pkg's configuration file.
8e15ce
+# Copyright (C) 2016 Free Software Foundation, Inc.
8e15ce
+#
8e15ce
+# GRUB is free software: you can redistribute it and/or modify
8e15ce
+# it under the terms of the GNU General Public License as published by
8e15ce
+# the Free Software Foundation, either version 3 of the License, or
8e15ce
+# (at your option) any later version.
8e15ce
+#
8e15ce
+# GRUB is distributed in the hope that it will be useful,
8e15ce
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
8e15ce
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8e15ce
+# GNU General Public License for more details.
8e15ce
+#
8e15ce
+# You should have received a copy of the GNU General Public License
8e15ce
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8e15ce
+
8e15ce
+PACKAGE_NAME=@PACKAGE_NAME@
8e15ce
+PACKAGE_VERSION=@PACKAGE_VERSION@
8e15ce
+datadir="@datadir@"
8e15ce
+if [ "x$pkgdatadir" = x ]; then
8e15ce
+    pkgdatadir="${datadir}/@PACKAGE@"
8e15ce
+fi
8e15ce
+
8e15ce
+self=`basename $0`
8e15ce
+
8e15ce
+export TEXTDOMAIN=@PACKAGE@
8e15ce
+export TEXTDOMAINDIR="@localedir@"
8e15ce
+
8e15ce
+. "${pkgdatadir}/grub-mkconfig_lib"
8e15ce
+
8e15ce
+# Usage: usage
8e15ce
+# Print the usage.
8e15ce
+usage () {
8e15ce
+    gettext_printf "Usage: %s [OPTION]\n" "$self"
8e15ce
+    gettext "Evaluate new-kernel-pkg configuration"; echo
8e15ce
+    echo
8e15ce
+    print_option_help "-h, --help" "$(gettext "print this message and exit")"
8e15ce
+    print_option_help "-v, --version" "$(gettext "print the version information and exit")"
8e15ce
+    echo
8e15ce
+}
8e15ce
+
8e15ce
+# Check the arguments.
8e15ce
+while test $# -gt 0
8e15ce
+do
8e15ce
+    option=$1
8e15ce
+    shift
8e15ce
+
8e15ce
+    case "$option" in
8e15ce
+    -h | --help)
8e15ce
+	usage
8e15ce
+	exit 0 ;;
8e15ce
+    -v | --version)
8e15ce
+	echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
8e15ce
+	exit 0 ;;
8e15ce
+    -*)
8e15ce
+	gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
8e15ce
+	usage
8e15ce
+	exit 1
8e15ce
+	;;
8e15ce
+    # Explicitly ignore non-option arguments, for compatibility.
8e15ce
+    esac
8e15ce
+done
8e15ce
+
8e15ce
+if test -f /etc/sysconfig/kernel ; then
8e15ce
+    . /etc/sysconfig/kernel
8e15ce
+fi
8e15ce
+
8e15ce
+if [ "$MAKEDEBUG" = "yes" ]; then
8e15ce
+    echo GRUB_LINUX_MAKE_DEBUG=true
8e15ce
+    echo export GRUB_LINUX_MAKE_DEBUG
8e15ce
+    echo GRUB_CMDLINE_LINUX_DEBUG=\"systemd.log_level=debug systemd.log_target=kmsg\"
8e15ce
+    echo export GRUB_CMDLINE_LINUX_DEBUG
8e15ce
+    echo GRUB_LINUX_DEBUG_TITLE_POSTFIX=\" with debugging\"
8e15ce
+    echo export GRUB_LINUX_DEBUG_TITLE_POSTFIX
8e15ce
+fi
8e15ce
+if [ "$DEFAULTDEBUG" = "yes" ]; then
8e15ce
+    echo GRUB_DEFAULT_TO_DEBUG=true
8e15ce
+else
8e15ce
+    echo GRUB_DEFAULT_TO_DEBUG=false
8e15ce
+fi
8e15ce
+echo export GRUB_DEFAULT_TO_DEBUG
8e15ce
+if [ "$UPDATEDEFAULT" = "yes" ]; then
8e15ce
+    echo GRUB_UPDATE_DEFAULT_KERNEL=true
8e15ce
+    echo export GRUB_UPDATE_DEFAULT_KERNEL
8e15ce
+fi
8e15ce
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
b35c50
index ba14cf6261..005f093809 100644
8e15ce
--- a/util/grub-mkconfig.in
8e15ce
+++ b/util/grub-mkconfig.in
8e15ce
@@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@"
8e15ce
 grub_file="${bindir}/@grub_file@"
8e15ce
 grub_editenv="${bindir}/@grub_editenv@"
8e15ce
 grub_script_check="${bindir}/@grub_script_check@"
8e15ce
+grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@"
8e15ce
 
8e15ce
 export TEXTDOMAIN=@PACKAGE@
8e15ce
 export TEXTDOMAINDIR="@localedir@"
8e15ce
@@ -158,6 +159,8 @@ if test -f ${sysconfdir}/default/grub ; then
8e15ce
   . ${sysconfdir}/default/grub
8e15ce
 fi
8e15ce
 
8e15ce
+eval "$("${grub_get_kernel_settings}")" || true
8e15ce
+
8e15ce
 if [ "x${GRUB_DISABLE_UUID}" = "xtrue" ]; then
8e15ce
   if [ -z "${GRUB_DISABLE_LINUX_UUID}" ]; then
8e15ce
     GRUB_DISABLE_LINUX_UUID="true"
8e15ce
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
b35c50
index 786dbabb4a..292e333324 100644
8e15ce
--- a/util/grub.d/10_linux.in
8e15ce
+++ b/util/grub.d/10_linux.in
8e15ce
@@ -111,7 +111,8 @@ linux_entry ()
8e15ce
   os="$1"
8e15ce
   version="$2"
8e15ce
   type="$3"
8e15ce
-  args="$4"
8e15ce
+  isdebug="$4"
8e15ce
+  args="$5"
8e15ce
 
8e15ce
   if [ -z "$boot_device_id" ]; then
8e15ce
       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
8e15ce
@@ -123,6 +124,9 @@ linux_entry ()
8e15ce
 	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
8e15ce
 	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
8e15ce
       fi
8e15ce
+      if [ x$isdebug = xdebug ]; then
8e15ce
+	  title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
8e15ce
+      fi
8e15ce
       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
8e15ce
   else
8e15ce
       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
b35c50
@@ -306,11 +310,15 @@ while [ "x$list" != "x" ] ; do
8e15ce
   fi
8e15ce
 
8e15ce
   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
8e15ce
-    linux_entry "${OS}" "${version}" simple \
8e15ce
+    linux_entry "${OS}" "${version}" simple standard \
8e15ce
     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
8e15ce
+    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
8e15ce
+      linux_entry "${OS}" "${version}" simple debug \
8e15ce
+        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
8e15ce
+    fi
8e15ce
 
8e15ce
     submenu_indentation="$grub_tab"
8e15ce
-    
8e15ce
+
8e15ce
     if [ -z "$boot_device_id" ]; then
8e15ce
 	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
8e15ce
     fi
b35c50
@@ -319,10 +327,15 @@ while [ "x$list" != "x" ] ; do
8e15ce
     is_top_level=false
8e15ce
   fi
8e15ce
 
8e15ce
-  linux_entry "${OS}" "${version}" advanced \
8e15ce
+  linux_entry "${OS}" "${version}" advanced standard \
8e15ce
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
8e15ce
+  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
8e15ce
+    linux_entry "${OS}" "${version}" advanced debug \
8e15ce
+                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
8e15ce
+  fi
8e15ce
+
8e15ce
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
8e15ce
-    linux_entry "${OS}" "${version}" recovery \
8e15ce
+    linux_entry "${OS}" "${version}" recovery standard \
8e15ce
                 "single ${GRUB_CMDLINE_LINUX}"
8e15ce
   fi
8e15ce