make grub default to last boot

Issues related to applications and software problems and general support
Post Reply
ezekiyovel@gmail.com
Posts: 1
Joined: 2019/11/02 22:15:06

make grub default to last boot

Post by ezekiyovel@gmail.com » 2019/11/02 22:25:15

Hello,

I have just installed centos 8 alongside windows 10, and grub shows a menu with three centos entries and windows, with first entry as default.
I want grub to always pre-select the entry I used last boot, e.g. if at some point I boot windows I want the fourth entry in the grub menu (the windows entry) to be pre-selected and the same with centos.
I read here: https://wiki.centos.org/HowTos/Grub2 that this could be achieved by having the next two lines in the /etc/default/grub file:

Code: Select all

GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved
and than re-creating the grub boot menu using the command:

Code: Select all

grub2-mkconfig -o /boot/grub2/grub.cfg
but I must be misunderstanding something because it doesn't work.
here is my /etc/default/grub:

Code: Select all

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
hopefully someone can help me find out how to make my grub always default to load last used os.

addmin
Posts: 23
Joined: 2019/05/07 10:16:11

Re: make grub default to last boot

Post by addmin » 2019/11/03 02:32:48

after mkconfig run this to make it persistent.

Code: Select all

sudo grub2-install "/dev/"`lsblk | grep disk -m 1 | cut -d" " -f1`

User avatar
TrevorH
Forum Moderator
Posts: 27125
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: make grub default to last boot

Post by TrevorH » 2019/11/03 02:39:36

That doesn't look like a wise thing to run. What do you think it is going to do?
CentOS 6 will die in November 2020 - migrate sooner rather than later!
CentOS 5 has been EOL for nearly 3 years and should no longer be used for anything!
Full time Geek, part time moderator. Use the FAQ Luke

addmin
Posts: 23
Joined: 2019/05/07 10:16:11

Re: make grub default to last boot

Post by addmin » 2019/11/03 04:45:42

ok. this can be used to choose the menuentry.

Code: Select all

grub2-set-default MENU_ENTRY
#MENU_ENTRY is a number, a menu item title or a menu item identifier.

nouvo09
Posts: 146
Joined: 2009/09/19 19:21:36
Location: Paris, France

Re: make grub default to last boot

Post by nouvo09 » 2019/11/03 16:30:35

Just be carefull what you are talking about.

BLSCFG=enable means that the fedora boot informations are no more picked up from the grub.cfg file but in the /boot/loader/entries directory where every version stores its boot information.

By the way the grub loader does not take care of the last boot also if corresponding options are in the /etc/default/grub file. Instead, grub reads these entries sorted by ALPHABETIC ORDER and as you can see, the corresponding names always begin with the UUID.

So, starting with BLS enabled, grub displays the menu choices by alphabetic order of UUID.

The only way to fix that is to change GRUB_ENABLE_BLSCFG to false and regenerate the grub. cfg file.
Member of centos-FR forum

Post Reply

Return to “CentOS 8 - General Support”