Skip to content

Arch Linux Bare-Metal Provisioning: LUKS2 Argon2id, Btrfs Subvolumes, Unified Kernel Images (UKI) & Secure Boot

Created: 2026-11-06  ·  Last updated: 2026-11-13  ·  Nejat Hakan

Executive Summary: A standard unencrypted Linux installation relying on legacy GRUB and an unprotected /boot partition leaves data at rest vulnerable to physical theft, permits Evil Maid tampering against the initramfs, and offers zero rollback protection against broken rolling-release upgrades. This enterprise masterclass walks step by step through an uncompromisingly hardened bare-metal deployment of Arch Linux: Cryptographic ISO verification (WKD & BLAKE2), GPT partitioning with LUKS2 (aes-xts-plain64 + Argon2id), dedicated Btrfs Copy-on-Write subvolumes (@, @home, @snapshots, @var_log, @pkg, @srv), dual-kernel resiliency (linux + linux-lts), systemd-based initramfs (sd-encrypt), cryptographically signed Unified Kernel Images (UKI) verified by UEFI Secure Boot (sbctl), hardware-bound TPM2/FIDO2 auto-unlock, and automated pre/post-upgrade snapshots (snapper + snap-pac).

  • 1. ISO Verification & Pre-Flight


    Validate Arch release signatures via Web Key Directory (pierre@archlinux.org) and BLAKE2 checksums while preparing UEFI Setup Mode and HTTPS mirrorlists.

  • 2. GPT & LUKS2 (Argon2id)


    Create a declarative GPT layout via sgdisk, enforce 4K sector alignment, configure Argon2id KDF (512-bit XTS key), and bypass dm-crypt workqueues for peak NVMe IOPS.

  • 3. Btrfs CoW Subvolume Topology


    Segregate @, @home, @snapshots, @var_log, @pkg, and @srv with zstd:3 compression and discard=async so logs and package caches survive root rollbacks.

  • 4. Bootstrap, Dual-Kernel & fstab


    Deploy mainline (linux) and fallback LTS (linux-lts) kernels via pacstrap -K and strip brittle subvolid= parameters from /etc/fstab.

  • 5. Chroot, Admin Hardening & Network


    Configure localization, timezone, an unprivileged wheel administrator (/etc/sudoers.d/10-wheel), a locked root account, and deterministic networking.

  • 6. Systemd Initramfs & UKI Build


    Replace legacy BusyBox hooks with systemd and sd-encrypt, bundling the kernel, microcode, initramfs, and kernel cmdline into a single PE binary (/efi/EFI/Linux/*.efi).

  • 7. UEFI Secure Boot via sbctl


    Generate custom Platform and Database keys, enroll them alongside Microsoft Option ROM certificates (sbctl enroll-keys -m), and auto-sign UKIs on every kernel upgrade.

  • 8. TPM2 & FIDO2 Hardware Unlock


    Bind LUKS2 decryption via systemd-cryptenroll to UEFI Secure Boot state (TPM 2.0 PCR 0+7 + PIN) or a FIDO2 hardware security token (YubiKey/Nitrokey).

  • 9. Transactional Snapper Rollbacks


    Anchor snapper cleanly onto the @snapshots subvolume, trigger automated read-only pre/post snapshots on every pacman -Syu via snap-pac, and execute atomic rollbacks.

  • 10. Zram Swap, Maintenance & Rescue


    Deploy compressed in-RAM swap (zram-generator with zstd and vm.swappiness=180), automated package cache pruning (paccache.timer), and the chroot emergency runbook.


1. Cryptographic ISO Verification & Live Pre-Flight

Before writing the installation image to USB media, verify its cryptographic authenticity against Pierre Schmitz's official Arch Linux release signing key (pierre@archlinux.org) and the BLAKE2b checksum manifest (b2sums.txt).

1.1 Validating the PGP Signature & BLAKE2 Checksum

Cryptographically Verifying the Arch Linux ISO (On Your Workstation)
# 1. Fetch the official Arch Linux Release Engineering key directly via Web Key Directory (WKD)
gpg --auto-key-locate clear,wkd -v --locate-external-key pierre@archlinux.org

# 2. Verify the detached PGP signature against the downloaded ISO image
gpg --keyserver-options auto-key-retrieve --verify archlinux-x86_64.iso.sig archlinux-x86_64.iso

# 3. Validate the BLAKE2b cryptographic hash
b2sum -c b2sums.txt --ignore-missing

Expected GPG Primary Fingerprint

Verify that gpg --verify outputs the exact primary fingerprint of the Arch Linux Release Engineering signing key: 3E80 CA1A 8B89 F69C BA57 D98A 76A5 EF90 5444 9A5C (Pierre Schmitz <pierre@archlinux.org>).

1.2 UEFI Setup Mode, Keymap & Mirrorlist in the Live Environment

Boot the target machine from the USB drive in 64-bit UEFI mode. In your UEFI/BIOS firmware settings, ensure Secure Boot is enabled but placed into Setup Mode (Clear Secure Boot Keys / Custom Mode), allowing custom key enrollment in Chapter 7.

File: /root/01_live_preflight.sh (Executed Inside the Arch Live ISO)
#!/usr/bin/env bash
set -euo pipefail

# 1. Confirm 64-bit UEFI platform mode (Must output '64')
cat /sys/firmware/efi/fw_platform_size

# 2. Check UEFI Secure Boot Setup Mode status
bootctl status | grep -E "Secure Boot|Setup Mode"

# 3. Set keyboard layout and high-DPI console font
loadkeys de-latin1
setfont ter-132b

# 4. Synchronize system clock via NTP
timedatectl set-ntp true
timedatectl status

# 5. Select the fastest HTTPS mirrors via reflector
reflector \
  --country Germany,Austria,Switzerland \
  --protocol https \
  --latest 15 \
  --sort rate \
  --save /etc/pacman.d/mirrorlist

2. GPT Partitioning & LUKS2 Argon2id Cryptography

Instead of relying on a fragile multi-stage boot chain (an unencrypted /boot partition + GRUB + separate LVM layers), this architecture uses exactly two GPT partitions:

  1. Partition 1 (/dev/nvme0n1p1, 1 GiB, Type ef00): The EFI System Partition (ESP), mounted at /efi. It holds only systemd-boot and cryptographically signed Unified Kernel Images (UKIs). An attacker cannot tamper with kernel parameters or the initramfs without invalidating the PE signature.
  2. Partition 2 (/dev/nvme0n1p2, Remaining Capacity, Type 8309): The Argon2id-hardened LUKS2 container (cryptroot), directly hosting the Btrfs filesystem and all Copy-on-Write subvolumes.
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
    subgraph S1 ["1. UEFI Firmware & Secure Boot"]
        direction TB
        PK["Custom PK / KEK / db Keys<br/>Enrolled via sbctl"]
        BOOT["systemd-bootx64.efi<br/>PE Signature Verification"]
        PK --> BOOT
    end

    subgraph S2 ["2. ESP (/efi on /dev/nvme0n1p1)"]
        direction TB
        UKI1["arch-linux.efi (Mainline UKI)<br/>Kernel + Ucode + Initrd + Cmdline"]
        UKI2["arch-linux-lts.efi (LTS UKI)<br/>Fallback Kernel + Initrd"]
        UKI1 --> UKI2
    end

    subgraph S3 ["3. LUKS2 Container (/dev/nvme0n1p2)"]
        direction TB
        CRYPT["LUKS2 (aes-xts-plain64, 512-Bit)<br/>Argon2id + TPM2 PCR 0+7 Unlock"]
    end

    subgraph S4 ["4. Btrfs CoW Pool (zstd:3)"]
        direction TB
        SUB1["@ (/) & @home (/home)"]
        SUB2["@snapshots (/.snapshots)<br/>& @var_log (/var/log)"]
        SUB3["@pkg (/var/cache/pacman/pkg)<br/>& @srv (/srv)"]
        SUB1 --> SUB2 --> SUB3
    end

    S1 ==> S2 ==> S3 ==> S4

2.1 Declarative GPT Partitioning via sgdisk

File: /root/02_partition_gpt.sh
#!/usr/bin/env bash
set -euo pipefail

DISK="/dev/nvme0n1"

# 1. Wipe all existing partition tables and filesystem signatures
wipefs -af "${DISK}"
sgdisk --zap-all "${DISK}"

# 2. Create GPT layout with 1 GiB ESP (ef00) and Linux LUKS2 (8309)
sgdisk --clear \
  --new=1:0:+1G   --typecode=1:ef00 --change-name=1:"EFI" \
  --new=2:0:0     --typecode=2:8309 --change-name=2:"cryptsystem" \
  "${DISK}"

partprobe "${DISK}"
lsblk -o NAME,SIZE,TYPE,PARTLABEL,PARTTYPENAME "${DISK}"

2.2 LUKS2 Formatting & NVMe Workqueue Optimization

Modern NVMe SSDs process I/O requests across massively parallel hardware queues. By default, the Linux kernel's dm-crypt subsystem inserts intermediate software read/write workqueues that introduce latency spikes and reduce throughput by up to 40% on PCIe 4.0/5.0 NVMe drives. Passing --perf-no_read_workqueue, --perf-no_write_workqueue, and --persistent permanently writes these optimization flags into the LUKS2 JSON header.

File: /root/03_luks2_format.sh
#!/usr/bin/env bash
set -euo pipefail

# 1. Format the EFI System Partition as FAT32
mkfs.fat -F 32 -n EFI /dev/nvme0n1p1

# 2. Initialize LUKS2 container with Argon2id (4 GiB memory cost, 4s iteration) and 4K sectors
cryptsetup luksFormat \
  --type luks2 \
  --cipher aes-xts-plain64 \
  --key-size 512 \
  --hash sha512 \
  --pbkdf argon2id \
  --pbkdf-memory 4194304 \
  --iter-time 4000 \
  --sector-size 4096 \
  /dev/nvme0n1p2

# 3. Open LUKS2 container and persist TRIM + workqueue bypass flags in the LUKS2 header
cryptsetup open \
  --allow-discards \
  --perf-no_read_workqueue \
  --perf-no_write_workqueue \
  --persistent \
  /dev/nvme0n1p2 cryptroot

# 4. Verify persistent flags in the LUKS2 header
cryptsetup luksDump /dev/nvme0n1p2 | grep -A 5 "Flags:"

3. Btrfs Copy-on-Write Subvolume Topology

Why does a rolling-release distribution like Arch Linux require dedicated Btrfs subvolumes for /var/log and /var/cache/pacman/pkg?

When a faulty system upgrade (pacman -Syu) requires rolling back the root subvolume @ to an earlier snapshot, two directory trees must never be reverted alongside /:

  1. @var_log (/var/log): Contains the journald and pacman.log records from the failed boot. If /var/log were part of @, rolling back would erase the forensic evidence needed to diagnose the failure.
  2. @pkg (/var/cache/pacman/pkg): Stores downloaded .pkg.tar.zst archives so broken packages can be downgraded offline via pacman -U.
Subvolume Mountpoint Mount Options Purpose & Rollback Behavior
@ / noatime,compress=zstd:3,ssd,discard=async,space_cache=v2 Root filesystem (snapshotted by snapper and swapped during rollbacks)
@home /home noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,nodev,nosuid User data (decoupled from root OS rollbacks)
@snapshots /.snapshots noatime,compress=zstd:3,ssd,discard=async,space_cache=v2 Storage pool for snapper read-only snapshots
@var_log /var/log noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,nodev,nosuid,noexec Persistent system and audit logs (survive root rollbacks)
@pkg /var/cache/pacman/pkg noatime,compress=zstd:3,ssd,discard=async,space_cache=v2 Local Pacman package cache for offline downgrades
@srv /srv noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,nodev,nosuid Persistent server and container payload data
@tmp /var/tmp noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,nodev,nosuid,noexec Persistent temporary files outside RAM (tmpfs)
File: /root/04_btrfs_subvolumes.sh
#!/usr/bin/env bash
set -euo pipefail

# 1. Create the Btrfs filesystem atop the opened LUKS2 mapper device
mkfs.btrfs -L ARCH -f /dev/mapper/cryptroot

# 2. Mount top-level subvolume (subvolid=5) temporarily and create subvolume layout
mount /dev/mapper/cryptroot /mnt

btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@var_log
btrfs subvolume create /mnt/@pkg
btrfs subvolume create /mnt/@srv
btrfs subvolume create /mnt/@tmp

umount /mnt

# 3. Mount root subvolume (@) with zstd:3 compression and async NVMe TRIM
BTRFS_OPTS="noatime,compress=zstd:3,ssd,discard=async,space_cache=v2"
mount -o "${BTRFS_OPTS},subvol=@" /dev/mapper/cryptroot /mnt

# 4. Create mountpoint directories
mkdir -p /mnt/{efi,home,.snapshots,var/log,var/cache/pacman/pkg,srv,var/tmp,var/lib/machines,var/lib/portables}

# 5. Mount dedicated subvolumes with CIS-hardened security flags
mount -o "${BTRFS_OPTS},nodev,nosuid,subvol=@home"                /dev/mapper/cryptroot /mnt/home
mount -o "${BTRFS_OPTS},subvol=@snapshots"                        /dev/mapper/cryptroot /mnt/.snapshots
mount -o "${BTRFS_OPTS},nodev,nosuid,noexec,subvol=@var_log"      /dev/mapper/cryptroot /mnt/var/log
mount -o "${BTRFS_OPTS},subvol=@pkg"                              /dev/mapper/cryptroot /mnt/var/cache/pacman/pkg
mount -o "${BTRFS_OPTS},nodev,nosuid,subvol=@srv"                 /dev/mapper/cryptroot /mnt/srv
mount -o "${BTRFS_OPTS},nodev,nosuid,noexec,subvol=@tmp"          /dev/mapper/cryptroot /mnt/var/tmp

# 6. Mount the EFI System Partition with restrictive permissions (umask=0077) at /mnt/efi
mount -o umask=0077,fmask=0077,dmask=0077 /dev/nvme0n1p1 /mnt/efi

# 7. Optional: Disable Copy-on-Write for database/VM directories to prevent fragmentation
mkdir -p /mnt/var/lib/{postgres,libvirt/images}
chattr +C /mnt/var/lib/postgres
chattr +C /mnt/var/lib/libvirt/images

4. Base System Bootstrap (pacstrap), Dual-Kernel & fstab Hardening

On production systems, we always install the Long-Term Support kernel (linux-lts) alongside the mainline kernel (linux). If a newly released mainline kernel introduces a hardware driver or filesystem regression, a signed LTS UKI remains immediately selectable at the boot menu.

Critical Pitfall: subvolid= in /etc/fstab After genfstab

By default, genfstab -U /mnt writes both the subvolume path (subvol=/@) and its numeric ID (subvolid=256) into /etc/fstab. When you later perform a rollback with snapper, the newly cloned root subvolume receives a new numeric subvolid, causing /etc/fstab to mount the wrong subvolume or fail at boot! Always strip subvolid=... entries from /etc/fstab using sed.

File: /root/05_pacstrap_and_fstab.sh
#!/usr/bin/env bash
set -euo pipefail

# 1. Bootstrap base system, dual kernels (mainline + LTS), microcode (amd-ucode or intel-ucode),
#    and security/snapshot tooling with a freshly initialized keyring (-K)
pacstrap -K /mnt \
  base base-devel \
  linux linux-lts linux-firmware \
  amd-ucode \
  btrfs-progs cryptsetup dosfstools efibootmgr \
  systemd-ukify sbctl \
  snapper snap-pac \
  zram-generator pacman-contrib reflector \
  networkmanager openssh nftables \
  sudo neovim git man-db man-pages texinfo

# 2. Generate /etc/fstab using filesystem UUIDs
genfstab -U /mnt >> /mnt/etc/fstab

# 3. CRITICAL: Strip hardcoded 'subvolid=...' entries from /etc/fstab
#    so Btrfs rollbacks to new subvolume IDs boot seamlessly!
sed -i 's/subvolid=[0-9]*,//g' /mnt/etc/fstab
sed -i 's/,subvolid=[0-9]*//g' /mnt/etc/fstab

cat /mnt/etc/fstab

5. Chroot System Configuration, Admin Hardening & Network Stack

Enter the newly bootstrapped environment via arch-chroot /mnt to configure localization, timezone, an unprivileged administrative account in the wheel group, the baseline nftables firewall, and networking services:

File: /root/06_chroot_base_config.sh (Executed Inside arch-chroot /mnt)
#!/usr/bin/env bash
set -euo pipefail

# 1. Timezone and hardware clock (UTC)
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc

# 2. Generate system locales
sed -i 's/^#de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen
sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
locale-gen

cat << 'EOF' > /etc/locale.conf
LANG=en_US.UTF-8
LC_TIME=de_DE.UTF-8
EOF

cat << 'EOF' > /etc/vconsole.conf
KEYMAP=de-latin1
FONT=ter-132b
EOF

# 3. Configure hostname and /etc/hosts
echo "arch-enterprise" > /etc/hostname
cat << 'EOF' > /etc/hosts
127.0.0.1   localhost
::1         localhost
127.0.1.1   arch-enterprise.internal arch-enterprise
EOF

# 4. Provision unprivileged admin user and configure sudo policy
useradd -m -G wheel -s /bin/bash sysadmin
passwd sysadmin

install -m 0440 /dev/null /etc/sudoers.d/10-wheel
cat << 'EOF' > /etc/sudoers.d/10-wheel
%wheel ALL=(ALL:ALL) ALL
Defaults passwd_timeout=1
Defaults timestamp_timeout=5
Defaults use_pty
EOF
visudo -cf /etc/sudoers.d/10-wheel

# 5. Lock direct root login (privilege elevation restricted to sudo)
passwd -l root

# 6. Enable essential system services for first boot
systemctl enable NetworkManager.service
systemctl enable sshd.service
systemctl enable nftables.service
systemctl enable fstrim.timer

6. Systemd Initramfs (mkinitcpio) & Unified Kernel Images (UKI)

A traditional Linux boot setup stores the initramfs as a standalone file (/boot/initramfs-linux.img) while reading kernel parameters from a plaintext bootloader config. An attacker with physical access can append init=/bin/sh to the kernel command line to hijack early boot.

A Unified Kernel Image (UKI) eliminates this attack surface by instructing mkinitcpio (and ukify) to bundle four artifacts into a single PE/COFF binary (/efi/EFI/Linux/arch-linux.efi) signed as an atomic unit for UEFI Secure Boot:

  1. The Linux kernel image (/boot/vmlinuz-linux)
  2. CPU microcode updates (/boot/amd-ucode.img or /boot/intel-ucode.img)
  3. The compressed systemd initramfs image
  4. The immutable kernel command line (/etc/kernel/cmdline)

6.1 Configuring the Kernel Command Line & mkinitcpio.conf

Files: /etc/kernel/cmdline & /etc/mkinitcpio.conf (Inside arch-chroot)
# 1. Retrieve the UUID of the LUKS2 partition (/dev/nvme0n1p2)
LUKS_UUID=$(blkid -s UUID -o value /dev/nvme0n1p2)

# 2. Write hardened kernel command line with TPM2 support, Btrfs root (@), and LSM stack
cat << EOF > /etc/kernel/cmdline
rd.luks.name=${LUKS_UUID}=cryptroot rd.luks.options=${LUKS_UUID}=discard,tpm2-device=auto,no-read-workqueue,no-write-workqueue root=/dev/mapper/cryptroot rootflags=subvol=@ rw quiet loglevel=3 systemd.show_status=auto lsm=landlock,lockdown,yama,integrity,apparmor,bpf
EOF

# 3. Switch /etc/mkinitcpio.conf to native systemd hooks (replaces udev, usr, keymap, encrypt)
cat << 'EOF' > /etc/mkinitcpio.conf
MODULES=(btrfs)
BINARIES=(/usr/bin/btrfs)
FILES=()
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems)
COMPRESSION="zstd"
COMPRESSION_OPTIONS=(-9 -T0)
EOF

