Back up your ESXi TPM recovery key before the motherboard gets swapped

If your ESXi host has a TPM 2.0 chip, its configuration is sealed to that chip. Replace the motherboard without the ESXi TPM recovery key, and the host greets you with a purple screen and a reinstall. That goes for any server with a TPM 2.0 device: Dell, HPE, Lenovo, Cisco or a homelab box.

I learned this at a customer. A system board in one of their Dell PowerEdge R640 hosts was replaced, and nobody had backed up the TPM recovery keys. I didn’t think about it either: a new board also means a new TPM, and the old one takes the key to the ESXi configuration with it. Without the recovery key there is no way to unlock that configuration on the new TPM, and we couldn’t recover it. We ended up reinstalling the host. This post covers the three parts you need: configure the TPM correctly (with a Dell R640 as the example), back up the recovery key of every host, and restore a host after the TPM or motherboard is replaced.

What the TPM actually protects

Since ESXi 7.0 U2 the host configuration is encrypted (secure ESXi configuration). When the host has a working TPM 2.0, the encryption key is sealed in the TPM. Check it on any host:

esxcli system settings encryption get
   Mode: TPM
   Require Executables Only From Installed VIBs: false
   Require Secure Boot: false

Mode: TPM means the key lives in the TPM. Mode: NONE means the host has no usable TPM and the key is stored in the bootbank instead.

With TPM mode on, ESXi generates a recovery key. That key is the only way to unlock the configuration when the TPM is no longer the same chip.

Why a board swap is the dangerous one

On most servers the TPM 2.0 is a small plug-in module on the system board, or built into the board firmware. Physically you can often take that module out, but the TPM is cryptographically bound to the motherboard. You can’t move the existing module to another board and expect ESXi to carry on as before.

There are two different scenarios:

  • Replacing only the TPM module. Whether that is possible depends on the vendor and the board design. Many TPM modules are specific to a motherboard generation and need firmware configuration. ESXi sees a different TPM.
  • Replacing the entire motherboard. The new board has a different TPM identity, with a new Endorsement Key. ESXi detects a different TPM, and the TPM-backed configuration needs the recovery key.

In both cases ESXi can no longer unseal its configuration with the TPM it had.

Dell PowerEdge R640 TPM 2.0 module (Nuvoton NPCT650) on the system board
The TPM 2.0 plug-in module on a Dell R640 system board. It is cryptographically bound to the board, so a new board means a new TPM identity.

Broadcom KB 316424 lists the hardware changes that can bite you:

  • system board / motherboard replacement
  • CMOS battery replacement
  • CPU or RAM replacement

The KB is clear about the worst case: if the recovery key was never saved and the motherboard is replaced, the host needs a full ESXi reinstall. A configuration backup alone is not enough.

Step 1: configure the TPM

Whatever the vendor, ESXi needs the same things from the BIOS: UEFI boot, Secure Boot, the TPM 2.0 enabled and set to SHA-256. ESXi supports TPM 2.0 only with SHA-256. If the BIOS uses SHA-1, vCenter shows the alarm “TPM 2.0 device detected but a connection cannot be established” (Dell KB 000193231). Intel TXT is optional but often enabled together with the TPM.

The menu names differ per vendor. On a Dell R640, in System Setup (F2 at boot):

  1. Check that the boot mode is UEFI and Secure Boot is enabled.
  2. System BIOS > System Security > TPM Security: On. Save and reboot.
  3. System BIOS > System Security > TPM Advanced Settings > TPM2 Algorithm Selection: SHA256.
  4. System BIOS > System Security > Intel TXT: On. Save and reboot.

If the host is already in vCenter with the TPM alarm, Dell advises to remove it from vCenter before you change these settings and add it again afterwards.

On a Dell you can also do this from the iDRAC with racadm. Attribute names can differ between BIOS versions, so list them first:

racadm get BIOS.SysSecurity
racadm get BIOS.BiosBootSettings.BootMode

Then set the values you need and create a BIOS job that applies them at the next power cycle:

racadm set BIOS.SysSecurity.TpmSecurity On
racadm set BIOS.SysSecurity.IntelTxt On
racadm jobqueue create BIOS.Setup.1-1 -r pwrcycle -s TIME_NOW

After the reboot, check on the host that ESXi sees the TPM:

esxcli hardware trustedboot get
esxcli system settings encryption get

In vCenter the host should show as Passed under Cluster > Monitor > Security.

Step 2: back up the ESXi TPM recovery key of every host

On one host it’s one command:

esxcli system settings encryption recovery list
Recovery ID                             Key
--------------------------------------  ---
{3B5C1E52-...}                          2290-...

Save the Recovery ID together with the key. The ID tells you which key belongs to which host when you have a list of them.

