Show the boot menu if the previous boot failed.

This commit is contained in:
Colin Watson 2013-11-13 00:08:56 +00:00 committed by Colin Watson
parent eb0a00804d
commit a2dac38edc
10 changed files with 234 additions and 8 deletions

1
debian/changelog vendored
View File

@ -17,6 +17,7 @@ grub2 (2.00-20) UNRELEASED; urgency=low
(LP: #1242417). (LP: #1242417).
- If building for Ubuntu: - If building for Ubuntu:
+ Bypass menu unless other OSes are installed or Shift is pressed. + Bypass menu unless other OSes are installed or Shift is pressed.
+ Show the boot menu if the previous boot failed.
-- Colin Watson <cjwatson@debian.org> Mon, 07 Oct 2013 09:48:53 +0100 -- Colin Watson <cjwatson@debian.org> Mon, 07 Oct 2013 09:48:53 +0100

2
debian/control vendored
View File

@ -71,7 +71,7 @@ Description: GRand Unified Bootloader, version 2 (dummy package)
Package: grub-common Package: grub-common
Priority: optional Priority: optional
Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-sparc any-mipsel any-ia64 Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-sparc any-mipsel any-ia64
Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base, ${lsb-base-depends}
Replaces: grub-pc (<< 2.00-4), grub-ieee1275 (<< 2.00-4), grub-efi (<< 1.99-1), grub-coreboot (<< 2.00-4), grub-linuxbios (<< 1.96+20080831-1), grub-efi-ia32 (<< 2.00-4), grub-efi-amd64 (<< 2.00-4), grub-efi-ia64 (<< 2.00-4), grub-yeeloong (<< 2.00-4) Replaces: grub-pc (<< 2.00-4), grub-ieee1275 (<< 2.00-4), grub-efi (<< 1.99-1), grub-coreboot (<< 2.00-4), grub-linuxbios (<< 1.96+20080831-1), grub-efi-ia32 (<< 2.00-4), grub-efi-amd64 (<< 2.00-4), grub-efi-ia64 (<< 2.00-4), grub-yeeloong (<< 2.00-4)
Recommends: os-prober (>= 1.33) Recommends: os-prober (>= 1.33)
Suggests: multiboot-doc, grub-emu, xorriso (>= 0.5.6.pl00), desktop-base (>= 4.0.6), console-setup Suggests: multiboot-doc, grub-emu, xorriso (>= 0.5.6.pl00), desktop-base (>= 4.0.6), console-setup

42
debian/grub-common.init vendored Normal file
View File

@ -0,0 +1,42 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: grub-common
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Record successful boot for GRUB
# Description: GRUB displays the boot menu at the next boot if it
# believes that the previous boot failed. This script
# informs it that the system booted successfully.
### END INIT INFO
which grub-editenv >/dev/null 2>&1 || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
case $1 in
start|restart|force-reload)
[ "$VERBOSE" != no ] && log_action_msg "Recording successful boot for GRUB"
[ -s /boot/grub/grubenv ] || rm -f /boot/grub/grubenv
mkdir -p /boot/grub
grub-editenv /boot/grub/grubenv unset recordfail
[ "$VERBOSE" != no ] && log_end_msg $?
;;
stop)
;;
status)
exit 0
;;
*)
echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
exit 0

11
debian/grub-common.pm-sleep vendored Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# Tell grub that resume was successful
case "$1" in
thaw)
[ -s /boot/grub/grubenv ] || rm -f /boot/grub/grubenv
mkdir -p /boot/grub
grub-editenv /boot/grub/grubenv unset recordfail
;;
esac

View File

