Coupled with LUKS, secureboot and uki have the potential to protect us from some physical attack vectors. I have concluded that using Secureboot, UKI, and signed initrds is viable under linux distros but there are too many fragile parts. Installs don't support this out of the box. The setup has to be hacked into the system after and it often breaks on system updates.
Having said that I was finally able to get a signed UKI working on ubuntu 26.10. I then deleted the unencrypted boot partition. Since my UEFI is protected including the jumper reset in the hardware this is probably the maximum I can protect the system from physical attack.
Ubuntu 26.10 is trying a new feature in a radical way that is using Secure boot to launch grub which launches UKI after confirming signatures using the TPM. They attempt to launch the primary and fallback to a secondary. UEFI cannot do this which is why they attempt it this way. Unfortunately, it is a very fragile setup and almost no one can get it to work. I have tried multiple times on the newest hardware I have.
26.10 release article mentions widening support for systems without compatible hardware for secure boot and full disk encryption.
in short. this does not work. see my Ubuntu page for details.
after the failed tpm unlock a passphrase prompt is shown. the recovery key that the installer shows will open but its a guid and takes a long time to type. After the system starts up I tried to add another passphrase so I could type less and fix the system with other boot options. multiple attempts fail there too. cryptsetup refuses to treat the recovery key as a passphrase which is odd since it works for boot.
I installed without the hardware option and add tried to add the tpm unlock after the fact. I have never gotten stock tpm+luks integration to work. not with initframfstools-not with dracut-not with clevis. It seems that ubuntu has moved to dracut after all. I found a post on debian forums saying ubuntu wanted to stick with initramfs-tools but guess not.
i suspect ubuntu still isn't including the features needed in the initrd. I'll try to get dracut working before going bakc to my initramfs fix.
We can create our own UKI and configure UEFI to boot it. If we also sign it and register the key in Secure Boot the system will boot securely.
DEV=/dev/nvmen0p1
UKILABEL="Ubuntu UKI Test"
UKIPATH="\EFI\ubuntu\ubuntu-latest.efi"
MY_UUID=$(findmnt -n -o UUID /)
INITRD=$(realpath /boot/initrd.img)
KERNEL=$(realpath /boot/vmlinuz)
sudo -E ukify build \
--linux="$KERNEL" \
--initrd="$INITRD" \
--cmdline="root=UUID=$MY_UUID ro quiet splash" \
--os-release=@/etc/os-release \
--output=/boot/efi/EFI/Linux/ubuntu-latest.efi
sudo efibootmgr -c -d $DEV -p 1 -L $UKILABEL -l $UKIPATH
Tried this a few times. the first time was a disaster. after booting the uki with secure boot off I set UEFI into Setup mode and boot back into Linux. Next I enroll which creates key and registers the uki with UEFI.
sudo mkdir -p /var/lib/systemd/pubkey/
cd /var/lib/systemd/pubkey/
EFIPATH=/boot/efi/EFI/ubuntu
STAMP="linuxuki-"$(/bin/date -u +"%Y%m%dT%H%M%S")".efi"
sudo /usr/lib/systemd/ukify build \
--linux=/boot/vmlinuz-$(uname -r) \
--initrd=/boot/initrd.img-$(uname -r) \
--secureboot-private-key=/var/lib/systemd/pubkey/secure-boot.key \
--secureboot-certificate=/var/lib/systemd/pubkey/secure-boot.crt \
--output="$EFIPATH/$STAMP"
echo "secure-boot-enroll force" | sudo tee -a /boot/efi/loader/loader.conf
sudo efibootmgr -c -d /dev/nvme0n1 -p 1 -L "$STAMP" -l "$EFIPATH/$STAMP"
reboot and reset to setup mode (again?). Next turn on secure boot. the sysetm should register the private keys with secure boot.....well it said it did that but fails to boot. furthermore it tries to register multiple times and since I wiped the original keys and setup ubuntu isn't happy either. I disable secure boot but the boot process is so trashed it cannot work.
After factory resetting I started over and was finally able to get a self signed UKI to work with Secure Boot. I have a script for it now that does most of it. After running the script the MOK.CER file has to be registered in UEFI. I copy the cer file to the same folder as the UKI which should be available to any UEFI process since it has to reach the uki file in the same location.
The script does not generate keys for you. here are the settings in the script
KVER="${1:-$(uname -r)}"
KEY="/root/secureboot-keys/MOK.key"
CERT="/root/secureboot-keys/MOK.crt"
CERT_DER="/root/secureboot-keys/MOK.cer"
create key and cert in these locations. a future version of the script may allow parameters.
sudo openssl req -newkey rsa:2048 -nodes -keyout /root/secureboot-keys/MOK.key \
-new -x509 -sha256 -days 3650 \
-subj "/CN=Custom UKI Signing Key/" \
-out /root/secureboot-keys/MOK.crt
sudo openssl x509 -outform DER -in /root/secureboot-keys/MOK.crt -out /root/secureboot-keys/MOK.cer
the private key is stored in /root home folder. as long as this is inside the encrypted partition it is safe.
since we now boot from uki we dont need the decrypted boot partition. I deleted it using a custom script, then rebooted and verified that the boot partition is no longer mounted. since the installer created p1 efi and p2 boot next to each i reclaim the space from former boot partition into the efi partition.
unmount /boot/efi
delete old boot partition
resize efi partition into empty space
mount /boot/efi
when the kernel updates i'll need to make sure a new uki is created and signed.
sudo apt install tpm2-toolslibtss2-esys
sudo cp /etc/crypttab /etc/crypttab.bak
sudo sed -i -E 's/^([[:space:]]*[^#[:space:]]+[[:space:]]+[^[:space:]]+[[:space:]]+[^[:space:]]+[[:space:]]+)none([[:space:]]*)$/\1luks,tpm2-device=auto\2/' /etc/crypttab
sudo cp /boot/initrd.img-$(uname -r) /boot/initrd.img-$(uname -r).bak
sudo dracut -f --kver $(uname -r)
now i need to build another uki and sign it.
sudo dnf install systemd-ukify binutils openssl mokutil sbverify
create keys
sudo mkdir -p /etc/kernel/certs
sudo openssl req -new -x509 -newkey rsa:2048 -nodes -days 3650 -keyout /etc/kernel/certs/secure-boot.key.pem -out /etc/kernel/certs/secure-boot.cert.pem -subj "/CN=My-Local-UKI-Key/"
enroll key. note that this requires the key to be in x509 format but the sbverify and uki genertion wants a different format (pem). you may need to keep two formats for the same cert.
sudo mokutil --import /etc/kernel/certs/secure-boot.cert.pem
note that a factory reset may not remove this key from UEFI. the key still shows up after a factory reset when I try to enroll it again.
We have to configure the system to generate the uki images and boot them
echo -e "layout=uki\nuki_generator=ukify" | sudo tee /etc/kernel/install.conf
echo -e "[UKI]\nSecureBootPrivateKey=/etc/kernel/certs/secure-boot.key.pem\nSecureBootCertificate=/etc/kernel/certs/secure-boot.cert.pem" | sudo tee /etc/kernel/uki.conf
now generate the first uki maually since we are not installing new kernels right now which is what triggers this. This command requires pem formatted cert to be configured--even if the mok enroll required the other format.
sudo kernel-install add $(uname -r) /lib/modules/$(uname -r)/vmlinuz
once that works we need to add the kernel to nvram. are we going to have to do this manually every time a new kernel is built? and manually remove old ones?
# Example: --disk /dev/nvme0n1 --part 1 --loader "\\EFI\\Linux\\your-kernel.efi"
sudo su
DEV=/dev/nvme0n1
PART_NUMBER=6
DISK=${DEV}p${PART_NUMBER}
UKI=$(ls -t /boot/efi/EFI/Linux/*.efi | sed 's|/boot/efi||' | head -n1 |sed 's|/|\\|g' )
efibootmgr --create --disk $DEV --part $PART_NUMBER --label "Fedora UKI" --loader "$UKI"
after a kernel update fedora is trashed. It boots but can't load services related to the drives during systemd stupid boot process. Since the system is now bricked I have to start over again.