Skip to content

R1DEN/ubuntu-luks-tpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Ubuntu 24.04 LTS: TPM2 LUKS Auto-Unlock Guide

A complete guide for setting up automatic LUKS disk decryption using TPM2 on Ubuntu 24.04 LTS, without requiring a password prompt at boot.

Overview

This guide documents the process of configuring TPM2-based automatic LUKS decryption on Ubuntu 24.04 LTS. Unlike Fedora or Arch Linux where this works out-of-the-box, Ubuntu requires additional configuration due to its use of initramfs-tools instead of dracut, and a missing tss user in the initramfs.

Why Is This So Complicated on Ubuntu?

  1. Ubuntu's initramfs-tools doesn't support systemd-cryptsetup — The tpm2-device=auto option in /etc/crypttab is a systemd-cryptsetup feature, but Ubuntu's initramfs uses traditional cryptsetup scripts.

  2. Security stance — Ubuntu developers have intentionally held back TPM auto-unlock support, arguing that without signed initramfs/UKI, it provides less security than passphrase-based encryption.

  3. Missing tss user bug — The clevis-initramfs package doesn't include the tss user/group needed for TPM2 access in the initramfs.

  4. Experimental official support — Ubuntu 23.10+ has an experimental Snap-based TPM encryption option in the installer, but it's a completely different architecture and marked as experimental.

Prerequisites

  • Ubuntu 24.04 LTS with LUKS-encrypted root partition
  • TPM 2.0 chip (Intel PTT, AMD fTPM, or discrete TPM)
  • Secure Boot enabled
  • Existing LUKS passphrase (will be kept as backup)

Verification Commands

Before starting, verify your system meets the requirements:

# Check TPM version (should show "2")
cat /sys/class/tpm/tpm0/tpm_version_major

# Verify TPM devices exist
ls -la /dev/tpm*

# Check Secure Boot status
mokutil --sb-state

# Identify your LUKS device
lsblk -o NAME,FSTYPE,TYPE,MOUNTPOINT | grep -E "crypt|luks"

# Get LUKS device details
cryptsetup luksDump /dev/nvme0n1p3  # Adjust device path as needed

Installation

Step 1: Install Clevis and TPM2 Tools

sudo apt install -y clevis clevis-luks clevis-tpm2 clevis-initramfs tpm2-tools

Verify installation:

dpkg -l | grep clevis

Step 2: Bind LUKS to TPM2

This creates a new LUKS keyslot bound to your TPM's PCR 7 (Secure Boot policy):

sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_ids":"7","pcr_bank":"sha256"}'

You'll be prompted for your existing LUKS passphrase.

Verify the binding:

sudo clevis luks list -d /dev/nvme0n1p3

Expected output:

1: tpm2 '{"hash":"sha256","key":"ecc","pcr_bank":"sha256","pcr_ids":"7"}'

Step 3: Fix Missing tss User (Critical Step)

This is the key fix that most guides miss. The clevis-initramfs package doesn't add the tss user to the initramfs, which causes TPM2 tools to fail during early boot.

Option A: Clone and install

git clone https://github.com/R1DEN/ubuntu-luks-tpm.git
sudo cp ubuntu-luks-tpm/hooks/tss-user /etc/initramfs-tools/hooks/
sudo chmod +x /etc/initramfs-tools/hooks/tss-user

Option B: Direct download

sudo curl -o /etc/initramfs-tools/hooks/tss-user https://raw.githubusercontent.com/R1DEN/ubuntu-luks-tpm/master/hooks/tss-user
sudo chmod +x /etc/initramfs-tools/hooks/tss-user

Step 4: Rebuild Initramfs

sudo update-initramfs -u -k all

Step 5: Verify Initramfs Contents

Confirm the tss user and clevis tools are included:

# Check for tss user
cd /tmp && rm -rf initrd_check && mkdir initrd_check && cd initrd_check
unmkinitramfs /boot/initrd.img-$(uname -r) .
grep tss main/etc/passwd main/etc/group

# Check for clevis and TPM2 tools
lsinitramfs /boot/initrd.img-$(uname -r) | grep -E "clevis|tpm2"