6.2 Configuring UKI Presets for Mainline & LTS Kernels

Files: /etc/mkinitcpio.d/linux.preset & /etc/mkinitcpio.d/linux-lts.preset
mkdir -p /efi/EFI/Linux

# 1. Preset for the mainline kernel (linux)
cat << 'EOF' > /etc/mkinitcpio.d/linux.preset
ALL_kver="/boot/vmlinuz-linux"
PRESETS=('default')
default_uki="/efi/EFI/Linux/arch-linux.efi"
default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"
EOF

# 2. Preset for the Long-Term Support kernel (linux-lts)
cat << 'EOF' > /etc/mkinitcpio.d/linux-lts.preset
ALL_kver="/boot/vmlinuz-linux-lts"
PRESETS=('default')
default_uki="/efi/EFI/Linux/arch-linux-lts.efi"
default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"
EOF

# 3. Remove redundant unencrypted /boot/initramfs-*.img files and build both UKIs
rm -f /boot/initramfs-*.img
mkinitcpio -P
ls -lh /efi/EFI/Linux/

7. UEFI Secure Boot Custom Keys (sbctl) & systemd-boot

Using sbctl, we manage our own UEFI Secure Boot Public Key Infrastructure (Platform Key PK, Key Exchange Key KEK, and Signature Database Key db). sbctl automatically installs a Pacman hook (/usr/share/libalpm/hooks/zz-sbctl.hook) that signs every rebuilt UKI whenever a kernel package is upgraded.

