Bug 33790 - savedefault doesn't honor boot_once under submenu
Summary: savedefault doesn't honor boot_once under submenu
Status: CLOSED WONTFIX
Alias: None
Product: Branch p7
Classification: Distributions
Component: grub2-common (show other bugs)
Version: не указана
Hardware: all Linux
: P3 normal
Assignee: Andrey Cherepanov
QA Contact: qa-p7@altlinux.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-21 18:18 MSK by Ivan Zakharyaschev
Modified: 2018-05-21 13:15 MSK (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2017-08-21 18:18:51 MSK
grub2-common-2.00-alt21.x86_64
grub2-efi-2.00-alt21.x86_64
grub2-pc-2.00-alt21.x86_64

(As for the new grub version in Sisyphus, I haven't yet tested this.)

The idea of the savedefault function in /boot/grub/grub.cfg is to update the saved default unless in the "boot_once" mode (so that the last saved default will be used on the next boot). And this is broken if "savedefault" is called from under a submenu, because AFAIU the "boot_once" variable is not inherited in the context of a submenu. (This can have really bad consequences for those who want to rely on the "boot_once" behavior invoked with grub-reboot: the good default will be overwritten. Workaround: don't use nested submenus OR remove the call to "savedefault" from the tested entries OR don't test nested menuentries with grub-reboot 'submenu_ID>menuentry_ID'.)

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
set default="${saved_entry}"

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

....

"savedefault" function is called in all the following generated menuentries:

# fgrep -A1 menuentry /boot/grub/grub.cfg
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi
--
export menuentry_id_option

--
menuentry 'ALT Linux Sisyphus' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-simple-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
submenu 'Дополнительные параметры для ALT Linux Sisyphus' $menuentry_id_option 'gnulinux-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	menuentry 'ALT Linux Sisyphus, vmlinuz' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-vmlinuz-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
	menuentry 'ALT Linux Sisyphus, vmlinuz (recovery mode)' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-vmlinuz-recovery-15eb82bb-060a-4cab-bfba-be39a4153542' {
		load_video
--
	menuentry 'ALT Linux Sisyphus, 4.9.44-std-def-alt1' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.9.44-std-def-alt1-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
	menuentry 'ALT Linux Sisyphus, 2.6.32-ovz-el-alt154' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-2.6.32-ovz-el-alt154-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
	menuentry 'ALT Linux Sisyphus, 2.6.32-ovz-el-alt151' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-2.6.32-ovz-el-alt151-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
	menuentry 'ALT Linux Sisyphus, 4.1.15-std-def-alt1' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.1.15-std-def-alt1-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
	menuentry 'ALT Linux Sisyphus, 3.14.51-std-def-alt1' --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.14.51-std-def-alt1-advanced-15eb82bb-060a-4cab-bfba-be39a4153542' {
	savedefault
--
menuentry 'ALT Linux starter kit (Trientalis)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
	savedefault
--
submenu 'Дополнительные параметры для ALT Linux starter kit (Trientalis)' $menuentry_id_option 'osprober-gnulinux-advanced-1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
	menuentry 'ALT Linux starter kit (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
	menuentry 'ALT Linux starter kit, vmlinuz (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
	menuentry 'ALT Linux starter kit, vmlinuz (recovery mode) (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
	menuentry 'ALT Linux starter kit, 2.6.32-ovz-el-alt139 (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-2.6.32-ovz-el-alt139--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
	menuentry 'ALT Linux starter kit, 3.14.58-std-def-alt0.M70P.1 (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-3.14.58-std-def-alt0.M70P.1--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
	menuentry 'ALT Linux starter kit, 2.6.32-ovz-el-alt138 (на /dev/sdc1)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-2.6.32-ovz-el-alt138--1cca8e47-f247-4c3f-bb9e-cd443267b1e3' {
		savedefault
--
menuentry "Memtest86+-5.01" {
	insmod part_msdos
Comment 1 Ivan Zakharyaschev 2017-08-21 18:54:10 MSK
Способ проверить, что сейчас сохранено:

# xargs -0 </boot/grub/grubenv 
# GRUB Environment Block
saved_entry=gnulinux-simple-15eb82bb-060a-4cab-bfba-be39a4153542
prev_saved_entry=
####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

Способ проверить, какой пункт был загружен:

# xargs -0 </proc/cmdline 
BOOT_IMAGE=/boot/vmlinuz root=UUID=15eb82bb-060a-4cab-bfba-be39a4153542 ro panic=30 splash

#
Comment 2 Michael Shigorin 2017-08-22 09:15:42 MSK
Для документации стоит использовать вики; ну и проверить на 2.02 тоже стоит.
Comment 3 Anton Farygin 2018-05-21 13:15:21 MSK
p7 is no longer supported