dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

4fe85b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4fe85b
From: Peter Jones <pjones@redhat.com>
4fe85b
Date: Thu, 23 Jun 2016 11:01:39 -0400
4fe85b
Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux
4fe85b
4fe85b
This patch adds grub-get-kernel-settings, which reads the system kernel
4fe85b
installation configuration from /etc/sysconfig/kernel, and outputs
4fe85b
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
4fe85b
variables are then used by 10_linux to choose whether or not to create
4fe85b
debug stanzas.
4fe85b
4fe85b
Resolves: rhbz#1226325
4fe85b
---
4fe85b
 configure.ac                                   |  2 +
4fe85b
 Makefile.util.def                              |  7 ++
4fe85b
 .gitignore                                     |  1 +
4fe85b
 util/bash-completion.d/grub-completion.bash.in | 22 +++++++
4fe85b
 util/grub-get-kernel-settings.3                | 20 ++++++
4fe85b
 util/grub-get-kernel-settings.in               | 91 ++++++++++++++++++++++++++
4fe85b
 util/grub-mkconfig.in                          |  3 +
4fe85b
 util/grub.d/10_linux.in                        | 23 +++++--
4fe85b
 8 files changed, 164 insertions(+), 5 deletions(-)
4fe85b
 create mode 100644 util/grub-get-kernel-settings.3
4fe85b
 create mode 100644 util/grub-get-kernel-settings.in
4fe85b
4fe85b
diff --git a/configure.ac b/configure.ac
4fe85b
index 04c052dc610..8b10a93cb56 100644
4fe85b
--- a/configure.ac
4fe85b
+++ b/configure.ac
4fe85b
@@ -58,6 +58,7 @@ grub_TRANSFORM([grub-install])
4fe85b
 grub_TRANSFORM([grub-mkconfig])
4fe85b
 grub_TRANSFORM([grub-mkfont])
4fe85b
 grub_TRANSFORM([grub-mkimage])
4fe85b
+grub_TRANSFORM([grub-get-kernel-settings])
4fe85b
 grub_TRANSFORM([grub-glue-efi])
4fe85b
 grub_TRANSFORM([grub-mklayout])
4fe85b
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
4fe85b
@@ -75,6 +76,7 @@ grub_TRANSFORM([grub-file])
4fe85b
 grub_TRANSFORM([grub-bios-setup.3])
4fe85b
 grub_TRANSFORM([grub-editenv.1])
4fe85b
 grub_TRANSFORM([grub-fstest.3])
4fe85b
+grub_TRANSFORM([grub-get-kernel-settings.3])
4fe85b
 grub_TRANSFORM([grub-glue-efi.3])
4fe85b
 grub_TRANSFORM([grub-install.1])
4fe85b
 grub_TRANSFORM([grub-kbdcomp.3])
4fe85b
diff --git a/Makefile.util.def b/Makefile.util.def
4fe85b
index e2821a2f3a5..3918e3b5292 100644
4fe85b
--- a/Makefile.util.def
4fe85b
+++ b/Makefile.util.def
4fe85b
@@ -704,6 +704,13 @@ script = {
4fe85b
   installdir = sbin;
4fe85b
 };
4fe85b
 