Critical Hardware Safety: Option ROM Protection with sbctl enroll-keys -m

Many motherboards, discrete GPUs (NVIDIA/AMD), and enterprise NICs execute UEFI Option ROM drivers during POST that are signed by the Microsoft Third-Party UEFI CA. If you enroll custom Secure Boot keys without the -m (--microsoft) flag, the UEFI firmware will refuse to initialize your GPU's Option ROM—resulting in a black screen or a soft-bricked motherboard! Always run sbctl enroll-keys -m.

Installing systemd-boot, Hardening Loader Config & Enrolling Secure Boot Keys via sbctl
# 1. Install systemd-boot to the ESP (/efi)
bootctl install

# 2. Harden systemd-boot configuration ('editor no' prevents kernel cmdline tampering at boot)
cat << 'EOF' > /efi/loader/loader.conf
default arch-linux.efi
timeout 3
console-mode max
editor no
EOF

# 3. Generate custom Secure Boot keys (stored under /var/lib/sbctl/)
sbctl create-keys

# 4. Enroll custom keys + Microsoft Option ROM certificates into UEFI NVRAM
sbctl enroll-keys -m

# 5. Sign all EFI binaries and both UKIs (-s registers paths for future Pacman upgrades)
sbctl sign -s /efi/EFI/BOOT/BOOTX64.EFI
sbctl sign -s /efi/EFI/systemd/systemd-bootx64.efi
sbctl sign -s /efi/EFI/Linux/arch-linux.efi
sbctl sign -s /efi/EFI/Linux/arch-linux-lts.efi