@ -8,9 +8,13 @@ Description: Add configure option to bypass boot menu if possible
This may or may not remain Ubuntu-specific, although it's not obviously This may or may not remain Ubuntu-specific, although it's not obviously
wanted upstream. It implements a requirement of wanted upstream. It implements a requirement of
https://wiki.ubuntu.com/DesktopExperienceTeam/KarmicBootExperienceDesignSpec#Bootloader. https://wiki.ubuntu.com/DesktopExperienceTeam/KarmicBootExperienceDesignSpec#Bootloader.
.
If the previous boot failed (defined as failing to get to the end of one of
the normal runlevels), then show the boot menu regardless.
Author: Colin Watson <cjwatson@ubuntu.com> Author: Colin Watson <cjwatson@ubuntu.com>
Author: Richard Laager <rlaager@wiktel.com>
Forwarded: no Forwarded: no
Last-Update: 2013-11-12 Last-Update: 2013-11-13
Index: b/configure.ac Index: b/configure.ac
=================================================================== ===================================================================
@ -34,27 +38,132 @@ Index: b/configure.ac
LIBS="" LIBS=""
AC_SUBST([FONT_SOURCE]) AC_SUBST([FONT_SOURCE])
Index: b/docs/grub.texi
===================================================================
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1289,6 +1289,15 @@
Each module will be loaded as early as possible, at the start of
@file{grub.cfg}.
+@item GRUB_RECORDFAIL_TIMEOUT
+If this option is set, it overrides the default recordfail setting. The
+default setting is -1, which causes GRUB to wait for user input. This option
+should be set on headless and appliance systems where access to a console is
+restricted or limited.
+
+This option is only effective when GRUB was configured with the
+@option{--enable-quick-boot} option.
+
@end table
For more detailed customisation of @command{grub-mkconfig}'s output, you may
Index: b/util/grub-mkconfig.in
===================================================================
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -228,7 +228,8 @@
GRUB_INIT_TUNE \
GRUB_SAVEDEFAULT \
GRUB_ENABLE_CRYPTODISK \
- GRUB_BADRAM
+ GRUB_BADRAM \
+ GRUB_RECORDFAIL_TIMEOUT
if test "x${grub_cfg}" != "x"; then
rm -f "${grub_cfg}.new"
Index: b/util/grub.d/00_header.in Index: b/util/grub.d/00_header.in
=================================================================== ===================================================================
--- a/util/grub.d/00_header.in --- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in
@@ -23,6 +23,7 @@ @@ -23,6 +23,8 @@
exec_prefix="@exec_prefix@" exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@" datarootdir="@datarootdir@"
grub_lang=`echo $LANG | cut -d . -f 1` grub_lang=`echo $LANG | cut -d . -f 1`
+grubdir="`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`"
+quick_boot="@QUICK_BOOT@" +quick_boot="@QUICK_BOOT@"
export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@" export TEXTDOMAINDIR="@localedir@"
@@ -272,7 +273,7 @@ @@ -46,6 +48,7 @@
cat << EOF
if [ -s \$prefix/grubenv ]; then
+ set have_grubenv=true
load_env
fi
EOF
@@ -86,7 +89,31 @@
save_env saved_entry
fi
}
+EOF
+
+if [ "$quick_boot" = 1 ]; then
+ cat <<EOF
+function recordfail {
+ set recordfail=1
+EOF
+ FS="$(grub-probe --target=fs "${grubdir}")"
+ case "$FS" in
+ btrfs | cpiofs | newc | odc | romfs | squash4 | tarfs | zfs)
+ cat <<EOF
+ # GRUB lacks write support for $FS, so recordfail support is disabled.
+EOF
+ ;;
+ *)
+ cat <<EOF
+ if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi
+EOF
+ esac
+ cat <<EOF
+}
+EOF
+fi
+cat <<EOF
function load_video {
EOF
if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
@@ -272,7 +299,15 @@
make_timeout () make_timeout ()
{ {
- if [ "x${1}" != "x" ] ; then - if [ "x${1}" != "x" ] ; then
+ if [ "$quick_boot" = 0 ] && [ "x${1}" != "x" ] ; then + if [ "$quick_boot" = 1 ] ; then
+ cat << EOF
+if [ "\${recordfail}" = 1 ]; then
+ set timeout=${GRUB_RECORDFAIL_TIMEOUT:--1}
+else
+ set timeout=${2}
+fi
+EOF
+ elif [ "x${1}" != "x" ] ; then
if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
verbose= verbose=
else else
Index: b/util/grub.d/10_linux.in
===================================================================
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -21,6 +21,7 @@
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
quiet_boot="@QUIET_BOOT@"
+quick_boot="@QUICK_BOOT@"
. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
@@ -113,6 +114,9 @@
else
echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
fi
+ if [ "$quick_boot" = 1 ]; then
+ echo "recordfail" | sed "s/^/$submenu_indentation/"
+ fi
if [ x$type != xrecovery ] ; then
save_default_entry | sed -e "s/^/\t/"
fi
Index: b/util/grub.d/30_os-prober.in Index: b/util/grub.d/30_os-prober.in
=================================================================== ===================================================================
--- a/util/grub.d/30_os-prober.in --- a/util/grub.d/30_os-prober.in

17
debian/rules vendored
View File

@ -55,8 +55,10 @@ endif
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes)) ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
DEFAULT_CMDLINE := quiet splash DEFAULT_CMDLINE := quiet splash
confflags += --enable-quiet-boot --enable-quick-boot confflags += --enable-quiet-boot --enable-quick-boot
substvars := -Vlsb-base-depends="lsb-base (>= 3.0-6)"
else else
DEFAULT_CMDLINE := quiet DEFAULT_CMDLINE := quiet
substvars :=
endif endif
SB_PACKAGE := SB_PACKAGE :=
@ -303,6 +305,10 @@ install/grub-common:
>> debian/grub-common.$$i ; \ >> debian/grub-common.$$i ; \
fi ; \ fi ; \
done done
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
install -D -m 0755 debian/grub-common.pm-sleep \
$(CURDIR)/debian/$(package)/etc/pm/sleep.d/10_grub-common
endif
override_dh_install: override_dh_install:
dh_install -pgrub2 -pgrub-linuxbios -pgrub-efi -pgrub-rescue-pc -pgrub-firmware-qemu dh_install -pgrub2 -pgrub-linuxbios -pgrub-efi -pgrub-rescue-pc -pgrub-firmware-qemu
@ -331,6 +337,14 @@ override_dh_installdocs:
dh_installdocs -pgrub-common -pgrub-rescue-pc -pgrub-firmware-qemu -A AUTHORS NEWS README THANKS TODO dh_installdocs -pgrub-common -pgrub-rescue-pc -pgrub-firmware-qemu -A AUTHORS NEWS README THANKS TODO
dh_installdocs -Ngrub-common -Ngrub-rescue-pc -Ngrub-firmware-qemu --link-doc=grub-common dh_installdocs -Ngrub-common -Ngrub-rescue-pc -Ngrub-firmware-qemu --link-doc=grub-common
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
override_dh_installinit:
dh_installinit -- start 99 2 3 4 5 .
else
override_dh_installinit:
:
endif
override_dh_bugfiles: override_dh_bugfiles:
dh_bugfiles -A dh_bugfiles -A
@ -347,7 +361,8 @@ LEGACY_DOC_CONFLICTS := grub-doc (<< 0.97-32), grub-legacy-doc (<< 0.97-59)
endif endif
override_dh_gencontrol: override_dh_gencontrol:
dh_gencontrol -- -Vlegacy-doc-conflicts="$(LEGACY_DOC_CONFLICTS)" dh_gencontrol -- \
-Vlegacy-doc-conflicts="$(LEGACY_DOC_CONFLICTS)" $(substvars)
TARNAME := grub2_$(deb_version)_$(DEB_HOST_ARCH).tar.gz TARNAME := grub2_$(deb_version)_$(DEB_HOST_ARCH).tar.gz

View File

@ -1289,6 +1289,15 @@ This option may be set to a list of GRUB module names separated by spaces.
Each module will be loaded as early as possible, at the start of Each module will be loaded as early as possible, at the start of
@file{grub.cfg}. @file{grub.cfg}.
@item GRUB_RECORDFAIL_TIMEOUT
If this option is set, it overrides the default recordfail setting. The
default setting is -1, which causes GRUB to wait for user input. This option
should be set on headless and appliance systems where access to a console is
restricted or limited.
This option is only effective when GRUB was configured with the
@option{--enable-quick-boot} option.
@end table @end table
For more detailed customisation of @command{grub-mkconfig}'s output, you may For more detailed customisation of @command{grub-mkconfig}'s output, you may

View File

@ -228,7 +228,8 @@ export GRUB_DEFAULT \
GRUB_INIT_TUNE \ GRUB_INIT_TUNE \
GRUB_SAVEDEFAULT \ GRUB_SAVEDEFAULT \
GRUB_ENABLE_CRYPTODISK \ GRUB_ENABLE_CRYPTODISK \
GRUB_BADRAM GRUB_BADRAM \
GRUB_RECORDFAIL_TIMEOUT
if test "x${grub_cfg}" != "x"; then if test "x${grub_cfg}" != "x"; then
rm -f "${grub_cfg}.new" rm -f "${grub_cfg}.new"

View File

@ -23,6 +23,7 @@ prefix="@prefix@"
exec_prefix="@exec_prefix@" exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@" datarootdir="@datarootdir@"
grub_lang=`echo $LANG | cut -d . -f 1` grub_lang=`echo $LANG | cut -d . -f 1`
grubdir="`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`"
quick_boot="@QUICK_BOOT@" quick_boot="@QUICK_BOOT@"
export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAIN=@PACKAGE@
@ -47,6 +48,7 @@ if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT
cat << EOF cat << EOF
if [ -s \$prefix/grubenv ]; then if [ -s \$prefix/grubenv ]; then
set have_grubenv=true
load_env load_env
fi fi
EOF EOF
@ -87,7 +89,31 @@ function savedefault {
save_env saved_entry save_env saved_entry
fi fi
} }
EOF
if [ "$quick_boot" = 1 ]; then
cat <<EOF
function recordfail {
set recordfail=1
EOF
FS="$(grub-probe --target=fs "${grubdir}")"
case "$FS" in
btrfs | cpiofs | newc | odc | romfs | squash4 | tarfs | zfs)
cat <<EOF
# GRUB lacks write support for $FS, so recordfail support is disabled.
EOF
;;
*)
cat <<EOF
if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi
EOF
esac
cat <<EOF
}
EOF
fi
cat <<EOF
function load_video { function load_video {
EOF EOF
if [ -n "${GRUB_VIDEO_BACKEND}" ]; then if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
@ -273,7 +299,15 @@ fi
make_timeout () make_timeout ()
{ {
if [ "$quick_boot" = 0 ] && [ "x${1}" != "x" ] ; then if [ "$quick_boot" = 1 ] ; then
cat << EOF
if [ "\${recordfail}" = 1 ]; then
set timeout=${GRUB_RECORDFAIL_TIMEOUT:--1}
else
set timeout=${2}
fi
EOF
elif [ "x${1}" != "x" ] ; then
if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
verbose= verbose=
else else

View File

@ -21,6 +21,7 @@ prefix="@prefix@"
exec_prefix="@exec_prefix@" exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@" datarootdir="@datarootdir@"
quiet_boot="@QUIET_BOOT@" quiet_boot="@QUIET_BOOT@"
quick_boot="@QUICK_BOOT@"
. "@datadir@/@PACKAGE@/grub-mkconfig_lib" . "@datadir@/@PACKAGE@/grub-mkconfig_lib"
@ -113,6 +114,9 @@ linux_entry ()
else else
echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
fi fi
if [ "$quick_boot" = 1 ]; then
echo "recordfail" | sed "s/^/$submenu_indentation/"
fi
if [ x$type != xrecovery ] ; then if [ x$type != xrecovery ] ; then
save_default_entry | sed -e "s/^/\t/" save_default_entry | sed -e "s/^/\t/"
fi fi