You are not logged in.

#1 2020-07-16 22:32:06

860lacov
Member
Registered: 2020-05-02
Posts: 497

How to change default kernel

My first installed kernal was linux-lts
Second linux

Currently, with GRUB_DEFAULT=0 the LTS kernel is loaded

During boot, I have two entries.
First one is Arch Linux one and it's lts kernel.
Second is Advanced options for Arch Linux with 4 entries
Arch Linux, with Linux linux-lts
Arch Linux, with Linux linux-lts (fallback initramfs)
Arch Linux, with Linux linux
Arch Linux, with Linux linux (fallback initramfs)

During my research I've found that I can change /etc/default/grub
GRUB_DEFAULT from 0 to full name of desired entry.

1. Should it look like:

GRUB_DEFAULT='Advanced options for Arch Linux>Arch Linux, with Linux linux'

?

I've found that I can use numbers. I tried this method
I read that it's start from 0 so I set up it like this:
GRUB_DEFAULT=1>2
But LTS kernel was loaded.
Sample with 1>2 is from GRUB/Tips and tricks. It should take third entry in advanced menu and it takes first one.
2. So what could be wrong with this?

Last edited by 860lacov (2020-07-16 22:46:04)

Offline

#2 2020-07-16 22:54:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: How to change default kernel

Did you rerun grub-mkconfig?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2020-07-16 23:04:27

860lacov
Member
Registered: 2020-05-02
Posts: 497

Re: How to change default kernel

Trilby wrote:

Did you rerun grub-mkconfig?

Yes.
I checked with the text version and it has changed - system is loading newest kernel.

GRUB_DEFAULT='Advanced options for Arch Linux>Arch Linux, with Linux linux'

It's working.
Are those names changing often? Do I have to check it every time linux kernel is updated?




I still don't understand why numbers are not working

GRUB_DEFAULT=1>2

I wanted to check another method.
I booted with mainline kernel and removed LTS version.
I did grub-mkconfig and then after reboot I installed LTS again. And It was set as default again.
Is this default behavior or becouse it was my first kernel?

Last edited by 860lacov (2020-07-16 23:13:23)

Offline

#4 2021-08-20 00:15:50

linuxninja
Member
Registered: 2018-07-28
Posts: 5

Re: How to change default kernel

If you want to get rid of the submenus, add:

GRUB_DISABLE_SUBMENU="true"

to your /etc/default/grub and re-run your

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

This will make the grub menu contain all the options so you can select the one you want with a number. I've never used the submenu syntax, so don't know anything about it.

Offline

#5 2021-08-20 11:07:22

dogknowsnx
Guest

Re: How to change default kernel

A simple solution would be:
https://wiki.archlinux.org/title/GRUB/T … ious_entry

Last edited by dogknowsnx (2021-08-20 14:10:39)

#6 2021-08-20 19:20:15

860lacov
Member
Registered: 2020-05-02
Posts: 497

Re: How to change default kernel

linuxninja wrote:

If you want to get rid of the submenus, add:

GRUB_DISABLE_SUBMENU="true"

to your /etc/default/grub and re-run your

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

This will make the grub menu contain all the options so you can select the one you want with a number. I've never used the submenu syntax, so don't know anything about it.

It's a quite old topic but thank you.
It's not the answer but it is some solution.
Currently on my old laptop I use sub menu with full name and it works.

On my new hardware I decided to try systemd-boot and I use only current kernel and no lts.

dogknowsnx wrote:

That's something you can do.
Don't know how about now but the time I've been posting this question there was a problem with btrfs and this option.
Don't remember the error message but It was connected with grub not beeing able to write changes on btrfs.

Last edited by 860lacov (2021-08-20 19:21:20)

Offline

#7 2021-08-20 19:57:22

dogknowsnx
Guest

Re: How to change default kernel

Don't remember the error message but It was connected with grub not beeing able to write changes on btrfs.

True, this won't work on btrfs. Since you didn't mention using btrfs anywhere, I thought you might want to give it a shot.
Glad to hear that you found a setup that's working for you.

#8 2022-01-22 06:16:09

lonxwolx
Member
Registered: 2021-12-14
Posts: 1

