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

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