|
|
8e15ce |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8e15ce |
From: Hans de Goede <hdegoede@redhat.com>
|
|
|
8e15ce |
Date: Wed, 6 Jun 2018 08:44:11 +0200
|
|
|
8e15ce |
Subject: [PATCH] Add auto-hide menu support
|
|
|
8e15ce |
|
|
|
8e15ce |
On single-os systems we do not want to show the menu, unless something
|
|
|
8e15ce |
went wrong with the previous boot, in which case the user may need the
|
|
|
8e15ce |
menu to debug/fix the problem.
|
|
|
8e15ce |
|
|
|
8e15ce |
This commit adds a new grub.d/00_menu_auto_hide file which emits a
|
|
|
8e15ce |
config snippet implementing this. I've chosen to do this in a separate
|
|
|
8e15ce |
grub.d file because chances of this going upstream are small and this way
|
|
|
8e15ce |
it will be easier to rebase.
|
|
|
8e15ce |
|
|
|
8e15ce |
Since auto-hiding the menu requires detecting the previous boot was ok,
|
|
|
8e15ce |
we get fastboot support (where we don't check for a key at all) for free
|
|
|
8e15ce |
so this commit also adds support for this.
|
|
|
8e15ce |
|
|
|
8e15ce |
The new config-file code uses the following variables:
|
|
|
8e15ce |
|
|
|
8e15ce |
menu_auto_hide Set this to "1" to activate the new auto-hide feature
|
|
|
8e15ce |
Set this to "2" to auto-hide the menu even when multiple
|
|
|
8e15ce |
operating systems are installed. Note the menu will still
|
|
|
8e15ce |
auto show after booting an other os as that won't set
|
|
|
8e15ce |
boot_success.
|
|
|
8e15ce |
menu_show_once Set this to "1" to force showing the menu once.
|
|
|
8e15ce |
boot_success The OS sets this to "1" to indicate a successful boot.
|
|
|
8e15ce |
boot_indeterminate The OS increments this integer when rebooting after e.g.
|
|
|
8e15ce |
installing updates or a selinux relabel.
|
|
|
8e15ce |
fastboot If set to "1" and the conditions for auto-hiding the menu
|
|
|
8e15ce |
are met, the menu is not shown and all checks for keypresses
|
|
|
8e15ce |
are skipped, booting the default immediately.
|
|
|
8e15ce |
|
|
|
8e15ce |
30_os-prober.in changes somewhat inspired by:
|
|
|
8e15ce |
https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch
|
|
|
8e15ce |
|
|
|
8e15ce |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
8e15ce |
---
|
|
|
8e15ce |
Changes in v2:
|
|
|
8e15ce |
-Drop shutdown_success tests, there is no meaningful way for systemd to set
|
|
|
8e15ce |
this flag (by the time it knows all filesystems are unmounted or read-only
|
|
|
8e15ce |
-Drop fwsetup_once support, systemd already supports booting directly into
|
|
|
8e15ce |
the fwsetup by doing "systemctl reboot --firmware"
|
|
|
8e15ce |
---
|
|
|
8e15ce |
Makefile.util.def | 6 +++++
|
|
|
8e15ce |
util/grub.d/01_menu_auto_hide.in | 48 ++++++++++++++++++++++++++++++++++++++++
|
|
|
8e15ce |
util/grub.d/30_os-prober.in | 18 +++++++++++++++
|
|
|
8e15ce |
3 files changed, 72 insertions(+)
|
|
|
8e15ce |
create mode 100644 util/grub.d/01_menu_auto_hide.in
|
|
|
8e15ce |
|
|
|
8e15ce |
diff --git a/Makefile.util.def b/Makefile.util.def
|
|
|
8e15ce |
index 41906486a71..04551e095bd 100644
|
|
|
8e15ce |
--- a/Makefile.util.def
|
|
|
8e15ce |
+++ b/Makefile.util.def
|
|
|
8e15ce |
@@ -458,6 +458,12 @@ script = {
|
|
|
8e15ce |
installdir = grubconf;
|
|
|
8e15ce |
};
|
|
|
8e15ce |
|
|
|
8e15ce |
+script = {
|
|
|
8e15ce |
+ name = '01_menu_auto_hide';
|
|
|
8e15ce |
+ common = util/grub.d/01_menu_auto_hide.in;
|
|
|
8e15ce |
+ installdir = grubconf;
|
|
|
8e15ce |
+};
|
|
|
8e15ce |
+
|
|
|
8e15ce |
script = {
|
|
|
8e15ce |
name = '01_users';
|
|
|
8e15ce |
common = util/grub.d/01_users.in;
|
|
|
8e15ce |
diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/01_menu_auto_hide.in
|
|
|
8e15ce |
new file mode 100644
|
|
|
8e15ce |
index 00000000000..ad175870a54
|
|
|
8e15ce |
--- /dev/null
|
|
|
8e15ce |
+++ b/util/grub.d/01_menu_auto_hide.in
|
|
|
8e15ce |
@@ -0,0 +1,48 @@
|
|
|
8e15ce |
+#! /bin/sh
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+# Disable / skip generating menu-auto-hide config parts on serial terminals
|
|
|
8e15ce |
+for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
|
|
|
8e15ce |
+ case "$x" in
|
|
|
8e15ce |
+ serial*)
|
|
|
8e15ce |
+ exit 0
|
|
|
8e15ce |
+ ;;
|
|
|
8e15ce |
+ esac
|
|
|
8e15ce |
+done
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+cat << EOF
|
|
|
8e15ce |
+if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
|
|
|
8e15ce |
+ set last_boot_ok=1
|
|
|
8e15ce |
+else
|
|
|
8e15ce |
+ set last_boot_ok=0
|
|
|
8e15ce |
+fi
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+# Reset boot_indeterminate after a successful boot
|
|
|
8e15ce |
+if [ "\${boot_success}" = "1" ] ; then
|
|
|
8e15ce |
+ set boot_indeterminate=0
|
|
|
8e15ce |
+# Avoid boot_indeterminate causing the menu to be hidden more then once
|
|
|
8e15ce |
+elif [ "\${boot_indeterminate}" = "1" ]; then
|
|
|
8e15ce |
+ set boot_indeterminate=2
|
|
|
8e15ce |
+fi
|
|
|
8e15ce |
+set boot_success=0
|
|
|
8e15ce |
+save_env boot_success boot_indeterminate
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+if [ x\$feature_timeout_style = xy ] ; then
|
|
|
8e15ce |
+ if [ "\${menu_show_once}" ]; then
|
|
|
8e15ce |
+ unset menu_show_once
|
|
|
8e15ce |
+ save_env menu_show_once
|
|
|
8e15ce |
+ set timeout_style=menu
|
|
|
8e15ce |
+ set timeout=60
|
|
|
8e15ce |
+ elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then
|
|
|
8e15ce |
+ set orig_timeout_style=\${timeout_style}
|
|
|
8e15ce |
+ set orig_timeout=\${timeout}
|
|
|
8e15ce |
+ if [ "\${fastboot}" = "1" ]; then
|
|
|
8e15ce |
+ # timeout_style=menu + timeout=0 avoids the countdown code keypress check
|
|
|
8e15ce |
+ set timeout_style=menu
|
|
|
8e15ce |
+ set timeout=0
|
|
|
8e15ce |
+ else
|
|
|
8e15ce |
+ set timeout_style=hidden
|
|
|
8e15ce |
+ set timeout=1
|
|
|
8e15ce |
+ fi
|
|
|
8e15ce |
+ fi
|
|
|
8e15ce |
+fi
|
|
|
8e15ce |
+EOF
|
|
|
8e15ce |
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
|
|
|
8e15ce |
index 4b27bd20153..3c9431cfcfb 100644
|
|
|
8e15ce |
--- a/util/grub.d/30_os-prober.in
|
|
|
8e15ce |
+++ b/util/grub.d/30_os-prober.in
|
|
|
8e15ce |
@@ -42,6 +42,7 @@ if [ -z "${OSPROBED}" ] ; then
|
|
|
8e15ce |
fi
|
|
|
8e15ce |
|
|
|
8e15ce |
osx_entry() {
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
# TRANSLATORS: it refers on the OS residing on device %s
|
|
|
8e15ce |
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
8e15ce |
hints=""
|
|
|
8e15ce |
@@ -102,6 +103,7 @@ for OS in ${OSPROBED} ; do
|
|
|
8e15ce |
|
|
|
8e15ce |
case ${BOOT} in
|
|
|
8e15ce |
chain)
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
|
|
|
8e15ce |
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
8e15ce |
cat << EOF
|
|
|
8e15ce |
@@ -132,6 +134,7 @@ EOF
|
|
|
8e15ce |
EOF
|
|
|
8e15ce |
;;
|
|
|
8e15ce |
efi)
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
|
|
|
8e15ce |
EFIPATH=${DEVICE#*@}
|
|
|
8e15ce |
DEVICE=${DEVICE%@*}
|
|
|
8e15ce |
@@ -176,6 +179,7 @@ EOF
|
|
|
8e15ce |
LINITRD="${LINITRD#/boot}"
|
|
|
8e15ce |
fi
|
|
|
8e15ce |
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
8e15ce |
recovery_params="$(echo "${LPARAMS}" | grep single)" || true
|
|
|
8e15ce |
counter=1
|
|
|
8e15ce |
@@ -257,6 +261,7 @@ EOF
|
|
|
8e15ce |
done
|
|
|
8e15ce |
;;
|
|
|
8e15ce |
hurd)
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
8e15ce |
cat << EOF
|
|
|
8e15ce |
menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
|
|
|
8e15ce |
@@ -283,6 +288,7 @@ EOF
|
|
|
8e15ce |
EOF
|
|
|
8e15ce |
;;
|
|
|
8e15ce |
minix)
|
|
|
8e15ce |
+ found_other_os=1
|
|
|
8e15ce |
cat << EOF
|
|
|
8e15ce |
menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
|
|
|
8e15ce |
EOF
|
|
|
8e15ce |
@@ -299,3 +305,15 @@ EOF
|
|
|
8e15ce |
;;
|
|
|
8e15ce |
esac
|
|
|
8e15ce |
done
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+# We override the results of the menu_auto_hide code here, this is a bit ugly,
|
|
|
8e15ce |
+# but grub-mkconfig writes out the file linearly, so this is the only way
|
|
|
8e15ce |
+if [ "${found_other_os}" = "1" ]; then
|
|
|
8e15ce |
+ cat << EOF
|
|
|
8e15ce |
+# Other OS found, undo autohiding of menu unless menu_auto_hide=2
|
|
|
8e15ce |
+if [ "\${orig_timeout_style}" -a "\${menu_auto_hide}" != "2" ]; then
|
|
|
8e15ce |
+ set timeout_style=\${orig_timeout_style}
|
|
|
8e15ce |
+ set timeout=\${orig_timeout}
|
|
|
8e15ce |
+fi
|
|
|
8e15ce |
+EOF
|
|
|
8e15ce |
+fi
|