techduck blog

smarthome, electronics, privacy


My linux multiboot setup with systemd-boot

Published: | Edited:

I wanted to learn more about the linux boot process and create a multiboot setup on my notebook. In the end, I threw away GRUB and replaced it with systemd-boot. My main system is KDE neon and the second is Arch linux.

The partitioning and LVM scheme

Output of 'lsblk':

user@notebook:~$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
[...]
nvme0n1     259:0    0 953,9G  0 disk 
├─nvme0n1p1 259:1    0     1G  0 part /boot
├─nvme0n1p2 259:2    0     4G  0 part [SWAP]
└─nvme0n1p3 259:3    0 948,9G  0 part 
  ├─vg-kde  252:0    0   256G  0 lvm  /
  └─vg-arch 252:1    0   256G  0 lvm 

The LVM setup:

user@notebook:~$ sudo pvs
  PV             VG Fmt  Attr PSize    PFree   
  /dev/nvme0n1p3 vg lvm2 a--  <948,87g <436,87g
user@notebook:~$ sudo vgs
  VG #PV #LV #SN Attr   VSize    VFree   
  vg   1   2   0 wz--n- <948,87g <436,87g
user@notebook:~$ sudo lvs
  LV   VG Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  arch vg -wi-a----- 256,00g                                                    
  kde  vg -wi-ao---- 256,00g                                                    
user@notebook:~$ 

I have created a joint boot partition, a joint swap partition and one main partition with logical volumes for each linux distribution. I am not sure if this is the best scheme, but it works for me. Please let me know if there is a better alternative.

The boot directory and systemd-boot

Please read how to install and use systemd-boot here: systemd-boot article in Arch wiki.

Important hint from article above:

“Installing systemd-boot will overwrite any existing esp/EFI/BOOT/BOOTX64.EFI (or esp/EFI/BOOT/BOOTIA32.EFI on IA32 UEFI), e.g. Microsoft’s version of the file.”

So if you installed GRUB bevor, it will be overwritten!

That the 'tree' of my boot directory:

user@notebook:~$ tree /boot/
/boot/
├── EFI
│   ├── BOOT
│   │   └── BOOTX64.EFI
│   ├── Linux
│   └── systemd
│       └── systemd-bootx64.efi
├── images
│   ├── arch
│   │   ├── initramfs-arch.img
│   │   └── vmlinuz-arch
│   └── kde
│       ├── initramfs-kde.img
│       └── vmlinuz-kde
└── loader
    ├── entries
    │   ├── arch.conf
    │   └── kde.conf
    ├── entries.srel
    ├── loader.conf
    └── random-seed

Content of 'loader.conf':

timeout 0
#console-mode keep
default kde.conf

This boots my KDE Neon by default and without a timeout. So there is no splash screen to select a distribution. You have to press “ESC” after the UEFI screen to display the systemd-boot screen.

Content of 'kde.conf':

title   KDE Neon
linux   /images/kde/vmlinuz-kde
initrd  /images/kde/initramfs-kde.img
options root=UUID=7550e7cb-f34f-4bf7-9af5-0cd672dcb8bc rw

As you can see, I have created a separate directory for each distribution in which I can store my kernel and ramdisk images. However, this has two problems:

  1. Ubuntu (KDE neon) and Arch linux store the kernel and the ramdisk in the directory /boot/ by default.
  2. The kernel has its own naming scheme for each distribution and systemd-boot does not support wildcards.

Therefore, we have to automatically move and rename our kernel and ramdisk after each update.

Automatically rename kernel image and move it to specific directory unter /boot/

Ubuntu

My files content:

#!/bin/bash
rm /boot/images/kde/*
mv /boot/vmlinuz-*-generic /boot/images/kde/vmlinuz-kde
mv /boot/initrd.img-*-generic /boot/images/kde/initramfs-kde.img
find /boot/ -maxdepth 1 -type f -exec mv {} /boot/images/kde/ \;
exit 0

This copies my main kernel and ramdisk image to the '/boot/images/kde/' directory and renames it to the static name configured in the 'kde.conf' file. It also copies the other files that are generated with kernel update (e.g. ram check).

The script requires the same authorizations as the others and it must be made executable.

Arch

You only need to edit the '/mnt/etc/mkinitcpio.d/linux.preset' file.

My files content:

# mkinitcpio preset file for the 'linux' package

#ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/images/arch/vmlinuz-arch"

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
default_image="/boot/images/arch/initramfs-arch.img"
#default_uki="/efi/EFI/Linux/arch-linux.efi"
#default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"

[...]

This will also copy and rename the images to the right directory.

Disclaimer

Thats the way i have created my linux multiboot setup. I can not guarantee that all steps are best practice and without mistakes. I am still learning linux and only want so share my finding with you.

Edit this Article.