# 6. Verify signature database and Secure Boot status
sbctl verify
sbctl status

Exit the chroot environment (exit), cleanly unmount all filesystems (umount -R /mnt), close the LUKS container (cryptsetup close cryptroot), and reboot into the newly provisioned system (reboot).


8. TPM2 Hardware Auto-Unlock (systemd-cryptenroll) & FIDO2 Fallback

Once the system boots with UEFI Secure Boot active (sbctl status reports Secure Boot: ✓ Enabled), bind the LUKS2 volume to the Trusted Platform Module (TPM 2.0) or a FIDO2 hardware security key.

8.1 Why PCR 0+7 Is Safe with Signed UKIs

  • PCR 0: Measures the cryptographic hash of the core motherboard UEFI firmware.
  • PCR 7: Measures the Secure Boot enforcement state and the exact certificates (PK, KEK, db) used to validate our UKI.

Because the kernel command line and initramfs are compiled directly inside the signed UKI binary, the TPM 2.0 will only unseal the LUKS2 decryption key when booting a UKI signed by our private sbctl key. On mobile workstations, combine TPM2 binding with --tpm2-with-pin=yes to require a pre-boot PIN.

Binding the LUKS2 Container to TPM 2.0 (PCR 0+7) or a FIDO2 Security Key
# 1. List available TPM2 PCR banks
sudo systemd-cryptenroll --tpm2-device=list

