Lazy UEFI multiboot for Slackware Linux and OpenBSD

       1251 words, 6 minutes

For reasons, I have a laptop running both Slackware Linux or OpenBSD. To have both available, I split the storage space in two and installed both systems. But if mainstream Linux distros use GRUB, Slackware has an historical love for LILO; and elilo when it comes to EFI-based computers.

When you run eliloconfig on a Slackware instance, it doesn’t identify anything else than the Linux kernel. And OpenBSD doesn’t care about integrating another kernel in its own bootloader. Unless I’m mistaken…

Fortunately, UEFI comes with a way to select an operating system loader. More information about UEFI on the Wikipedia dedicated page . And I’m gonna use this lazy smart feature to switch between booting Slackware Linux and OpenBSD.

Split the storage

There are probably thousands of ways of doing this but I did split my laptop storage using the cfdisk tool that comes with the Slackware installation media.

# cfdisk -z /dev/nvme0n1
(...)
Select label type: gpt
(...)

I created an EFI partition, a Linux partition, an OpenBSD partition and a spare vFAT partition to exchange data from one OS to the other.

# fdisk -l /dev/nvme0n1
Disk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: WD_BLACK SN770 2TB
(...)
Device              Start        End    Sectors  Size Type
/dev/nvme0n1p1       2048    2099199    2097152    1G EFI System
/dev/nvme0n1p2    2099200 1920993279 1918894080  915G Linux LVM
/dev/nvme0n1p3 1920993280 3839887359 1918894080  915G OpenBSD data
/dev/nvme0n1p4 3839887360 3907029134   67141775   32G Microsoft basic data

The EFI partition is quite big. But I wanted to avoid any “Disk Full” issue when a new Linux kernel would be installed. This is because elilo installs a copy of the kernel and the initrd image in the EFI Partition. After every installations are done, I could see that the OpenBSD EFI directory uses 152KB and the Slackware EFI directory uses 20.1MB. So 1GB is way enough…

The Linux partition type was set to Linux LVM. I’m using (near) Full Disk Encryption using LUKS and LVM. This way, only the kernel is left unencrypted at rest on the EFI Partition.
This is way more difficult to achieve using GRUB with Slackware - see an example here .
Also, regarding the “bla bla kernel insecurely stored”, I don’t care! If the laptop gets stolen, my data are safe. And if it is ever restored to me with a keyloader installed on the EFI partition, I don’t care; I would restore the official BIOS and wipe the whole disk before reinstalling from scratch and restore from trusted backup.

The OpenBSD partition is known as OpenBSD data using cfdisk.
This may vary depending on the tool you use for partitioning.
From the OpenBSD fdisk utility, the partition type appears as “A6”.

The exchange partition is set to type Microsoft basic data. Because there were no better type in the list. It is formatted using the mkfs.vfat utility; same as EFI System. The reason I’m using it is because:

Yes, USB keys exist. But I won’t need any this way :)

Format the EFI partition

The EFI System partition should be formatted using FAT32 for maximum compatibility. On my NVMe storage, using Slackware 15.0 installation media, this goes like this:

# mkfs.vfat /dev/nvme0n1p1

Slackware Linux installation

I am using LUKS to encrypt my disk and LVM to organise my Linux partitions. Read the documentation (README_CRYPT.TXT, README_LVM.TXT) for more details. I went to encrypt the Linux partition, enable LVM and create volumes for root, swap and home. The swap volume is big enough to enable hibernation.

# cryptsetup -y luksFormat /dev/nvme0n1p2

# cryptsetup luksOpen /dev/nvme0n1p2 tatooine

# vgcreate slacker /dev/mapper/tatooine

# lvcreate -L 24G -n swap slacker
# lvcreate -L 128G -n root slacker
# lvcreate -l 100%FREE -n home slacker

Then Slackware installation goes as usual.

# mkswap /dev/slacker/swap
# setup

Not sure why, but the installer wants to mount the USB key EFI partition instead of the one on my internal drive. So I have to manually correct this. When the “Source Media Selection” screen appears, I pause it and switch to a console. Spell a few magic commands and go back to installation.

^Z
# umount /mnt/boot/efi
# mount /dev/nvme0n1p1 /mnt/boot/efi
# fg

When the installer offers to “Make USB Flash Boot”, I answer “Skip”.
When the installer detects UEFI, it offers to “Skip installing LILO and proceed to ELILO installation”. I’m “OK” with this.
When the installer offers to “Install ELILO on the EFI System Partition”, I answer “OK”. Then proceed and acknowledge all choices that the installer proposes.

When offered, set the hardware clock to UTC. This will make both Slackware Linux and OpenBSD agree on the current time when switching from one OS to the other.

When the “System configuration and installation is complete”, I select the “EXIT” option, remove the USB key from the laptop and select the “Shell” option. There are things to do to be able to boot from FDE: create an initrd image with LUKS and LVM modules, set the hibernation device and add modules for my (French) USB keyboard.

# chroot /mnt
# $(/usr/share/mkinitrd/mkinitrd_command_generator.sh -i -r)
# cp -p /boot/initrd.gz /boot/efi/EFI/Slackware/initrd.gz
# exit

# reboot

From there, Slackware Linux may boot and be useable.

OpenBSD installation

Boot an OpenBSD installation media and proceed as usual; mostly.

When the disk selection occurs, select the partitioned disk. Enter ‘p’ to encrypt the disk and select the (O)penBSD area.

Available disks are: sd0 sd1 sd2.
Which disk is the root disk? ('?' for details) [sd0] <ENTER>
Encrypt the root disk with a (p)assphrase or (k)eydisk? [no] p<ENTER>

Configuring the crypto chunk sd0...

Disk: sd0    Usable LBA: 2048 to 3907029134 [3907029168 Sectors]
   #: type                         [       start:         size ]
----------------------------------------------------------------
   0: EFI Sys                      [        2048:      2097152 ]
   1: Linux LVM                    [     2099200:   1918894080 ]
   2: OpenBSD                      [  1920993280:   1918894080 ]
   3: Microsoft basic data         [  3839887360:     67141775 ]

Use (W)hole disk MBR, whole disk (G)PT, (O)penBSD area or (E)dit? [OpenBSD] <ENTER>
New passphrase:

Finish the installation and reboot.

Manual Operating System Loader installation

I’m not sure why, but the installer didn’t properly register the OpenBSD bootloader. It was not available in the UEFI Boot Menu. I could hopefully still boot to Slackware and correct this. From Linux, install the EFI Boot manager, download the OpenBSD loader and enable it.

# sbpkg -i efiboots

# mkdir /boot/efi/EFI/OpenBSD
# wget -O /boot/efi/EFI/OpenBSD/BOOTX64.EFI \
  https://cdn.openbsd.org/pub/OpenBSD/7.6/amd64/BOOTX64.EFI

Run the EFI boot manager. Click the “+” button, fill-in the parameters and validate.

Click the ‘save" button and confirm that you want to continue.
An OpenBSD entry should now appear as active in the list.

Reboot the computer.

Hit the relevant key that triggers “Entering the Boot Menu…”.
On my ThinkPad, it is “F12”. Select which OS you like to boot.

So far, I could switch between OpenBSD and Linux using only the UEFI Boot Menu. That configuration survived both a Slackware and OpenBSD system updates so it should be safe… maybe :D

From the BIOS boot configuration, it is possible to set a default choice for booting. This OS will be booted if no key are pressed when the computer is turned on. It is also possible to change the boot order using the EFI boot manager tool. There may be an option in OpenBSD’s ports but I haven’t looked for.

As usual, don’t held me responsible if your wreck your computer. Until then, that’s all folks!