
In recent years, TPM 2.0 modules have gone from being a hardware mystery to a standard component in any modern UEFI-enabled Secure Boot system. This article explains what /dev/tpm0 and /dev/tpmrm0 are and how to use tpm2_pcrread and tpm2_pcrextend (as well as their actual command in tpm2-tools), and how they fit into measured boot, disk encryption, and signed PCR policies in Linux.
Useful documentation exists, but it's scattered among systemd man pages, wiki entries, and very dense posts; here we gather all the key information (PCRs, practical examples, risks and defenses) so that technical people, even if they are not TPM experts, can work with these tools without getting lost in obscure details.
What is a TPM 2.0 and why you might care
A Trusted Platform Module (TPM) is a security chip located on your motherboard (or inside the CPU as an fTPM/Intel PTT) that acts as a secure store, random number generator, and system root of trust. It's passive: if you don't use it, it does nothing . However, when integrated into your boot process and disk encryption, it provides integrity verification and hardware-protected keys.
In practice, a TPM 2.0 allows you two main modes of use in disk encryption: a) generate/store a robust key and protect its use with a PIN with anti-brute force lock; b) activate the so-called measured boot, where each boot component is measured in PCR registers , so that the key is only "decapsulated" if the system has not been altered (and optionally with a pre-boot PIN).
/dev/tpm0 and /dev/tpmrm0: differences and when to use each one
In Linux, you'll see two device names when TPM 2.0 is available. /dev/tpm0 is the "raw" TPM interface , while /dev/tpmrm0 exposes access through the Resource Manager (which handles multiple clients, sessions, and resources), and is recommended by tpm2-tools in most scenarios.
If you're unsure whether a TPM exists, you can check it live. If `/sys/class/tpm/` is empty or the wiki command returns nothing , there's no visible TPM: it may not physically exist or it may be disabled in the firmware.
# ¿Hay TPM 2.0?
ls /sys/class/tpm/
cat /sys/class/tpm/tpm*/tpm_version_major
# Dispositivos
ls -l /dev/tpm*
When both device nodes are present, tpm2-tools will typically detect /dev/tpmrm0 and use it automatically. If you need to force a device, most tools accept `--tcti` or use TCTI environment variables, but this is usually unnecessary for common tasks.
TPM PCRs: How they work and what they measure
Platform Configuration Registers are registers that store hashes (usually SHA-256) of the state of critical components at each boot stage. They are initialized to zero at power-up and can only be extended : never rewritten or deleted (except in debugging cases such as PCR 16).
The fundamental operation is the extension: new_value = SHA256(current_value || SHA256(data)) . This chains measurements without allowing opportunistic resets. This pattern is used to measure firmware, configuration, Secure Boot, kernel, initrd, and kernel parameters, among others.
On modern equipment you will see 24 PCRs (0–23). The most relevant ones in UEFI boot with systemd are:
– PCR 0: firmware code.
– PCR 1: firmware configuration (UEFI settings).
– PCR 7: Secure Boot status and certificates it trusts.
– PCR 9: initrd(s) measured by the kernel.
– PCR 11: UKI (Unified Kernel Image) and phase marks via systemd-stub/systemd-pcrphase.
– PCR 12: kernel command line.
Read and extend PCRs with tpm2-tools: tpm2_pcrread and tpm2_pcr_extend
In tpm2-tools, reading is done with tpm2_pcrread and extension with tpm2_pcrextend . You will sometimes see “tpm2_pcr_extend” used to refer to the conceptual extension operation, but the actual command in the suite is tpm2_pcrextend.
To inspect the current status of SHA-256 PCRs , it's as simple as:
# Leer PCRs en SHA-256 (ejemplos de índices habituales)
sudo tpm2_pcrread sha256:0,1,7,9,11,12
# O todos los PCRs SHA-256 disponibles
tpm2_pcrread sha256:all
To extend a PCR with the hash of arbitrary data (for example, the hash of /etc/passwd), calculate the SHA-256 hash and extend it. Remember: the TPM doesn't receive huge amounts of data, only its hash , due to design limitations.
# 1) Guardar el hash de /etc/passwd
echo -n $(sha256sum /etc/passwd | cut -d' ' -f1) > passwd.sha
# 2) Extender PCR 7 (ejemplo) con el hash previo
sudo tpm2_pcrextend 7:sha256=$(cat passwd.sha)
# 3) Ver el nuevo valor del PCR 7
tpm2_pcrread sha256:7
If you want to reproduce the math of the extension outside of the TPM, you concatenate the current value of the PCR (binary) with the new hash and apply SHA-256 again to check the result.
Can a PCR be reset?
Under normal circumstances, no. The philosophy is that a PCR only grows with extensions . There is one exception: PCR 16 is usually reserved for "debug" and can be reset in certain flows, but it's not useful as the root security for your policy.
Measured Boot, LUKS, and systemd-cryptenroll: Putting the Pieces Together
When you integrate the TPM into your disk encryption, you can "tie" the key unlock to a set of PCRs. If, during the current boot, those PCRs have the same values as when you registered the key , the TPM unseals and the LUKS volume opens automatically (with or without a pre-boot PIN, depending on your configuration).
This is easily accomplished using systemd-cryptenroll and systemd-cryptsetup. The idea is to create your volume, register the TPM key, and add a recovery key so you're not locked out if metrics change (for example, after a firmware or kernel update).
# Ejemplo: crear LUKS, matricular TPM y añadir recuperación (pseudoflujo)
# 1) Crear el volumen con contraseña temporal
sudo cryptsetup luksFormat /dev/nvme0n1p2
# 2) Matricular TPM en LUKS usando PCRs concretos y PIN
sudo systemd-cryptenroll \
--tpm2-device=auto \
--tpm2-with-pin=yes \
--tpm2-pcrs=1+2+3+4 \
--wipe-slot=empty \
/dev/nvme0n1p2
# 3) Añadir clave de recuperación aleatoria
sudo systemd-cryptenroll --recovery-key /dev/nvme0n1p2
# 4) Abrir con TPM o con recovery cuando proceda
systemd-cryptsetup attach root /dev/nvme0n1p2 - tpm2-device=auto
If you force a discrepancy (for example, by intentionally extending PCR 4 ), the TPM will no longer release the key, and you'll have to use the recovery key. You can then re-enroll the TPM with the new values using `--wipe-slot=tpm2` and another run of `systemd-cryptenroll`.
Which PCRs to choose and why
The more relevant PCRs you link, the more surface area you reduce, but the more often you'll have to re-register after legitimate changes. Some practical criteria:
– PCR 7 (Secure Boot): Should be very stable if your keyset doesn’t change.
– PCR 0/1 (firmware and configuration): These rarely change; they require re-registration after updating firmware or changing the BIOS/UEFI.
– PCR 9/11/12 (kernel, initrd, UKI and cmdline): These change frequently if you don’t use UKI or stable signature/policy.
In some environments, only PCR 7 has been linked, relying on Secure Boot verifying the kernel and initrd if they are booted as signed UKIs and using systemd-boot, which prevents editing kernel parameters when Secure Boot is active . This works, but if your Secure Boot relies on third-party keys (like Microsoft's third-party system), it's easier to orchestrate an alternative boot that preserves PCR 7, and therefore, it's not the most restrictive option.
UKI and PCR policies signed: stability without losing security
A practical solution to avoid re-registering every time you update the kernel is to use a Unified Kernel Image (UKI) and a signed PCR policy . You generate a key pair, bind the public key to the TPM upon registration, and sign your UKI after each update; the TPM trusts this signature and allows unlocking even if the specific kernel hash changes.
The systemd-measure tool and the systemd-ukify helper facilitate this: ukify packages the kernel, initrd, and cmdline into the UKI (typically measured at PCR 11), and systemd-measure signs the policy. With mkinitcpio, ukify can be integrated so that post-installation signing is performed automatically.
# Esquema típico (pseudocomandos)
# 1) Crear claves para política PCR firmada
openssl genpkey -algorithm RSA -out /etc/kernel/pcr-initrd.key.pem -pkeyopt rsa_keygen_bits:3072
openssl req -new -x509 -key /etc/kernel/pcr-initrd.key.pem -out /etc/kernel/pcr-initrd.pub.pem -subj "/CN=UKI PCR Policy"
# 2) Configurar ukify/mkinitcpio para generar UKI y firmar política
# (consultar man ukify y systemd-measure para parámetros)
# 3) Matricular en LUKS atando PCRs y clave pública de la política
sudo systemd-cryptenroll \
--tpm2-device=auto \
--wipe-slot=tpm2 \
--tpm2-with-pin=yes \
--tpm2-pcrs=0+1+2+7 \
--tpm2-public-key=/etc/kernel/pcr-initrd.pub.pem \
--tpm2-public-key-pcrs=11 \
/dev/nvme0n1p2
This way, your policy remains stable against kernel/initrd changes as long as you continue signing the UKI with your key . If you renew keys or change the set of PCRs, you will need to re-register.
Examples of measurement chains with systemd
During startup, systemd-stub and systemd-pcrphase extend PCRs at specific times. For example, “enter-initrd” is registered in PCR 11 , allowing a key unlock to be valid only within the initrd (reducing vectors where an attacker might try to reuse the key later).
On systems with UKI, the UKI contents are measured in PCR 11; on systems without UKI, the kernel measures initrds in PCR 9 and the bootloader can measure the cmdline in PCR 12. Make sure to cover initrd and cmdline in your policy, or someone could backdoor the initrd or boot with a malicious cmdline like init=/bin/bash.
Real risks: cold boot, TPM sniffing, and more
What could go wrong? Several things to know for threat modeling. Cold boot attacks remain viable: if unlocking is fully automatic, an attacker can make unlimited attempts. The clear mitigation is to require a pre-boot PIN (PBA), reducing attempts to one per power cycle.
Another category involves sniffing attacks on the TPM bus . The CPU requests the key, the TPM sends it; if the link is compromised, the key can be leaked. To prevent this, systemd implements parameter encryption so that the exchange is encrypted; alternatively, using fTPM/Intel PTT or encrypted memory reduces exposure. There are relatively affordable public demonstrations (even using microcontrollers) that illustrate the feasibility of this on laptops from major brands.
There have also been academic and practical vulnerabilities: TPM-Fail, faulTPM (with a notable impact on AMD) , and the bitpixie case (CVE-2023-21563) . This doesn't mean TPM is useless, but rather that you should keep your firmware up to date, understand your threat model, and not rely on it blindly.
BitLocker status against these threats
In the Windows world, BitLocker is the most widely deployed disk encryption method. It has recently been pointed out that its default configuration (automatic unlocking only with TPM) leaves the door open to both cold booting and TPM channel sniffing, as it does not implement systemd-style parameter encryption. This makes certain corporate systems vulnerable to attack within minutes.
The recommendation there is to enable pre-boot authentication via policies/registry or CLI, something that isn't sufficiently exposed to the average user. Also, remember to check where the recovery key is stored: it often resides in the user's Microsoft account, which is another potential risk if not properly managed.
Offensive/Defensive Trick: Replace the LUKS root to force your password
An interesting attack vector exists when there is no pre-boot authentication. An attacker can clone the real LUKS partition, replace it with another LUKS partition using the same UUID and a password they know , and boot the machine. Since the PCR measurements match, the TPM releases the key, but it doesn't match the fake LUKS partition, so the initrd prompts for the "recovery" key. By entering the password known to the attacker, their system runs as root in the initrd, and they can then orchestrate the theft of the original key (for example, by mounting the real copy over the network and using systemd-cryptsetup).
Clear mitigations: enable pre-boot authentication , leverage systemd-pcrphase to tie unlocking strictly to the initrd phase, and consider measuring/tying the target LUKS volume as well (requires careful design to avoid vicious circles).
Choosing partitioning and second key: best practice
Maintaining a recovery key is mandatory: if the TPM or the motherboard fails, your key tied to the TPM is useless. LUKS allows multiple slots (TPM uses one, recovery another). Furthermore, separating / and /home partitions has advantages: you can enforce strict TPM security measures on / and use a strong key or a FIDO2/YubiKey device for /home, reducing reliance on a single mechanism.
What happens when you update firmware or kernel?
If you change the firmware or modify UEFI settings, PCRs like 0/1 will change, and the TPM won't release the key until you re-register. For the kernel and initrd , changes are frequent : if you don't use a signed UKI policy, each update might force you to use recovery mode and re-register afterward. With a signed UKI, you simply sign and you're done.
Community Notes and Observations
Some popular guides for certain distributions recommend using only PCR 7 when using UKI and systemd-boot , citing the security of Secure Boot and the inability to edit cmdlines. It works, but there are risks if you rely on third-party sources. A bug has also been documented in the past where repeatedly pressing Enter would cause a recovery shell to appear after unlocking; it's advisable to keep versions updated to avoid surprises.
On 2025/06, some interesting comments were shared: faultTPM continues to affect AMD to some extent; wikis have added specific sections on signed PCR policies; and the installer of a distribution that offers FDE with TPM as an experimental feature was tested, with some practical hiccups (requesting recovery on the first boot, dependence on snaps, double encrypted disk), a topic that deserves a deeper audit.
A follow-up study focusing on disk encryption in Windows was published in July 2025. The overall conclusion reinforces the need for PBA and TPM channel encryption , as well as limiting reliance on third-party keys in Secure Boot.
Operational tips with tpm2-tools and systemd
For everyday use: install tpm2-tools and tpm2-tss. Use /dev/tpmrm0 by default , and tpm2_pcrread/tpm2_pcrextend to check and experiment with PCRs. Avoid extending production PCRs with arbitrary data: do this in labs or use PCR16 for testing.
When registering with systemd-cryptenroll: `--tpm2-device=auto` detects the TPM; `--tpm2-with-pin` adds a PBA; `--tpm2-pcrs=… ` selects your PCRs; `--tpm2-public-key=…` and `--tpm2-public-key-pcrs=… ` activate a signed PCR policy (for example, tied to PCR 11 for UKI). Don't forget `--wipe-slot` when you want to clear a previous slot.
If you don't have TPM and systemd makes you wait on boot
Occasionally, after an update, a service might try to use the TPM even if your machine doesn't have it visible, causing timeouts on startup. First, check that there are no entries in /dev/tpm* or /sys/class/tpm.
# Verificación rápida
ls /dev/tpm*
ls /sys/class/tpm/
If there is no TPM, check that your /etc/crypttab file doesn't contain options like tpm2-device=auto . If they exist, remove them and regenerate your initrd. You can also disable the metering phase on devices without a TPM.
# 1) Eliminar referencias TPM en /etc/crypttab y regenerar initrd
sudo mkinitcpio -P # (o dracut/rebuildinitrd según distro)
# 2) Evitar carga de módulos TPM si el firmware publica algo extraño
echo -e "blacklist tpm\nblacklist tpm_tis\nblacklist tpm_crb" | sudo tee /etc/modprobe.d/no-tpm.conf
# 3) Opcional: evitar pcrphase si te da problemas
sudo systemctl mask systemd-pcrphase.service
This eliminates unnecessary waiting if your computer lacks a TPM. If you later enable the TPM in BIOS/UEFI , remove the blacklist and unmask the drive to retrieve measurements.
Good practices and trust decisions
Some people are wary of TPM because it's a "black box," just like self-encrypting disks. This is a reasonable concern. Evaluate your threat model and balance usability, privacy, and maintenance. For many, TPM + PBA + signed UKI represents a significant security upgrade without excessive friction.
On hardware that allows it, add encrypted memory and avoid relying on third-party keys in Secure Boot; limit the key chain to your own keys whenever feasible. Keep firmware and kernel updated to incorporate published vulnerability mitigations.
Mastering `/dev/tpm0`, `/dev/tpmrm0`, and the `tpm2_pcrread` and `tpm2_pcr_extend` operations opens the door to measured booting and robust disk encryption in Linux. With UKI and a signed PCR policy, you achieve operational stability, and adding a pre-boot PIN protects against the most practical attacks. The key is choosing the right PCRs, signing frequently changing settings, and always maintaining a strong recovery key.
Table of Contents
- 1 What is a TPM 2.0 and why you might care
- 2 /dev/tpm0 and /dev/tpmrm0: differences and when to use each one
- 3 TPM PCRs: How they work and what they measure
- 4 Read and extend PCRs with tpm2-tools: tpm2_pcrread and tpm2_pcr_extend
- 5 Can a PCR be reset?
- 6 Measured Boot, LUKS, and systemd-cryptenroll: Putting the Pieces Together
- 7 Which PCRs to choose and why
- 8 UKI and PCR policies signed: stability without losing security
- 9 Examples of measurement chains with systemd
- 10 Real risks: cold boot, TPM sniffing, and more
- 11 BitLocker status against these threats
- 12 Offensive/Defensive Trick: Replace the LUKS root to force your password
- 13 Choosing partitioning and second key: best practice
- 14 What happens when you update firmware or kernel?
- 15 Community Notes and Observations
- 16 Operational tips with tpm2-tools and systemd
- 17 If you don't have TPM and systemd makes you wait on boot
- 18 Good practices and trust decisions