How to disable grub2 editing itself on boot, for remembering the last selected entry

I was surprised to discover that in Manjaro, grub2 has the ability to self modify when booting. This comes in the form of remembering the last boot entry you used and automatically selecting it next time the machine is powered on, instead of defaulting to the topmost option.

While this is a harmless albeit useless feature, it implies the boot loader changes itself when picking an entry. I was used to the idea that only the update-grub command (or similar) can make any permanent change to the settings. Editing the config on use just to remember the last booted entry feels unsafe for something so minor considering how important the loader is: What if grub can become corrupted if you abort a boot or the machine is powered off right as you select a menu entry? That risk’s obviously greater if you have a power failure during a grub installation process, albeit that’s only triggered if you update kernels and you know when to be aware. Was curious if there’s more input on this.

Explore your GRUB config file.

//EDIT: what is unsafe in the remembering the last boot entry you previously selected.

2 Likes

I looked in /boot but couldn’t find where this info is stored. My concern is that in the past, I thought the boot loader is fully static and accessed fully as read-only on boot, only edited when the system updates it: Just wanting to make sure there’s no risk in updating any settings during use like that.

You can do like this.

With the advanced text editor (kate, featherpad, etc) on your system do this:

featherpad /etc/default/grub

Search for:

GRUB_SAVEDEFAULT=true

Comment this line or change from true to false

sudo update-grub

T+ = See you later

3 Likes

This is not your GRUB config file, look into /etc/default/grub

//EDIT: GRUB - ArchWiki

This info is stored in /boot/grub/grubenv

prompt> cat /boot/grub/grubenv                                                 
# GRUB Environment Block
# WARNING: Do not edit this file by tools other than grub-editenv!!!
menu_auto_hide=1
boot_success=1
saved_entry=1>2
##################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################%

Guys, what the user wanted was that in a dual boot, the last system chosen to boot would not be marked for automatic start and it would be resolved in /etc/default/grub

Manjaro is not the only distribution where GRUB will save the user’s previous selected menuentry

GRUB has 3 options for the default boot option

GNU GRUB Manual 2.04 - Simple-configuration

‘GRUB_DEFAULT’
The default menu entry. This may be a number, in which case it identifies the Nth entry in the generated menu counted from zero, or the title of a menu entry, or the special string ‘saved’.

‘GRUB_SAVEDEFAULT’
If this option is set to ‘true’, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. This is only useful if ‘GRUB_DEFAULT=saved’

If user wants GRUB to default to first menuentry GRUB_SAVEDEFAULT=true should be commented out to #GRUB_SAVEDEFAULT=true (as already suggested)

but GRUB_DEFAULT=Saved should also be changed to GRUB_DEFAULT=0

1 Like

You’re absolutely right, but the good thing is also that the Linux operating system offers us a range beyond what our eyes can see.

Me, I do as I showed the fellow above and never had to edit more than the lines I mentioned in my previous message.

Best regards,
Paulo Creto

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.