# Hooks for Automating Systemd-Boot Kernel installs

**URL:** <https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254>\
**Category:** Kernel, boot, graphics & hardware\
**Created:** [April 2, 2021, 7:20am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254 "2021-04-02T07:20:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 2, 2021, 7:20am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/1 "2021-04-02T07:20:09Z")

</div>

**DO NOT USE THIS** , @dalto **has a much better solution and this is abandoned. Follow instructions here** [[Tutorial] Convert to systemd-boot](https://forum.endeavouros.com/t/tutorial-convert-to-systemd-boot/13290)

NOTE: In its current state its not likely to handle multiboot and maybe other issues. This is an early state hack of @dalto s work at best…there be dragons here

Hey Everyone, its been a while

Ive had a lot going on these past couple months with almost being homeless lol but ive started working on some ideas for things to make EOS better for myself and others.

Recently Ive moved to using systemd-boot as it seems to be a touch faster boot time vs grub for me with minimal changes to the setup vs grub

This is a set of hooks to automate the creation of systemd boot entries. This is a modification of

> **[dalto / systemd-boot Manager for Manjaro · GitLab](https://gitlab.com/dalto.8/systemd-boot-manager)**
>
> GitLab.com

I had to tweak it to work properly on EOS and it should work with only changing the “ENTRY\_ROOT=” for regular Arch. This set of hooks assumes you followed the Arch Wiki for systemd-boot [https://wiki.archlinux.org/index.php/Systemd-boot](https://wiki.archlinux.org/index.php/Systemd-boot)

> **[Echoa / systemd-boot-manager · GitLab](https://gitlab.com/echoa/systemd-boot-manager)**
>
> This projects attempts to add boot entry automation for users of systemd-boot on Arch

Current bugs are

* * *

1. If you remove the base Arch kernel (you shouldnt do this anyway) it will wipe all of your systemd-boot entries. Ive yet to figure out how to fix this

2. Currently havent figured out how to change the default boot option automatically to the latest installed kernel. You can do it via terminal by using “sudo sdboot-manage default” and it will ask you which conf file should be the default

3. You tell me, Id like this to end up pretty universal

* * *

Installation

* * *

git clone [https://gitlab.com/echoa/systemd-boot-manager.git](https://gitlab.com/echoa/systemd-boot-manager.git)

makepkg -si

Read instructions on the repo so you can configure it properly

* * *

If you know bash a bit better than i do or just have a good idea on how this can be improved feel free to start an issue on my gitlab

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [April 2, 2021, 12:50pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/2 "2021-04-02T12:50:39Z")

</div>

First, some general comments.

- There were a few reasons I created `systemd-boot-manager` at the time
  - Manjaro had constantly changing kernel names since the kernel version was embedded into the kernel name
  - I was trying to create an experience as close to possible as the way grub is managed
  - I wanted an easy way to setup systemd-boot that could be automated in Manjaro Architect.

- The reasons I have never championed it’s use on Arch are:
  - Arch doesn’t have changing kernel names like Manjaro so this is a lot of complexity to add for not much additional functionality
  - The kernel pattern matching stuff is likely to break if you are multi-booting distros
  - Since creating systemd-boot-manager, systemd-boot created a built-in method for doing this called `kernel-install`. I am in the process of testing a solution for EndeavourOS which fully automates the use of `kernel-install`. It should be ready soon.

- If you are planning to maintain this for general use(as opposed to your personal use), there are some things you should be aware of
  - It needs ongoing maintenance since anything that changes the options line in a non-static way needs to be accounted for manually. This is most commonly a change with filesystems and/or encryption. This means you need to acquire a working knowledge of all that if you don’t already have it.
  - To properly test it requires a large investment in time since there are so many different filesystem and encryption combinations
  - It essential to have working knowledge of the whole script, since changes to one section can have unintended consequences. Most of the contributions I get need to be reworked by the authors because they have failed to understand the whole scope and inadvertently broken something else.

I took a quick look at what you did and have some specific comments

- The reason removing the `vmlinuz-linux` kernel removes all the entries is because it has a shared root with all the other kernels. That doesn’t happen in Manjaro so you will need to modify that section to be more specific.
- You removed the lines that set `$kernelpath` but you are still using the variable. The reason it is important is because many systemd-boot users keep the kernel/initramfs in subdirectories to better enable multi-booting.
- Setting the pattern matching to `vmlinuz-*` is likely to cause problems if anyone is multi-booting. You may pull the kernels from other distros in.
- All that kernel name parsing and reassembly can be simplified on Arch
  - The description/name/variant can be found with `${kernel#vmlinuz-}`
  - The name of initramfs should always be `"initramfs-${kernel#vmlinuz-}.img" `

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [April 2, 2021, 2:43pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/3 "2021-04-02T14:43:36Z")

</div>

I would like to try systemd boot on EndeavourOS but i don’t have the skill to make it happen. 🙃

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [April 2, 2021, 2:45pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/4 "2021-04-02T14:45:01Z")

</div>

It is very simple. I am in the process of writing a tutorial.

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [April 2, 2021, 2:45pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/5 "2021-04-02T14:45:49Z")

</div>

I was going to ask you to do that. 😉

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 2, 2021, 2:50pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/6 "2021-04-02T14:50:21Z")

</div>

The man himself 😄

Hey thanks for the good criticism, and i would like to try and make it a more general option for creating systemd-boot entries, likely just Arch specific though but I havent thought about it.

> [@dalto](#):
>
> It needs ongoing maintenance since anything that changes the options line in a non-static way needs to be accounted for manually. This is most commonly a change with filesystems and/or encryption. This means you need to acquire a working knowledge of all that if you don’t already have it.

Im learning about encryption/filesystems but am in no way and expert and wont claim to be.

> [@dalto](#):
>
> To properly test it requires a large investment in time since there are so many different filesystem and encryption combinations

I was actually looking to setup VMs for some testing to try and do this

> [@dalto](#):
>
> It essential to have working knowledge of the whole script, since changes to one section can have unintended consequences. Most of the contributions I get need to be reworked by the authors because they have failed to understand the whole scope and inadvertently broken something else.

Ive been creating separate scripts based on each section to test and try and make sure i get whats going on throughout the original.

Thanks again for the criticism and information, its been noted thoroughly

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 2, 2021, 2:50pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/7 "2021-04-02T14:50:59Z")

</div>

Its super easy to setup, just making loaders all the time is painful xP

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [April 2, 2021, 2:58pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/8 "2021-04-02T14:58:46Z")

</div>

> [@Echoa](#):
>
> I was actually looking to setup VMs for some testing to try and do this

That is really the only efficient way to do it. You can take snapshots at a known system state. Test, then instantly revert the snapshot.

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 2, 2021, 3:03pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/9 "2021-04-02T15:03:19Z")

</div>

> [@dalto](#):
>
> That is really the only efficient way to do it. You can take snapshots at a known system state. Test, then instantly revert the snapshot.

The bigger issue is going to be getting the time to do all of the testing 😅 Im working on 3 other projects too atm so I added a note at the top that this is a hack at best of your work so people can be aware this be dragons

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 2, 2021, 3:27pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/10 "2021-04-02T15:27:25Z")

</div>

> [@dalto](#):
>
> You removed the lines that set `$kernelpath` but you are still using the variable. The reason it is important is because many systemd-boot users keep the kernel/initramfs in subdirectories to better enable multi-booting.

I actually didnt mean to do this, i was looking just now and realized what you meant (oops 😬 )

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 3, 2021, 6:48am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/11 "2021-04-03T06:48:49Z")

</div>

made some adjustments based on feedback from @dalto (thanks a bunch), removed the systemd update hook as i want this to be just for entries and theres a perfectly good hook for that already.

Still working on bug #1, need to make the removal more specific

note: was running into an issue with initramfs line having a . at the beginning, currently it ignores the leading . but this may be a bad idea

note 2: This will likely be rendered pointless by what dalto is working on and his will probably be much better than my hack job of his old scripts

---

<div class="post-metadata">

**Author:** ![Feakster](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/feakster/32/24784_2.png) [@Feakster](https://forum.endeavouros.com/u/Feakster)\
**Post date:** [April 3, 2021, 8:15am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/12 "2021-04-03T08:15:20Z")

</div>

Would this work with BTRFS & allow snapshot booting, or is that still a GRUB-only feature for now?

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [April 3, 2021, 11:25am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/13 "2021-04-03T11:25:21Z")

</div>

How does that work? Does it give you a series of menus to choose your snapshot or does it multiply the number of kernels by the number of snapshots?

---

<div class="post-metadata">

**Author:** ![Feakster](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/feakster/32/24784_2.png) [@Feakster](https://forum.endeavouros.com/u/Feakster)\
**Post date:** [April 3, 2021, 11:40am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/14 "2021-04-03T11:40:11Z")

</div>

The `grub-btrfs` package places a snapshots entry in your list of bootable entries in grub. I’ve never actually selected one, but I presume it contains a sublist of all my current snapshots.

> **[GitHub - Antynea/grub-btrfs: Include btrfs snapshots at boot options. (Grub...](https://github.com/Antynea/grub-btrfs)**
>
> Include btrfs snapshots at boot options. (Grub menu) - GitHub - Antynea/grub-btrfs: Include btrfs snapshots at boot options. (Grub menu)

From a brief internet search, I’m guessing this functionality still isn’t possible with `systemd-boot`.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [April 3, 2021, 11:43am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/15 "2021-04-03T11:43:42Z")

</div>

I am not sure that would be possible in systemd-boot. It is a much less complicated thing than grub. It doesn’t have submenus.

You could create entries for the snapshots but it would multiply them out. In other words, if you had two kernels and created entries for the last 5 snapshots you would have a list of 20 things.

---

<div class="post-metadata">

**Author:** ![Feakster](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/feakster/32/24784_2.png) [@Feakster](https://forum.endeavouros.com/u/Feakster)\
**Post date:** [April 3, 2021, 11:45am UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/16 "2021-04-03T11:45:18Z")

</div>

I guess `systemd-boot` will get more features with time.

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [April 3, 2021, 1:14pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/17 "2021-04-03T13:14:57Z")

</div>

Yeah this atm at least seems a bit outside of what systemd-boot can do in a nice way. It would likely balloon your entries significantly and be a mess with how it is now but possibly in the future.

Systemd-boot is supposed to be pretty dead simple which it does well and why i use it, but as for doing things like what youre looking at id probably stick to grub

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [July 23, 2021, 9:31pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/18 "2021-07-23T21:31:22Z")

</div>

This hasnt been replied to in a bit but i wanted to add a tip for those of us that do you systemd-boot.

Originally I had been working on a script to let me easily change the default boot entry in the loader.conf, but after looking into sd-boot a bit i found that making the script is completely unnecessary as sd-boot can handle this all on its own.

Normally it will automatically select which kernel to boot based on the current default title when it was setup and then use whatever is the newest kernel/highest version number kernel for that automatically. This means when installing custom kernels just add higher versioning to it and itll be used before default arch/distro kernel.

Now if you want to change your default its very simple. when booting stop at the bootloader menu by pressing space bar. Then select the entry you wish to be default and press D. This will select that entry as the default boot option for sd-boot with NO SCRIPT REQUIRED 😃

If i wouldve taken the time to look at sd-boot i couldve saved myself some time testing and duplicating a feature that it already had, but at least i learned some things.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 23, 2021, 9:44pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/19 "2021-07-23T21:44:56Z")

</div>

> [@Echoa](#):
>
> Then select the entry you wish to be default and press D. This will select that entry as the default boot option for sd-boot with NO SCRIPT REQUIRED

This works as long as your entry and version names are static. However, if they aren’t, it will no longer be selected once your kernel is updated.

I use a different trick. The default value in loader.conf accepts wildcards. So you can usually set a string that will boot the latest version of the kernel you want. Some thing like `*zen.conf` could be used to boot the latest zen kernel.

---

<div class="post-metadata">

**Author:** ![Echoa](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/echoa/32/77553_2.png) [@Echoa](https://forum.endeavouros.com/u/Echoa)\
**Post date:** [July 23, 2021, 10:00pm UTC](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254/20 "2021-07-23T22:00:21Z")

</div>

> [@dalto](#):
>
> This works as long as your entry and version names are static. However, if they aren’t, it will no longer be selected once your kernel is updated.

I dont use zen but does it use a different title besides “Arch Linux” and weird versioning in the conf file? So far for me I havent had any issues with TKG kernel once figuring this out but I also obviously dont cover all use cases.

The fact that loader also accepts wildcards can also make this convenient using your method.

[Next page](https://forum.endeavouros.com/t/hooks-for-automating-systemd-boot-kernel-installs/13254.md?page=2)
