Skip to content

Unlock LUKS Automatically with TPM 2.0 on Fedora

Step-by-step guide for configuring automatic LUKS2 root volume decryption using hardware TPM 2.0 and systemd-cryptenroll.

Tested on: Fedora 44 KDE Plasma

Before you start

  • Your passphrase stays. The TPM is added as an extra key slot; your existing LUKS passphrase keeps working and is the fallback whenever the TPM refuses to unlock.
  • Expect to need it. The binding uses PCR 7 (Secure Boot state), so turning Secure Boot off, enrolling new keys, or some firmware updates will make the TPM refuse, and you'll be asked for the passphrase. Make sure you know it before starting.
  • Optional recovery key: sudo systemd-cryptenroll --recovery-key /dev/<YOUR_PARTITION> prints a key you can store offline (password manager, paper).

1. Install Dependencies

Install the required packages to interact with the TPM 2.0 chip using systemd-cryptenroll.

Command:

sudo dnf install tpm2-tss tpm2-tools

Example Output:

Dependencies resolved.
================================================================================
 Package             Architecture   Version              Repository        Size
================================================================================
Installing:
 tpm2-tools          x86_64         5.5-1.fc44           fedora           1.2 M
 tpm2-tss            x86_64         4.0.1-3.fc44         fedora           1.5 M

Transaction Summary
================================================================================
Install  2 Packages
...
Complete!

2. Configure Dracut for Early Boot

The initramfs must load the TPM modules before attempting to mount the encrypted root filesystem. Create the required configuration file.

Command:

echo 'add_dracutmodules+=" tpm2-tss "' | sudo tee /etc/dracut.conf.d/tpm2.conf

Full File Content (/etc/dracut.conf.d/tpm2.conf):

add_dracutmodules+=" tpm2-tss "

3. Identify Your LUKS Device Partition

Find the exact partition containing your encrypted volume.

Command:

lsblk -f

4. Enroll the TPM into the LUKS Volume

Bind the unlock process to PCR 7, which ensures the drive only unlocks if the Secure Boot state remains untampered. Replace /dev/<YOUR_PARTITION> with the specific partition identified in the previous step.

Command:

sudo systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/<YOUR_PARTITION>

Example Output:

New TPM2 token enrolled as key slot 1.

(You can verify the enrollment with sudo systemd-cryptenroll /dev/<YOUR_PARTITION>, which will show the new tpm2 keyslot alongside your existing password slot.)

5. Update Crypttab

Modify your configuration to instruct the system to use the TPM during boot by adding the tpm2-device=auto option. Replace <YOUR-UUID> with the exact UUID of your LUKS partition.

Command:

sudo nano /etc/crypttab

Full Updated File Template (/etc/crypttab):

luks-<YOUR-UUID> UUID=<YOUR-UUID> none discard,tpm2-device=auto

Keep each entry on one line: crypttab has no line continuation, so an entry split with \ will fail to unlock at boot. The four columns are the mapped name, the device, the key file (none = ask for the passphrase or use the TPM), and the options.

6. Rebuild Initramfs and Reboot

Apply the changes to the boot image and restart the machine to verify the configuration.

Commands:

sudo dracut -f --regenerate-all
sudo reboot

Example Output (dracut):

dracut: Executing: /usr/bin/dracut -f --regenerate-all
dracut: *** Including module: tpm2-tss ***
dracut: *** Including module: crypt ***
dracut: *** Creating image file '/boot/initramfs-6.9.X-XXX.fc44.x86_64.img' ***
dracut: *** Creating initramfs image file '/boot/initramfs-6.9.X-XXX.fc44.x86_64.img' done ***

Undo: go back to passphrase-only unlock

  1. Remove the TPM key slot (the passphrase slot is untouched):
sudo systemd-cryptenroll --wipe-slot=tpm2 /dev/<YOUR_PARTITION>
  1. Edit /etc/crypttab (sudo nano /etc/crypttab) and remove tpm2-device=auto from the options column, keeping the line otherwise as it was.
  2. Remove the dracut setting and rebuild the boot images:
sudo rm /etc/dracut.conf.d/tpm2.conf
sudo dracut -f --regenerate-all
sudo reboot

Sources & Verification:

  • ArchWiki: Systemd-cryptenroll and TPM 2.0 configuration
  • Freedesktop.org Manual: crypttab(5) syntax for tpm2-device
  • Fedora Magazine: Native LUKS decoupling and TPM integration documentation