# 2. Bind a LUKS2 keyslot to TPM 2.0 (PCR 0+7) + pre-boot PIN
sudo systemd-cryptenroll \
  --tpm2-device=auto \
  --tpm2-pcrs=0+7 \
  --tpm2-with-pin=yes \
  /dev/nvme0n1p2

# 3. Optional/Fallback: Enroll a FIDO2 hardware security key (YubiKey / Nitrokey)
sudo systemd-cryptenroll \
  --fido2-device=auto \
  --fido2-with-client-pin=yes \
  --fido2-with-user-presence=yes \
  /dev/nvme0n1p2

# 4. Inspect active LUKS2 keyslots
sudo systemd-cryptenroll /dev/nvme0n1p2

# 5. To rotate the TPM2 slot after a BIOS firmware update:
# sudo systemd-cryptenroll --wipe-slot=tpm2 /dev/nvme0n1p2

9. Transactional Rollbacks with snapper & snap-pac

For snapper to integrate cleanly with our dedicated @snapshots subvolume, we must prevent snapper create-config from creating a nested subvolume inside @. Execute the Unmount-Create-Remount procedure:

Initializing Snapper on Subvolume @snapshots & Hardening Retention Policies
# 1. Unmount /.snapshots temporarily and remove the empty mountpoint directory
sudo umount /.snapshots
sudo rmdir /.snapshots

