More robust systemd-boot intergration

With this post I’d like to vouch for better systemd-boot integration. When its installed at /boot (I assume) everything works fine. However, when it’s installed at /boot/efi there are a lot of hurdles to manually overcome.

As I am dual booting with PopOS (transitioning to Manjaro after using it for 3 years), I had an active systemd-boot installation on /boot/efi. I installed Manjaro with the architect, and although I select install location as /boot/efi during the installation process, it caused it to wipe all active entries present (PopOS in my case), and did not install a Manjaro entry. To get up and running I had to first copy my boot files from /boot to a location inside /boot/efi, as it otherwise couldn’t accessed, in my case /boot/efi/EFI/Manjaro/<kernel version>/

However, the trouble persists even after. I thought I had fixed this by manually amending /etc/mkinitcpio.d/linux510.conf to use my custom location, however that results in a kernel unsync (see my post for more details).

Thus in the end I still have to manually create new boot entries for every new kernel version, and I have to copy the boot files over manually every time they are regenerated for whatever reason.

Edit: While doing more research on the topic, I came across systemd’s “boot loader specification” link. Sounds like something excellent for this situation, and is something I recognize as Pop has implemented it

A week ago I was excited to move to Manjaro, after using PopOS for three years. To make the transition as smooth as possible I dual booted Manjaro along side Pop. As Pop uses a systemd-boot installation in /boot/efi, I also selected that option during the Manjaro Architect installation, expecting it to integrate seamlessly. However, to the only thing that did was remove all my existing sdboot entries in /boot/efi/loader/entries. After posting this as a feature request on the forum here, I still wanted to resolve the issue myself, as I manually had to copy the kernel images, and recreate the sdboot entries everytime a kernel or initramfs image got updated.

Problem

Regardless of bootloader installation installation location, the kernel image installation location is currently hardcoded into the pacman hooks to /boot. If any other sdboot installation dir is used, such as /boot/efi or /efi, this obviously creates problems, as the bootloader is unable to access the images during boot.

Solution

To mitigate this issue, the respective pacman hook scripts have to changed to dynamically detect the bootloader installation directory. The scripts are /usr/share/libalpm/scripts/mkinitcpio-install and /usr/share/libalpm/scripts/mkinitcpio-remove. Additionally, to integrate better with multi-boot setups, compliance with the Systemd bootloader specification, specifying that boot files should be installed in EFI/<distro>-<root-uuid>, would be really nice to have. In my case this is /boot/efi/EFI/ManjaroLinux-cb3b0f4f-3639-4b20-9154-f1254bff5fd3.

Patch

To solve this problem, and thus make Manjaro’s sdboot integration more robust, I have changed the mkinitcpio-install, mkinitcpio-remove, alongside with the sdboot entry generator sdboot-manage in this GitHub repo, which could theoretically directly replace the current scripts. As sdboot-manage seems to belongs to the “systemd-boot-manager” repo on Gitlab, I have also created a merge request there to implement the patch.

Testing

To test the patch, I have used the install.sh script also located in my GitHub repo to install a custom hook to /etc/pacman.d/hooks to overwrite the system hooks, which appears to work flawlessly. However, this is only test for systemd-boot. I don’t use other bootloaders such as Grub, and thus haven’t tested the patch on them, as they also need to be able to pick-up the new installation location of the images.