Ubuntu Version:
24.04 Server
Desktop Environment (if applicable):
NA
Problem Description:
I’m trying to add TPM2/LUKS support via autoinstall
How to get a clean working install of ubuntu server via autoinstall.yaml with TPM2 support for the LUKS partition automatic decryption?
For clarity, I started of with a fully working autoinstall, and i’m trying to add an encrypted disk with a password in the autoinstall, this works for the creation of the partition and every following reboot the password is required to continue booting. So far so good.
Now the goal is to have the system boot automatic with a password that is stored in the TPM. Via some workaround for initramfs and missing TPM support, I install dracut and tpm2tools so I can get the system to boot. This works except on the very first boot when it switches from “live cd” to the actual host. In itself this is explained because I have the workaround in the cloudinit/user-data phase of the autoinstall (and at the time of switching from live cd to host we haven’t reached this part of autoinstall yet). If i try to do the same things in the “late-commands” section with all the same commands (adapted for ‘/target’ directory change) it fails. i’ve tried using the ‘curtain in-target - - …’ approach but to no avail.
Can someone point me in the right direction for how to continue?
Side question: Would waiting a couple of months for ubuntu server 26.xx make a difference here?
Please find all commands below :
storage section of autoinstall.yaml (working)
storage:
layout:
name: lvm
password: testing123
user-data:
runcmd:
#LUKS
- apt install -y dracut tpm2-tools
- systemd-cryptenroll --wipe-slot=tpm2
- systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 --unlock-key-file=/opt/luks.key /dev/nvme0n1p3
- sed -i 's/luks/luks,tpm2-device=auto/' /etc/crypttab
- echo 'hostonly="yes"' > /etc/dracut.conf.d/tpm2.conf
- echo 'add_dracutmodules=" tpm2-tss "' >> /etc/dracut.conf.d/tpm2.conf
- dpkg-reconfigure linux-image-$(uname -r)
fyi: /opt/luks.key contains the correct key (‘testing123‘)
Not working solution:
late-commands:
- curtin in-target -- apt install -y dracut tpm2-tools
- curtin in-target -- 'systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 --unlock-key-file=/opt/luks.key /dev/nvme0n1p3'
- sed -i 's/luks/luks,tpm2-device=auto/' /target/etc/crypttab
- echo 'hostonly="yes"' > /target/etc/dracut.conf.d/tpm2.conf
- echo 'add_dracutmodules=" tpm2-tss "' >> /taget/etc/dracut.conf.d/tpm2.conf
- curtin in-target -- dpkg-reconfigure linux-image-$(uname -r)
This ends up in the emergency shell.