Reimplement grub-reboot to not depend on saved_entry. Use next_entry

variable for one time boot menu entry.
This commit is contained in:
Andrey Borzenkov 2013-05-06 22:13:34 +04:00
parent fa2923436b
commit 5945c2f849
4 changed files with 25 additions and 12 deletions

View file

@ -1,3 +1,8 @@
2013-05-06 Andrey Borzenkov <arvidjaar@gmail.com>
Reimplement grub-reboot to not depend on saved_entry. Use next_entry
variable for one time boot menu entry.
2013-05-05 Bean <bean123ch@gmail.com>
* grub-core/commands/testspeed.c: New command testspeed.

View file

@ -46,8 +46,6 @@ export TEXTDOMAINDIR="@localedir@"
usage () {
gettext_printf "Usage: %s [OPTION] MENU_ENTRY\n" "$self"
gettext "Set the default boot menu entry for GRUB, for the next boot only."; echo
gettext_printf "This requires setting GRUB_DEFAULT=saved in %s/default/grub.\n" "$sysconfdir"
echo
print_option_help "-h, --help" "$(gettext "print this message and exit")"
print_option_help "-v, --version" "$(gettext "print the version information and exit")"
dirmsg="$(gettext_printf "expect GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
@ -129,17 +127,14 @@ fi
grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
# Restore saved_entry if it was set by previous version
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^prev_saved_entry=//p'`
if [ "$prev_saved_entry" ]; then
$grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
else
# We need some non-empty value for prev_saved_entry so that GRUB will
# recognise that grub-reboot has been used and restore the previous
# saved entry. "0" is the same as an empty value, i.e. the first menu
# entry.
$grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
$grub_editenv ${grubdir}/grubenv set saved_entry="$prev_saved_entry"
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
fi
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
$grub_editenv ${grubdir}/grubenv set next_entry="$entry"
# Bye.
exit 0

View file

@ -130,6 +130,7 @@ fi
grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
$grub_editenv ${grubdir}/grubenv unset next_entry
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.

View file

@ -51,13 +51,25 @@ if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
cat <<EOF
if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
set default="${GRUB_DEFAULT_BUTTON}"
elif [ "\${next_entry}" ] ; then
set default="\${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${GRUB_DEFAULT}"
fi
EOF
else
cat <<EOF
set default="${GRUB_DEFAULT}"
if [ "\${next_entry}" ] ; then
set default="\${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${GRUB_DEFAULT}"
fi
EOF
fi
cat <<EOF