2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-07-10 19:08:14 +00:00
|
|
|
From: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
Date: Wed, 6 Jun 2018 08:44:11 +0200
|
|
|
|
Subject: [PATCH] Add auto-hide menu support
|
|
|
|
|
|
|
|
On single-os systems we do not want to show the menu, unless something
|
|
|
|
went wrong with the previous boot, in which case the user may need the
|
|
|
|
menu to debug/fix the problem.
|
|
|
|
|
|
|
|
This commit adds a new grub.d/00_menu_auto_hide file which emits a
|
|
|
|
config snippet implementing this. I've chosen to do this in a separate
|
|
|
|
grub.d file because chances of this going upstream are small and this way
|
|
|
|
it will be easier to rebase.
|
|
|
|
|
|
|
|
Since auto-hiding the menu requires detecting the previous boot was ok,
|
|
|
|
we get fastboot support (where we don't check for a key at all) for free
|
|
|
|
so this commit also adds support for this.
|
|
|
|
|
|
|
|
The new config-file code uses the following variables:
|
|
|
|
|
|
|
|
menu_auto_hide Set this to "1" to activate the new auto-hide feature
|
|
|
|
Set this to "2" to auto-hide the menu even when multiple
|
|
|
|
operating systems are installed. Note the menu will still
|
|
|
|
auto show after booting an other os as that won't set
|
|
|
|
boot_success.
|
|
|
|
menu_show_once Set this to "1" to force showing the menu once.
|
|
|
|
boot_success The OS sets this to "1" to indicate a successful boot.
|
|
|
|
boot_indeterminate The OS increments this integer when rebooting after e.g.
|
|
|
|
installing updates or a selinux relabel.
|
|
|
|
fastboot If set to "1" and the conditions for auto-hiding the menu
|
|
|
|
are met, the menu is not shown and all checks for keypresses
|
|
|
|
are skipped, booting the default immediately.
|
|
|
|
|
|
|
|
30_os-prober.in changes somewhat inspired by:
|
|
|
|
https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch
|
|
|
|
|
|
|
|
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
---
|
|
|
|
Makefile.util.def | 6 +++++
|
2019-07-16 09:23:51 +00:00
|
|
|
util/grub.d/01_menu_auto_hide.in | 48 ++++++++++++++++++++++++++++++++++++++++
|
2018-07-10 19:08:14 +00:00
|
|
|
util/grub.d/30_os-prober.in | 18 +++++++++++++++
|
2019-07-16 09:23:51 +00:00
|
|
|
3 files changed, 72 insertions(+)
|
|
|
|
create mode 100644 util/grub.d/01_menu_auto_hide.in
|
2018-07-10 19:08:14 +00:00
|
|
|
|
|
|
|
diff --git a/Makefile.util.def b/Makefile.util.def
|
2024-08-01 23:56:47 +00:00
|
|
|
index 1079add5bbe..5b9f85d4869 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/Makefile.util.def
|
|
|
|
+++ b/Makefile.util.def
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -461,6 +461,12 @@ script = {
|
2018-07-10 19:08:14 +00:00
|
|
|
installdir = grubconf;
|
|
|
|
};
|
|
|
|
|
|
|
|
+script = {
|
2019-07-16 09:23:51 +00:00
|
|
|
+ name = '01_menu_auto_hide';
|
|
|
|
+ common = util/grub.d/01_menu_auto_hide.in;
|
2018-07-10 19:08:14 +00:00
|
|
|
+ installdir = grubconf;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
script = {
|
|
|
|
name = '01_users';
|
|
|
|
common = util/grub.d/01_users.in;
|
2019-07-16 09:23:51 +00:00
|
|
|
diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/01_menu_auto_hide.in
|
2018-07-10 19:08:14 +00:00
|
|
|
new file mode 100644
|
2024-08-01 23:56:47 +00:00
|
|
|
index 00000000000..ad175870a54
|
2018-07-10 19:08:14 +00:00
|
|
|
--- /dev/null
|
2019-07-16 09:23:51 +00:00
|
|
|
+++ b/util/grub.d/01_menu_auto_hide.in
|
|
|
|
@@ -0,0 +1,48 @@
|
2018-07-10 19:08:14 +00:00
|
|
|
+#! /bin/sh
|
|
|
|
+
|
|
|
|
+# Disable / skip generating menu-auto-hide config parts on serial terminals
|
|
|
|
+for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
|
|
|
|
+ case "$x" in
|
|
|
|
+ serial*)
|
|
|
|
+ exit 0
|
|
|
|
+ ;;
|
|
|
|
+ esac
|
|
|
|
+done
|
|
|
|
+
|
|
|
|
+cat << EOF
|
|
|
|
+if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
|
|
|
|
+ set last_boot_ok=1
|
|
|
|
+else
|
|
|
|
+ set last_boot_ok=0
|
|
|
|
+fi
|
|
|
|
+
|
|
|
|
+# Reset boot_indeterminate after a successful boot
|
|
|
|
+if [ "\${boot_success}" = "1" ] ; then
|
|
|
|
+ set boot_indeterminate=0
|
|
|
|
+# Avoid boot_indeterminate causing the menu to be hidden more then once
|
|
|
|
+elif [ "\${boot_indeterminate}" = "1" ]; then
|
|
|
|
+ set boot_indeterminate=2
|
|
|
|
+fi
|
|
|
|
+set boot_success=0
|
2019-07-16 09:23:51 +00:00
|
|
|
+save_env boot_success boot_indeterminate
|
2018-07-10 19:08:14 +00:00
|
|
|
+
|
|
|
|
+if [ x\$feature_timeout_style = xy ] ; then
|
|
|
|
+ if [ "\${menu_show_once}" ]; then
|
|
|
|
+ unset menu_show_once
|
|
|
|
+ save_env menu_show_once
|
|
|
|
+ set timeout_style=menu
|
2019-07-16 09:23:51 +00:00
|
|
|
+ set timeout=60
|
2018-07-10 19:08:14 +00:00
|
|
|
+ elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then
|
|
|
|
+ set orig_timeout_style=\${timeout_style}
|
|
|
|
+ set orig_timeout=\${timeout}
|
|
|
|
+ if [ "\${fastboot}" = "1" ]; then
|
|
|
|
+ # timeout_style=menu + timeout=0 avoids the countdown code keypress check
|
|
|
|
+ set timeout_style=menu
|
|
|
|
+ set timeout=0
|
|
|
|
+ else
|
|
|
|
+ set timeout_style=hidden
|
|
|
|
+ set timeout=1
|
|
|
|
+ fi
|
|
|
|
+ fi
|
|
|
|
+fi
|
|
|
|
+EOF
|
|
|
|
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
|
2024-08-01 23:56:47 +00:00
|
|
|
index d7d423b2eaf..18fe02cefd8 100644
|
2018-07-10 19:08:14 +00:00
|
|
|
--- a/util/grub.d/30_os-prober.in
|
|
|
|
+++ b/util/grub.d/30_os-prober.in
|
2021-06-14 08:48:27 +00:00
|
|
|
@@ -42,6 +42,7 @@ if [ -z "${OSPROBED}" ] ; then
|
2018-07-10 19:08:14 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
osx_entry() {
|
|
|
|
+ found_other_os=1
|
|
|
|
# TRANSLATORS: it refers on the OS residing on device %s
|
|
|
|
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
|
hints=""
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -106,6 +107,7 @@ for OS in ${OSPROBED} ; do
|
2018-07-10 19:08:14 +00:00
|
|
|
|
|
|
|
case ${BOOT} in
|
|
|
|
chain)
|
|
|
|
+ found_other_os=1
|
|
|
|
|
|
|
|
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
|
cat << EOF
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -136,6 +138,7 @@ EOF
|
2018-07-10 19:08:14 +00:00
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
efi)
|
|
|
|
+ found_other_os=1
|
|
|
|
|
|
|
|
EFIPATH=${DEVICE#*@}
|
|
|
|
DEVICE=${DEVICE%@*}
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -180,6 +183,7 @@ EOF
|
2018-07-10 19:08:14 +00:00
|
|
|
LINITRD="${LINITRD#/boot}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
+ found_other_os=1
|
|
|
|
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
|
recovery_params="$(echo "${LPARAMS}" | grep single)" || true
|
|
|
|
counter=1
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -261,6 +265,7 @@ EOF
|
2018-07-10 19:08:14 +00:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
hurd)
|
|
|
|
+ found_other_os=1
|
|
|
|
onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
|
|
|
|
cat << EOF
|
|
|
|
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}")' {
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -287,6 +292,7 @@ EOF
|
2018-07-10 19:08:14 +00:00
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
minix)
|
|
|
|
+ found_other_os=1
|
|
|
|
cat << EOF
|
|
|
|
menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" {
|
|
|
|
EOF
|
2024-08-01 23:56:47 +00:00
|
|
|
@@ -303,3 +309,15 @@ EOF
|
2021-03-12 21:54:28 +00:00
|
|
|
;;
|
2018-07-10 19:08:14 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
+
|
|
|
|
+# We override the results of the menu_auto_hide code here, this is a bit ugly,
|
|
|
|
+# but grub-mkconfig writes out the file linearly, so this is the only way
|
|
|
|
+if [ "${found_other_os}" = "1" ]; then
|
|
|
|
+ cat << EOF
|
|
|
|
+# Other OS found, undo autohiding of menu unless menu_auto_hide=2
|
|
|
|
+if [ "\${orig_timeout_style}" -a "\${menu_auto_hide}" != "2" ]; then
|
|
|
|
+ set timeout_style=\${orig_timeout_style}
|
|
|
|
+ set timeout=\${orig_timeout}
|
|
|
|
+fi
|
|
|
|
+EOF
|
|
|
|
+fi
|