Doing that over SSH on every host is not something you want to repeat. So I wrote a small PowerCLI script that does it for all hosts in one or more clusters through vCenter. It only reads, it changes nothing:

.\Get-TpmRecoveryKey.ps1 -VCenter vc01.corp.local -Cluster CL-MGMT-01 | Format-Table
VMHost           Cluster    EncryptionMode RecoveryId   Key       Status  Message
------           -------    -------------- ----------   ---       ------  -------
esx01.corp.local CL-MGMT-01 TPM            {3B5C...}    2290-...  OK
esx02.corp.local CL-MGMT-01 NONE                                  NoKey   No recovery key (TPM configuration encryption not active?)
esx03.corp.local CL-MGMT-01                                       Skipped Host is NotResponding

Hosts that are disconnected, have no key or fail are in the output too, with the reason. A host with NONE is worth a look: that usually means the TPM is off in the BIOS or set to SHA-1.

On VCF you don’t need to type the vCenter password. With -UseSddcCredentials the script reads the vCenter SSO account from the SDDC Manager vault, so you only log in to SDDC Manager:

.\Get-TpmRecoveryKey.ps1 -VCenter vc01.corp.local -SddcManager sddc01.corp.local -UseSddcCredentials

Add -CsvPath if you want a CSV. The script is on my GitHub: Get-TpmRecoveryKey.

The output contains secrets. Put the keys in your password manager or vault, and delete the CSV from disk afterwards. A recovery key in a file share next to the hosts it unlocks is not a backup, it’s a risk.

When do you run it? After you enable TPM mode on new hosts, after a reinstall, and before you log a hardware call with your vendor.

Step 3: before the technician comes in

When you know a board swap is coming, prepare the host (KB 316424):

  1. Put the host in maintenance mode.
  2. Run the script (or esxcli system settings encryption recovery list) and check that the key is in your vault.
  3. Sync and back up the configuration:
vim-cmd /hostsvc/firmware/sync_config
vim-cmd /hostsvc/firmware/backup_config
  1. Power off the host and let the technician do the swap.

The new board comes with a new TPM. Run through Step 1 again: a replacement board does not always come with the BIOS settings you had, so check the TPM, SHA-256 and Secure Boot settings before you boot ESXi.

Step 4: restore ESXi with the TPM recovery key

  1. Power on the host and open the remote console (iDRAC, iLO, XClarity, CIMC, …).
  2. At the ESXi boot screen press Shift+O (the letter O, not zero).
  3. Leave the existing bootUUID=... alone. Add a space and then the key:
bootUUID=<existing UUID> encryptionRecoveryKey=<your recovery key>
  1. Press Enter. The host decrypts its configuration and boots.

The key is long. If your remote console supports pasting text (on Dell, iDRAC9 with a Datacenter license), paste it instead of typing it.

Watch out for one thing: if you press Shift+O more than once, it’s easy to end up with a trailing “O” on the bootUUID. Then the configuration can’t be saved after the recovery and the host asks for the key on every boot (KB 410638). Check the boot options with bootOption -poC if that happens.

Once the host is up, SSH to it and seal the configuration to the new TPM, then save it:

esxcli system settings encryption set --mode=TPM
/sbin/auto-backup.sh

The output of auto-backup.sh should show the bootbank being saved and esx.conf being encrypted with a key ID. Reboot once without the recovery key to be sure it sticks.

Finally, run the script again. The new TPM means a new recovery key, and your vault now holds the old one.

vCenter attestation after the swap

vCenter remembers the Endorsement Key of the old TPM. After the swap it sees a different EK, shows a TPM endorsement key mismatch alarm and attestation goes to Failed. KB 440352 describes this for ESXi 8.x, including a PSOD when the old keys stay in the vCenter database.

The light fix is to disconnect and reconnect the host in vCenter (or remove it and add it again) so it learns the new EK, and then clear the alarm. If that doesn’t do it, KB 440352 has a procedure that clears the stored keys directly in the vCenter database. That is a database edit: take a snapshot of the vCenter appliance first, and open a case with Broadcom if you are not comfortable with it.

Wrap-up

  • With a TPM 2.0, ESXi seals its configuration to that chip. This is not specific to one vendor: on any server a new TPM module or a new board means a different TPM identity.
  • Configure the BIOS for ESXi: UEFI, Secure Boot, TPM 2.0 on, SHA-256. On a Dell R640 that is TPM Security On, SHA256 and Intel TXT On.
  • Back up the recovery key of every host and keep it in a vault, not in a CSV on a share. My Get-TpmRecoveryKey script does that for whole clusters.
  • After the swap: Shift+O, encryptionRecoveryKey=, then esxcli system settings encryption set --mode=TPM and /sbin/auto-backup.sh.
  • Back up the new key afterwards, and fix the attestation in vCenter.

References

Leave a Reply

Your email address will not be published. Required fields are marked *