# 2. Create the Snapper 'root' configuration for / (automatically creates a nested /.snapshots subvolume)
sudo snapper -c root create-config /

# 3. Delete Snapper's auto-created subvolume and remount our dedicated @snapshots subvolume
sudo btrfs subvolume delete /.snapshots
sudo mkdir -p /.snapshots
sudo mount -a
sudo chmod 750 /.snapshots
sudo chown :wheel /.snapshots

# 4. Tune retention limits in /etc/snapper/configs/root for production workloads
sudo sed -i 's/^ALLOW_GROUPS=.*/ALLOW_GROUPS="wheel"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_CREATE=.*/TIMELINE_CREATE="yes"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_LIMIT_HOURLY=.*/TIMELINE_LIMIT_HOURLY="5"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_LIMIT_DAILY=.*/TIMELINE_LIMIT_DAILY="7"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_LIMIT_WEEKLY=.*/TIMELINE_LIMIT_WEEKLY="2"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_LIMIT_MONTHLY=.*/TIMELINE_LIMIT_MONTHLY="0"/' /etc/snapper/configs/root
sudo sed -i 's/^TIMELINE_LIMIT_YEARLY=.*/TIMELINE_LIMIT_YEARLY="0"/' /etc/snapper/configs/root
sudo sed -i 's/^NUMBER_LIMIT=.*/NUMBER_LIMIT="20"/' /etc/snapper/configs/root

