Hidden Wonders

Technology·Tutorial

Setting Up Systemd-Boot on Arch Linux



Published:

Table of Contents

Introduction[#]


This is a guide on how to setup systemd-boot on Arch Linux. Most of this information is in the linked Arch Linux wiki page, but I keep making mistakes the two times I’ve had to set it up so I thought I’d compile my thoughts here for setting it up. If using this guide in the distant future, make sure to reference the wiki page for any changes to the setup process that may have occurred.

One thing I just got working that I thought was cool was the ability to get an entry to boot my Windows partition that was in a separate EFI partition, which systemd-boot isn’t supposed to support.

1) Gather system information.[#]


Systemd-boot only supports UEFI systems, so make sure the following directory exists:

/sys/firmware/efi/efivars

Then, you need to identify your ESP mountpoint. You can do this with the command lsblk:

[hiddenwonders@xyz ~]$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
nvme1n1     259:0    0   1.8T  0 disk 
├─nvme1n1p1 259:1    0     1G  0 part /boot
└─nvme1n1p2 259:2    0   1.8T  0 part /
nvme0n1     259:3    0 465.8G  0 disk 
├─nvme0n1p1 259:4    0   100M  0 part 
├─nvme0n1p2 259:5    0    16M  0 part 
├─nvme0n1p3 259:6    0 465.1G  0 part 
└─nvme0n1p4 259:7    0   509M  0 part

On my system I have two SSDs, one with Windows 10 & another with Arch Linux. Looking at the mountpoints tab, the ESP mountpoint should be the partition mounted at either /boot or /efi. Mine is mounted at /boot, and is /dev/nvme1n1p1. (I use a swapfile if wondering why I only have two partitions). The ESP mountpoint should be formatted as FAT32 if you’re having trouble finding it (filetype can be output by running lsblk -f.

Regarding systemd-boot installation: it ships with systemd, which is required for Arch Linux systems (for better or worse).

2) Install systemd-boot to your EFI partition.[#]


bootctl install

That creates some boot image files. You may also want to do this to reinstall the boot image on each update of systemd.

Now we need to configure systemd-boot.

3) Setup loader.conf[#]


Create file at /boot/loader/loader.conf:

default @saved
timeout 2
console-mode max
editor no

See loader.conf(5).

This controls options for the loader menu that appears. The default line sets the last selected entry in the menu as default next time you boot. You can also set it to one of the configuration files that get made in the next step.

The timeout option controls how long the menu pops up for. I have it set to 2 seconds, “If you have set timeout 0, the boot menu can be accessed by pressing Space.”

4) Setup loader files[#]


There’s a directory, /boot/loader/entries/, where configuration files reside that specify another boot image option for systemd-boot. Without these, systemd-boot displays no options in the boot menu. Here’s an example:

title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw

The line with all the X’s can be acquired by running lsblk -f. In this case we want the UUID of the root partition, so in my case that’s the UUID of the disk /dev/nvme1n1p2.

The lines containing the linux and initrd parameters are paths relative to the root of the EFI directory (hence /vmlinuz-linux rather than /boot/vmlinuz-linux). Note that these filenames will change based on the Linux kernel you’re using: if you’re using the default kernel then everything will be like in the example, however if you’re using the LTS kernel, your filenames will differ:

# For LTS kernel
title Arch Linux
linux /vmlinuz-linux-lts
initrd /initramfs-linux-lts.img
options root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw

Finally, update your config by running bootctl update.

With this step done, you should be able to boot and select the Arch Linux boot options with systemd-boot. Have an Arch Linux USB handy though in case you soft-lock your system though, it’s easy to make a mistake.

5) Setup a UEFI shell boot option.[#]


The final goal of this setup guide will be to boot an OS with a separate EFI partition. An OS like Windows should work with no trouble if it’s located on the same EFI partition, but for a separate EFI partition like I have, the only real way to launch the OS is through the UEFI shell (or you need some strange intermediary XBOOTLDR partition).

First we need to boot into a UEFI shell by installing the edk2-shell package and setting up systemd-boot to find the shell and present it as a boot option.

pacman -S edk2-shell

This installs a file which we can copy onto our EFI partition:

cp /usr/share/edk2-shell/x64/Shell_Full.efi /boot/shellx64.efi

You probably want to run bootctl update again to get the UEFI shell option to appear on your next reboot.

If this doesn’t work, see the wiki page for more options.

Before rebooting into the UEFI shell, run lsblk and take note of the UUID of your Windows parition, which can be found using lsblk -f as was done earlier.

6) Reboot into the UEFI shell.[#]


Reboot your system and the UEFI shell boot option should be present (systemd-boot automatically adds a boot entry if the shellx64.efi file is present). Select it, and you should be dropped into the UEFI shell. Type map, which should present you a mapping of all partitions, including their UUID. Find the FS alias which has the correct UUID and note it’s name (for me, my FS alias was HD0b).

7) Finish configuration[#]


Boot back into Linux and create the following /boot/loader/entries/windows.conf, substituting HD0b to whatever your output was from the UEFI shell:

title Windows 10
efi /shellx64.efi
options -nointerrupt -nomap -noversion HD0b:EFI\Microsoft\Boot\Bootmgfw.efi

See the wiki the details of what those options do.

Run bootctl update and you should then be able to boot Windows by selecting the Windows 10 option on the systemd-boot menu on your next restart.

8) Unmentioned Limitation[#]


I recently found out that this method sometimes doesn’t work. I plugged in an old iPod I found laying around to my computer and this must have changed my FS alias from HD0b to something else because the Windows 10 boot option was no longer working until after I unplugged the iPod. Just something to keep in mind, this method is convienient but not perfect unfortunately.

Conclusion[#]


You should be good to go and will hopefully not have to configure systemd-boot any further after this.

Even though it’s not as straight forward as it could be, I still believe systemd-boot is a bit less error-prone than using GRUB, and since it comes with systemd and you’re stuck with systemd since you’re on Arch Linux, might as well save the extra package install right?

I wish you all a comfy night and a working bootloader.

Home Top


Site Licensing Site last updated: 2024-11-01