Booting Ubuntu with systemd boot instead of GRUB2

After I’ve been playing around with Arch Linux for quite a while I’ve come to really like booting with systemd boot. It’s fast, very simple to maintain and not as finicky to play around with as GRUB2.

So I set myself the challenge of changing my HTPC running Xubuntu from GRUB2 to systemd boot because you can. That is the main reason. Getting rid of the bloated monster that is GRUB2 is actually secondary. Before actually doing it on the HTPC, I decided to do it on a virtual machine just to be sure nothing went wrong.

I found a great guide made by Josh Stoik at Blobfolio.com and decided to give it a go. You really should go read the guide at Blobfolio as it’s very easy to understand.

It was very easy, it might help that I have been playing around with systemd boot before and I really had a hard time believing that it just worked at my first attempt.

Here are my kernel hooks that I stitched together from this github comment and the guide (here I mainly used the idea of using a variable to set the PARTUUID as I don’t use LUKS or any root flags at the moment):

#!/bin/bash
#
# This is a simple custom kernel hook to populate the systemd-boot entries
# whenever kernels are added or removed during an update.
#


# The PARTUUID of your root partition
PARTUUID="INSERTYOURPARTUUIDHERE"

vmlinuz=$(find /boot -maxdepth 1 -name "vmlinuz-*-generic")
version=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | head -n -1)
latest=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | tail -n 1)

echo ">> COPYING ${latest}-generic. LATEST VERSION."

cat << EOF > /boot/efi/loader/entries/ubuntu.conf
title   Ubuntu
linux   /ubuntu/vmlinuz-generic
initrd  /ubuntu/initrd.img-generic
options root=PARTUUID=${PARTUUID} rw
EOF

for file in initrd.img vmlinuz; do
    cp "/boot/${file}-${latest}-generic" "/boot/efi/ubuntu/${file}-generic"
done

for ver in $version; do

    echo ">> COPYING ${ver}-generic."

cat << EOF > /boot/efi/loader/entries/ubuntu-${ver}.conf
title   Ubuntu ${ver}
linux   /ubuntu/vmlinuz-${ver}-generic
initrd  /ubuntu/initrd.img-${ver}-generic
options root=PARTUUID=${PARTUUID} rw
EOF

    for file in initrd.img vmlinuz; do
        cp "/boot/${file}-${ver}-generic" "/boot/efi/ubuntu/${file}-${ver}-generic"
    done
done

As the guide suggests, you should reinstall the kernel to see if the kernel hooks work. To save even more time, don’t fiddle around with copying the kernels manually. Just wait until you’ve created your kernel hooks and then reinstall the latest kernel as it’ll all be done for you with the proper naming and all:

apt install --reinstall linux-image-[VERSION]-generic

That is all it takes and you can then install Systemd boot

If we look at the effect it had a systemd-analyze shows:

unax@cerberus:~$ systemd-analyze 
Startup finished in 4.281s (kernel) + 4.244s (userspace) = 8.525s
graphical.target reached after 4.229s in userspace
unax@cerberus:~$ systemd-analyze 
Startup finished in 361ms (firmware) + 273ms (loader) + 3.277s (kernel) + 2.684s (userspace) = 6.596s
graphical.target reached after 2.676s in userspace

To finish it off here is a neofetch of the system:

           `-/osyhddddhyso/-`              unax@cerberus 
        .+yddddddddddddddddddy+.           --------- 
      :yddddddddddddddddddddddddy:         OS: Ubuntu 18.04.1 LTS x86_64 
    -yddddddddddddddddddddhdddddddy-       Kernel: 4.15.0-45-generic 
   odddddddddddyshdddddddh`dddd+ydddo      Uptime: 31 minutes 
 `yddddddhshdd-   ydddddd+`ddh.:dddddy`    Packages: 1791 (dpkg), 3 (snap) 
 sddddddy   /d.   :dddddd-:dy`-ddddddds    Shell: /bin/bash 4.4.19 
:ddddddds    /+   .dddddd`yy`:ddddddddd:   Resolution: 1920x1080, 1920x1080 
sdddddddd`    .    .-:/+ssdyodddddddddds   DE: Xfce 
ddddddddy                  `:ohddddddddd   CPU: Intel i5-4460 (2) @ 3.198GHz 
dddddddd.                      +dddddddd   CPU Usage: 14% 
sddddddy                        ydddddds   GPU: VMware SVGA II Adapter 
:dddddd+                      .oddddddd:   GPU Driver: vmwgfx, vmwgfx 
 sdddddo                   ./ydddddddds    Memory: 1742MiB / 3921MiB 
 `yddddd.              `:ohddddddddddy`    Disk (/): 9,1G / 39G (25%) 
   oddddh/`      `.:+shdddddddddddddo      
    -ydddddhyssyhdddddddddddddddddy-       
      :yddddddddddddddddddddddddy:
        .+yddddddddddddddddddy+.                                   
           `-/osyhddddhyso/-`

Next up is doing it on the HTPC and maybe a little more about the current setup.