# 5. Enable Snapper timeline and cleanup timers
sudo systemctl enable --now snapper-timeline.timer snapper-cleanup.timer

# 6. Verify Snapper state (every Pacman run now triggers pre/post snapshots via snap-pac)
sudo snapper -c root list

9.1 Atomic Rollback After a Broken Upgrade

If an update renders the system unstable, mount the top-level Btrfs pool (subvolid=5) and replace @ with a read-write snapshot of the intact pre snapshot:

Atomic Btrfs Root Rollback to Snapshot Number N (e.g., Snapshot 42)
# Mount the top-level Btrfs filesystem (subvolid=5) at /mnt
sudo mount -o subvolid=5 /dev/mapper/cryptroot /mnt

# Move the broken root subvolume (@) aside for forensic inspection
sudo mv /mnt/@ /mnt/@_broken_$(date +%Y%m%d)

# Clone a writable snapshot from the known-good pre-upgrade snapshot (e.g., #42) as @
sudo btrfs subvolume snapshot /mnt/@snapshots/42/snapshot /mnt/@

# Unmount and reboot (because subvolid= was removed from /etc/fstab, @ boots immediately!)
sudo umount /mnt
sudo reboot

10. In-RAM Zram Swap, Pacman Automation & Emergency Runbook

10.1 Compressed In-RAM Swap (zram-generator) & Sysctl Tuning