Re: How to change default kernel

Numbers worked for me. Just have to add parenthesis, it should be GRUB_DEFAULT="1>2". I am also wondering if there are other methods and why the "Arch Linux" entry doesn't default to "linux" kernel.

Offline

#9 2022-01-22 13:45:02

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: How to change default kernel

lonxwolx wrote:

if there are other methods

The recommendation for the current GRUB release is to use the string specified by the --id option in the menuentry line.

lonxwolx wrote:

why the "Arch Linux" entry doesn't default to "linux" kernel

I think that's due to the version_test_gt function in /usr/share/grub/grub-mkconfig_lib — the -lts suffix is interpreted as a version string and hence a newer version. But I might be wrong.


Jin, Jîyan, Azadî

Offline

#10 2022-01-24 13:50:04

Ferdinand
Member
From: Norway
Registered: 2020-01-02
Posts: 338

Re: How to change default kernel

Just a summary from a little dive-in (sorry if this is too much about something too obvious):

The "Arch Linux" entry is the first in the list that is built up in /etc/grub.d/10_linux (round about line 170):

...
	for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
	done ;;
...

I can't find where grub_file_is_not_garbage is defined, but assuming it's just a function for checking that $i is a valid kernel, then that list would be a list of installed kernels, and it will be used a little further down, starting with:

...
while [ "x$list" != "x" ] ; do
  linux=`version_find_latest $list`
  gettext_printf "Found linux image: %s\n" "$linux" >&2
  basename=`basename $linux`
...

Even further down, the entries are added like this:

...
  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
    linux_entry "${OS}" "${version}" simple \
    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
...
  linux_entry "${OS}" "${version}" advanced \
              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
...
    linux_entry "${OS}" "${version}" fallback \
                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
...

And the linux_entry function, that creates the Grub entries, does this:

linux_entry ()
{
  os="$1"
  version="$2"
  type="$3"
  args="$4"

  if [ -z "$boot_device_id" ]; then
      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  fi
  if [ x$type != xsimple ] ; then
      case $type in
	  booster)
	      title="$(gettext_printf "%s, with Linux %s (booster initramfs)" "${os}" "${version}")" ;;
	  fallback)
	      title="$(gettext_printf "%s, with Linux %s (fallback initramfs)" "${os}" "${version}")" ;;
	  recovery)
	      title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
	  *)
	      title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
      esac
      ...
      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  else
      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  fi      
...

So, the first menu entry is keeping ${OS} as its menu title because it's 3rd parameter is simple, but the entries in the Advanced submenu gets more verbose titles.

And with me this ends up with the first entry in my Grub menu having the title Arch Linux, and is actually the /boot/vmlinuz-linux-zen kernel, whereas that same entry in the advanced submenu has the title Arch Linux, with Linux linux-zen (fallback initramfs), while my /boot/vmlinuz-linux kernel exists only in the advanced submenu as Arch Linux, with Linux linux.

Considering the way the list (up at the top) is made, I don't understand why /boot/vmlinuz-linux isn't added first (vmlinuz-zen should alphabetically be the last of the supported kernels), but anyway, I think the whole business of having a simple entry is a unnecessary, as you just end up masking what kernel is actually behind that first entry.

EDIT: I just realized that /usr/bin/grub-mkconfig is a script, and one of the first things it does is to source /usr/share/grub/grub-mkconfig_lib, that @Head_on_a_Stick pointed to. It seems that's where most of the functions in /etc/grub.d/10_linux are defined. So it's a rather big puzzle then, that grub configuration thing. I'll just shut up and read now smile

Last edited by Ferdinand (2022-01-25 06:31:38)

Offline

#11 2025-04-22 08:16:41

zun43d
Member
Registered: 2025-04-22
Posts: 1

Re: How to change default kernel

Numbered entry works but you need to wrap the number with quotation (").
Like this:

GRUB_DEFAULT="1>2"

Last edited by zun43d (2025-04-22 08:17:22)

Offline

#12 2025-04-22 08:38:12

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,480
Website

Re: How to change default kernel

Mod note: taking this opportunity to close this old topic.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB