Systemd-boot and multiple kernels

I rebuilt my system the other day and took the opportunity to switch from grub to systemd-boot, the new default. I set it to remember what I booted from last so I don’t really have to pay attention to the boot menu, except when the kernel updates. The lts kernel is listed first so after a kernel update I have to select the newly installed one otherwise it will default to lts. How can I prevent this? I have a couple of machines that I run headless and update via ssh. With grub it’s not an issue because the boot options says Linux not linux-version number. If I were to migrate them from grub to systemd-boot, being headless would become an issue. How do I fix this, or do I have to remove the lts kernel. Note even though I have it installed I’ve never actually had to boot into it, but I’ve kept it thinking it’s good practice.

You can examine the contents of /efi/loader/entries, identify the kernel you wish to set as the default boot option, and change the default line in /efi/loader/loader.conf accordingly. See the example in this thread:

That will not change the order the kernels appear in the list, but it will allow you to control what is set as the default.

1 Like

Highlight the one you want to boot from and hit “Shift D” on the keyboard.

2 Likes

Ooh, I like that–that looks easy. :eyes: :joy:

1 Like

That will break as soon as there is a kernel update.

The solution recommended by @BluishHumility above is more effective. That is the same thing recommended in the wiki.

2 Likes

Been using it for years on Arch base OS and never failed me yet. :man_shrugging:

It works with manually created entries where the names don’t change.

We use kernel-install, provided by systemd, which dynamically create the entries as new kernels are removed and installed. As a result, the entry names change.

1 Like

My loader.conf is different then as I use this.

timeout 3
#console-mode keepconf and arch
default arch-*

and have my arch.conf and arch-lts.conf in my entries directory

If the entry is dynamically created, how can I set it up as the default? Sorry if it’s a stupid question I’m still working through these entries to figure it out

The method that will survive the kernel being renamed is the one described in post 2: Systemd-boot and multiple kernels - #2 by BluishHumility

I also found the wiki entry dalto mentioned, which bears the same explanation: https://discovery.endeavouros.com/installation/systemd-boot/2022/12/

How to change the default entry to boot

There is a default entry inside /efi/loader/loader.conf that determine the default boot entry.

On a new install, it will look something like this:

default 665eca4ae83246df8ec17d1cbc6a1763*

That first string of characters is you entry token which identifies the install. That is important if you are dual-booting with another Linux, otherwise it can be replaced with *. That line supports wildcards and so if you want to boot the LTS kernel by default you could use something like this:

default 665eca4ae83246df8ec17d1cbc6a1763*lts.conf

Alternatively, if you want to boot the mainline kernel by default, something like this should work:

default 665eca4ae83246df8ec17d1cbc6a1763-*-arch?-?.conf

These changes will take effect on the next reboot and nothing else is required except modifying the file.

3 Likes

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