Rather than wearing out NVMe flash cells with a physical swap partition, zram compresses memory pages directly in RAM using the zstd algorithm (typically achieving a 3:1 to 4:1 compression ratio). Because reading and writing compressed RAM is orders of magnitude faster than block storage I/O, set vm.swappiness = 180 and disable swap readahead clustering (vm.page-cluster = 0).

File: /etc/systemd/zram-generator.conf
[zram0]
zram-size = min(ram / 2, 16384)
compression-algorithm = zstd
swap-priority = 100
fs-type = swap
File: /etc/sysctl.d/99-zram-tuning.conf
# Optimal kernel VM parameters for high-speed zstd in-RAM swap
vm.swappiness = 180
vm.watermark_boost_factor = 0
vm.watermark_scale_factor = 125
vm.page-cluster = 0
Activating Zram Swap and Kernel VM Parameters Immediately
sudo systemctl daemon-reload
sudo systemctl start systemd-zram-setup@zram0.service
sudo sysctl --system
zramctl

10.2 Pacman Hardening & Automated Maintenance Timers (paccache & reflector)

Without automated pruning, /var/cache/pacman/pkg (@pkg) grows indefinitely. Enabling paccache.timer (provided by pacman-contrib) automatically retains the 3 most recent versions of every package for offline downgrades while purging older archives.

Enabling Pacman Parallel Downloads, paccache.timer & reflector.timer
# 1. Enable color output, verbose package tables, and 5 parallel downloads in /etc/pacman.conf
sudo sed -i 's/^#Color/Color/' /etc/pacman.conf
sudo sed -i 's/^#VerbosePkgLists/VerbosePkgLists/' /etc/pacman.conf
sudo sed -i 's/^#ParallelDownloads.*/ParallelDownloads = 5/' /etc/pacman.conf

# 2. Configure weekly HTTPS mirrorlist optimization (/etc/xdg/reflector/reflector.conf)
cat << 'EOF' | sudo tee /etc/xdg/reflector/reflector.conf
--save /etc/pacman.d/mirrorlist
--country Germany,Austria,Switzerland
--protocol https
--latest 15
--sort rate
EOF

# 3. Enable automated package cache pruning and mirror refresh timers
sudo systemctl enable --now paccache.timer reflector.timer

10.3 Emergency Runbook: Live-USB Chroot & UKI Rebuild

If a motherboard BIOS update wipes UEFI NVRAM boot entries or invalidates Secure Boot signatures, recover the encrypted Arch Linux installation from the Live ISO in under two minutes:

Emergency Chroot & UKI Signature Recovery from the Arch Live ISO
# 1. Set keymap and unlock the LUKS2 container
loadkeys de-latin1
cryptsetup open /dev/nvme0n1p2 cryptroot

# 2. Mount Btrfs subvolumes and the ESP (/efi) matching the production layout
BTRFS_OPTS="noatime,compress=zstd:3,ssd,discard=async,space_cache=v2"
mount -o "${BTRFS_OPTS},subvol=@"         /dev/mapper/cryptroot /mnt
mount -o "${BTRFS_OPTS},subvol=@home"     /dev/mapper/cryptroot /mnt/home
mount -o "${BTRFS_OPTS},subvol=@snapshots" /dev/mapper/cryptroot /mnt/.snapshots
mount -o "${BTRFS_OPTS},subvol=@var_log"  /dev/mapper/cryptroot /mnt/var/log
mount -o "${BTRFS_OPTS},subvol=@pkg"      /dev/mapper/cryptroot /mnt/var/cache/pacman/pkg
mount /dev/nvme0n1p1 /mnt/efi

# 3. Enter chroot, reinstall systemd-boot, rebuild UKIs, and re-sign with sbctl
arch-chroot /mnt /bin/bash -c "
  bootctl install
  mkinitcpio -P
  sbctl sign-all
  sbctl verify
"

# 4. Cleanly unmount and reboot
umount -R /mnt
cryptsetup close cryptroot
reboot