Expected output should show:

  • tss user in passwd and group
  • clevis-decrypt-tpm2 and various tpm2_* binaries

Step 6: Reboot and Test

sudo reboot

The system should now boot directly to the login screen without prompting for the LUKS passphrase.

Final Configuration Summary

After successful setup, your configuration should look like:

Component Status
Keyslot 0 Passphrase (backup)
Keyslot 1 Clevis TPM2
/etc/crypttab Standard entry, no special options needed
Custom hook /etc/initramfs-tools/hooks/tss-user

Verify with:

sudo cryptsetup luksDump /dev/nvme0n1p3 | grep -E "^  [0-9]+:|^Tokens:|clevis"

Troubleshooting

Boot Still Prompts for Password

  1. Check boot logs:

    journalctl -b | grep -iE "clevis|tpm|crypt" | head -50
  2. Verify tss user is in initramfs:

    lsinitramfs /boot/initrd.img-$(uname -r) | xargs -I{} echo {} | grep passwd
    # Then extract and check the actual passwd file
  3. Test clevis unlock manually (from live USB or recovery):

    sudo clevis luks unlock -d /dev/nvme0n1p3 -n test

TPM Device Busy Error

If you see errors about /dev/tpm0 being busy, the tpm2-abrmd service might conflict. This usually doesn't affect boot unlock but can be checked:

journalctl -b | grep tpm2-abrmd

PCR Values Changed (After BIOS Update)

If the TPM refuses to unlock after a BIOS/firmware update, the PCR values have changed. Re-bind clevis:

# Remove old binding
sudo clevis luks unbind -d /dev/nvme0n1p3 -s 1

# Re-bind with current PCR values
sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_ids":"7","pcr_bank":"sha256"}'

# Rebuild initramfs
sudo update-initramfs -u -k all

Or use the regenerate command:

sudo clevis luks regen -d /dev/nvme0n1p3 -s 1

Security Considerations

What PCR 7 Measures

PCR 7 contains measurements of the Secure Boot policy. This means:

  • ✅ Stable across kernel updates
  • ✅ Stable across initramfs rebuilds
  • ⚠️ Changes if Secure Boot keys are modified
  • ⚠️ Changes if UEFI firmware is updated (sometimes)

Alternative PCR Combinations

For stricter security (but more frequent re-enrollment):

# PCR 0 + 7: Firmware + Secure Boot (breaks on BIOS updates)
sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_ids":"0,7","pcr_bank":"sha256"}'

# PCR 1 + 7: Hardware config + Secure Boot
sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_ids":"1,7","pcr_bank":"sha256"}'

Backup Passphrase

Always keep your passphrase keyslot (slot 0) intact. This is your recovery method if:

  • TPM fails
  • You need to access the disk from another machine
  • PCR values change unexpectedly

Maintenance

After Kernel Updates

No action needed — clevis and the tss-user hook are automatically included when initramfs is rebuilt.

After BIOS/Firmware Updates

May require re-binding clevis if PCR values change. You'll know because the system will fall back to password prompt.

Removing TPM Auto-Unlock

# Remove clevis binding
sudo clevis luks unbind -d /dev/nvme0n1p3 -s 1

# Remove custom hook
sudo rm /etc/initramfs-tools/hooks/tss-user

# Rebuild initramfs
sudo update-initramfs -u -k all

Why Not systemd-cryptenroll?

Ubuntu 24.04's initramfs-tools doesn't support systemd-cryptsetup, which is required to use keys enrolled via systemd-cryptenroll. While you can enroll a TPM key with:

systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/nvme0n1p3

And add tpm2-device=auto to /etc/crypttab, the initramfs will show:

cryptsetup: WARNING: dm_crypt-0: ignoring unknown option 'tpm2-device'

This is because Ubuntu's cryptroot scripts don't understand systemd-cryptsetup options. Solutions:

  1. Use Clevis (this guide)
  2. Replace initramfs-tools with Dracut (more invasive)
  3. Wait for Ubuntu to adopt UKI/systemd-boot natively

References


Document created: December 2024 Tested on: Ubuntu 24.04.3 LTS with kernel 6.14.0-37-generic Hardware: TPM 2.0 (tpm_crb driver)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages