You are not logged in.

#1 2021-06-21 12:14:25

4kH
Member
Registered: 2021-06-21
Posts: 3

[SOLVED] GRUB default kernel selection

Hi guys,

So, I was not using multiple kernels anytime before seriously, but I planned to do it for my new install. My use-case is like this ->

For default boot (no user interaction at grub screen), I want the latest kernel to boot, and, if something breaks, I want to have a fallback, that I can manually choose the LTS kernel to boot into my machine. As far as the /etc/defaults/grub file go, yes, I was able to make GRUB go into the "Advanced" section and boot the kernel I like automatically by setting "1>0" for the GRUB_DEFAULT. (I have manually changed the kernel list order using grub-customizer. My LTS kernel was listed as the first...or the 0, and the latest kernel as the third...or the 2, in the beginning. Now, the latest kernel is the 0th kernel under Advanced, and 2nd kernel the LTS kernel). Also, I should mention, that /etc/grub.d/10_linux has linux=`version_find_latest $list` in it.

Now, my question is, when selecting the GRUB_DEFAULT=0, that is the "Arch" main menu above "Advanced", GRUB chooses the LTS kernel by default. Why is it so? Can I make this default behavior to choose the latest kernel without pointing at the Advanced section in the GRUB_DEFAULT? Why does version_find_latest in  /etc/grub.d/10_linux doesn't take care of that?

I want to make it as a permanent solution, where kernel updates wouldn't break my default choice of kernel. Also, if possible, I want to be able to boot into the latest kernel just by selecting the "Arch" main menu, not into the Advanced section.

If anyone has any tips for me, please let me know. It's not like I can't work with the hack I did now, but, I really want to know how GRUB is selecting which kernel to use from the main menu, and not going into the submenu.

Thanks in advance,
73, 4kH

Last edited by 4kH (2021-06-23 08:46:47)

Offline

#2 2021-06-21 12:23:17

Pryka
Member
Registered: 2018-02-07
Posts: 85

Re: [SOLVED] GRUB default kernel selection

https://wiki.archlinux.org/title/GRUB/T … menu_entry

I'm using this solution on my machines. But it won't change "visual" order in GRUB menu. It will just highlight another option of your choosing.

Last edited by Pryka (2021-06-21 12:27:05)

Offline

#3 2021-06-21 12:31:16

4kH
Member
Registered: 2021-06-21
Posts: 3

Re: [SOLVED] GRUB default kernel selection

Pryka wrote:

https://wiki.archlinux.org/title/GRUB/T … menu_entry

I'm using this solution on my machines. But it won't change "visual" order in GRUB

Yes, I did that, I told that in my main post. But, I want to know how Grub selects which kernel to use when choosing the "Arch" option on the main menu. It takes the LTS kernel to boot whenever I choose that. Either manually, or pointing towards the Advanced-> Latest kernel in the /etc/defaults/grub only seems to get the thing done, which is okay..but..I mean..why the other way is not working neutral

linux=`version_find_latest should take care of finding the latest kernel...right?

Offline

#4 2021-06-21 13:10:14

seth
Member
Registered: 2012-09-03
Posts: 51,473

Re: [SOLVED] GRUB default kernel selection

https://wiki.archlinux.org/title/GRUB/T … le_entries

This has nothing to do w/ grub, grub is controlled by /boot/grub/grub.cfg - you can write that file by hand however you want.
grub-mkconfig builds a grub.cfg from the simpler default/grub file - iirc the order is determined by how grub-mkconfig list the kernel images, so use the label selection for the default entry.

Offline

#5 2021-06-23 04:26:45

4kH
Member
Registered: 2021-06-21
Posts: 3

Re: [SOLVED] GRUB default kernel selection

Thanks seth for your help, that does work as you described. But, I found a solution that feels more robust in my opinion.

In your /etc/default/grub, if Arch Linux main menu GRUB entry is the first entry.

GRUB_DEFAULT="0"

If you have dual-boot with some other OS, and have set Arch Linux as the second main menu entry,

GRUB_DEFAULT="1"

Now, in /etc/grub.d/ , check if you have a file named 10_linux or 10_linux_proxy.
If 10_linux is available, then vim/nano into /etc/grub.d/10_linux.
If only 10_linux_proxy is available, then vim/nano into /etc/grub.d/proxifiedScripts/linux

In this file which you have opened in your text editor, search for a line

linux=`version_find_latest $list`

Comment that line out. and add this line just below the commented out line->

linux=`echo $list | tr ' ' '\n' | sort -V | head -1 | cat`

Save and exit. Then

sudo grub-mkconfig -o /boot/grub/grub.cfg

Reboot to complete the procedure.

Now, the error here, according the Grub Bug Tracker, is that the naming convention of Arch kernels is a little different from what GRUB expects. So, the sorting algorithm that is default, takes the lts kernel as the latest one. But, the solution that I mentioned is working so far pretty well.
Hope this helps.
Regards,
73, 4kH.

Offline

#6 2021-06-23 06:01:51

seth
Member
Registered: 2012-09-03
Posts: 51,473

Re: [SOLVED] GRUB default kernel selection

Notice that this change is going to be reverted w/ the next grub update as the file gets overridden.

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

Board footer

Powered by FluxBB