4fe85b
+script = {
4fe85b
+  name = grub-get-kernel-settings;
4fe85b
+  common = util/grub-get-kernel-settings.in;
4fe85b
+  mansection = 3;
4fe85b
+  installdir = sbin;
4fe85b
+};
4fe85b
+
4fe85b
 script = {
4fe85b
   name = grub-set-default;
4fe85b
   common = util/grub-set-default.in;
4fe85b
diff --git a/.gitignore b/.gitignore
4fe85b
index e49f76b114a..547ef0bcff0 100644
4fe85b
--- a/.gitignore
4fe85b
+++ b/.gitignore
4fe85b
@@ -61,6 +61,7 @@ grub-fstest.exe
4fe85b
 grub_fstest_init.c
4fe85b
 grub_fstest_init.h
4fe85b
 grub_func_test
4fe85b
+grub-get-kernel-settings
4fe85b
 grub-install
4fe85b
 grub-install.exe
4fe85b
 grub-kbdcomp
4fe85b
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
4fe85b
index 44bf135b9f8..5c4acd496d4 100644
4fe85b
--- a/util/bash-completion.d/grub-completion.bash.in
4fe85b
+++ b/util/bash-completion.d/grub-completion.bash.in
4fe85b
@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \
4fe85b
 unset __grub_sparc64_setup_program
4fe85b
 
4fe85b
 
4fe85b
+#
4fe85b
+# grub-get-kernel-settings
4fe85b
+#
4fe85b
+_grub_get_kernel_settings () {
4fe85b
+    local cur
4fe85b
+
4fe85b
+    COMPREPLY=()
4fe85b
+    cur=`_get_cword`
4fe85b
+
4fe85b
+    if [[ "$cur" == -* ]]; then
4fe85b
+        __grubcomp "$(__grub_get_options_from_help)"
4fe85b
+    else
4fe85b
+        # Default complete with a filename
4fe85b
+        _filedir
4fe85b
+    fi
4fe85b
+}
4fe85b
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
4fe85b
+have ${__grub_get_kernel_settings_program} && \
4fe85b
+ complete -F _grub_get_kernel_settings -o filenames ${__grub_get_kernel_settings_program}
4fe85b
+unset __grub_get_kernel_settings_program
4fe85b
+
4fe85b
+
4fe85b
 #
4fe85b
 # grub-install
4fe85b
 #
4fe85b
diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3
4fe85b
new file mode 100644
4fe85b
index 00000000000..ba33330e28d
4fe85b
--- /dev/null
4fe85b
+++ b/util/grub-get-kernel-settings.3
4fe85b
@@ -0,0 +1,20 @@
4fe85b
+.TH GRUB-GET-KERNEL-SETTINGS 3 "Thu Jun 25 2015"
4fe85b
+.SH NAME
4fe85b
+\fBgrub-get-kernel-settings\fR \(em Evaluate the system's kernel installation settings for use while making a grub configuration file.
4fe85b
+
4fe85b
+.SH SYNOPSIS
4fe85b
+\fBgrub-get-kernel-settings\fR [OPTION]
4fe85b
+
4fe85b
+.SH DESCRIPTION
4fe85b
+\fBgrub-get-kernel-settings\fR reads the kernel installation settings on the host system, and emits a set of grub settings suitable for use when creating a grub configuration file.
4fe85b
+
4fe85b
+.SH OPTIONS
4fe85b
+.TP
4fe85b
+-h, --help
4fe85b
+Display program usage and exit.
4fe85b
+.TP
4fe85b
+-v, --version
4fe85b
+Display the current version.
4fe85b
+
4fe85b
+.SH SEE ALSO
4fe85b
+.BR "info grub"
4fe85b
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
4fe85b
new file mode 100644
4fe85b
index 00000000000..ae0b4696d49
4fe85b
--- /dev/null
4fe85b
+++ b/util/grub-get-kernel-settings.in
4fe85b
@@ -0,0 +1,91 @@
4fe85b
+#!/bin/sh
4fe85b
+set -e
4fe85b
+
4fe85b
+# Evaluate new-kernel-pkg's configuration file.
4fe85b
+# Copyright (C) 2016 Free Software Foundation, Inc.
4fe85b
+#
4fe85b
+# GRUB is free software: you can redistribute it and/or modify
4fe85b
+# it under the terms of the GNU General Public License as published by
4fe85b
+# the Free Software Foundation, either version 3 of the License, or
4fe85b
+# (at your option) any later version.
4fe85b
+#
4fe85b
+# GRUB is distributed in the hope that it will be useful,
4fe85b
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4fe85b
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4fe85b
+# GNU General Public License for more details.
4fe85b
+#
4fe85b
+# You should have received a copy of the GNU General Public License
4fe85b
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
4fe85b
+
4fe85b
+prefix="@prefix@"
4fe85b
+exec_prefix="@exec_prefix@"
4fe85b
+datarootdir="@datarootdir@"
4fe85b
+
4fe85b
+prefix="@prefix@"
4fe85b
+exec_prefix="@exec_prefix@"
4fe85b
+sbindir="@sbindir@"
4fe85b
+bindir="@bindir@"
4fe85b
+sysconfdir="@sysconfdir@"
4fe85b
+PACKAGE_NAME=@PACKAGE_NAME@
4fe85b
+PACKAGE_VERSION=@PACKAGE_VERSION@
4fe85b
+host_os=@host_os@
4fe85b
+datadir="@datadir@"
4fe85b
+if [ "x$pkgdatadir" = x ]; then
4fe85b
+    pkgdatadir="${datadir}/@PACKAGE@"
4fe85b
+fi
4fe85b
+grub_cfg=""
4fe85b
+
4fe85b
+self=`basename $0`
4fe85b
+
4fe85b
+grub_probe="${sbindir}/@grub_probe@"
4fe85b
+grub_file="${bindir}/@grub_file@"
4fe85b
+grub_editenv="${bindir}/@grub_editenv@"
4fe85b
+grub_script_check="${bindir}/@grub_script_check@"
4fe85b
+
4fe85b
+export TEXTDOMAIN=@PACKAGE@
4fe85b
+export TEXTDOMAINDIR="@localedir@"
4fe85b
+
4fe85b
+. "${pkgdatadir}/grub-mkconfig_lib"
4fe85b
+
4fe85b
+# Usage: usage
4fe85b
+# Print the usage.
4fe85b
+usage () {
4fe85b
+    gettext_printf "Usage: %s [OPTION]\n" "$self"
4fe85b
+    gettext "Evaluate new-kernel-pkg configuration"; echo
4fe85b
+    echo
4fe85b
+    print_option_help "-h, --help" "$(gettext "print this message and exit")"
4fe85b
+    print_option_help "-v, --version" "$(gettext "print the version information and exit")"
4fe85b
+    echo
4fe85b
+}
4fe85b
+
4fe85b
+# Check the arguments.
4fe85b
+while test $# -gt 0
4fe85b
+do
4fe85b
+    option=$1
4fe85b
+    shift
4fe85b
+
4fe85b
+    case "$option" in
4fe85b
+    -h | --help)
4fe85b
+	usage
4fe85b
+	exit 0 ;;
4fe85b
+    -v | --version)
4fe85b
+	echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
4fe85b
+	exit 0 ;;
4fe85b
+    -*)
4fe85b
+	gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
4fe85b
+	usage
4fe85b
+	exit 1
4fe85b
+	;;
4fe85b
+    # Explicitly ignore non-option arguments, for compatibility.
4fe85b
+    esac
4fe85b
+done
4fe85b
+
4fe85b
+if test -f /etc/sysconfig/kernel ; then
4fe85b
+    . /etc/sysconfig/kernel
4fe85b
+fi
4fe85b
+
4fe85b
+if [ "$MAKEDEBUG" = "yes" ]; then
4fe85b
+    echo GRUB_LINUX_MAKE_DEBUG=true
4fe85b
+    echo GRUB_CMDLINE_LINUX_DEBUG=\"systemd.log_level=debug systemd.log_target=kmsg\"
4fe85b
+    echo GRUB_LINUX_DEBUG_TITLE_POSTFIX=\" with debugging\"
4fe85b
+fi
4fe85b
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
4fe85b
index 0cfe6047539..aa4fdb8a3b2 100644
4fe85b
--- a/util/grub-mkconfig.in
4fe85b
+++ b/util/grub-mkconfig.in
4fe85b
@@ -42,6 +42,7 @@ grub_probe="${sbindir}/@grub_probe@"
4fe85b
 grub_file="${bindir}/@grub_file@"
