nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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