4fe85b
 grub_editenv="${bindir}/@grub_editenv@"
4fe85b
 grub_script_check="${bindir}/@grub_script_check@"
4fe85b
+grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@"
4fe85b
 
4fe85b
 export TEXTDOMAIN=@PACKAGE@
4fe85b
 export TEXTDOMAINDIR="@localedir@"
4fe85b
@@ -148,6 +149,8 @@ if test -f ${sysconfdir}/default/grub ; then
4fe85b
   . ${sysconfdir}/default/grub
4fe85b
 fi
4fe85b
 
4fe85b
+eval `${grub_get_kernel_settings}` || true
4fe85b
+
4fe85b
 if [ "x$GRUB_DISABLE_UUID" != "xtrue" -a -z "$GRUB_DEVICE_UUID" ]; then
4fe85b
   GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED"
4fe85b
 fi
4fe85b
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
4fe85b
index b3c460cb266..0d0086d3b6a 100644
4fe85b
--- a/util/grub.d/10_linux.in
4fe85b
+++ b/util/grub.d/10_linux.in
4fe85b
@@ -99,7 +99,8 @@ linux_entry ()
4fe85b
   os="$1"
4fe85b
   version="$2"
4fe85b
   type="$3"
4fe85b
-  args="$4"
4fe85b
+  isdebug="$4"
4fe85b
+  args="$5"
4fe85b
 
4fe85b
   sixteenbit=""
4fe85b
   linuxefi="linux"
4fe85b
@@ -130,6 +131,9 @@ linux_entry ()
4fe85b
   else
4fe85b
       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
4fe85b
   fi      
4fe85b
+  if [ x$isdebug = xdebug ]; then
4fe85b
+      title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
4fe85b
+  fi
4fe85b
   if [ x$type != xrecovery ] ; then
4fe85b
       save_default_entry | grub_add_tab
4fe85b
   fi
4fe85b
@@ -281,11 +285,15 @@ while [ "x$list" != "x" ] ; do
4fe85b
   fi
4fe85b
 
4fe85b
   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
4fe85b
-    linux_entry "${OS}" "${version}" simple \
4fe85b
+    linux_entry "${OS}" "${version}" simple standard \
4fe85b
     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
4fe85b
+    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
4fe85b
+      linux_entry "${OS}" "${version}" simple debug \
4fe85b
+        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
4fe85b
+    fi
4fe85b
 
4fe85b
     submenu_indentation="$grub_tab"
4fe85b
-    
4fe85b
+
4fe85b
     if [ -z "$boot_device_id" ]; then
4fe85b
 	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
4fe85b
     fi
4fe85b
@@ -294,10 +302,15 @@ while [ "x$list" != "x" ] ; do
4fe85b
     is_top_level=false
4fe85b
   fi
4fe85b
 
4fe85b
-  linux_entry "${OS}" "${version}" advanced \
4fe85b
+  linux_entry "${OS}" "${version}" advanced standard \
4fe85b
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
4fe85b
+  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
4fe85b
+    linux_entry "${OS}" "${version}" advanced debug \
4fe85b
+                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
4fe85b
+  fi
4fe85b
+
4fe85b
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
4fe85b
-    linux_entry "${OS}" "${version}" recovery \
4fe85b
+    linux_entry "${OS}" "${version}" recovery standard \
4fe85b
                 "single ${GRUB_CMDLINE_LINUX}"
4fe85b
   fi
4fe85b