Skip to content

Formatting Your First Vault

Outcome: a formatted LUKS2 vault in vault.img, and a luksDump printout you can read line by line. This is the chapter where the moving parts of chapter 2 stop being a diagram. Transcript: luks-lab/transcripts/t01-format-and-dump.txt.

Before the command: what format does

luksFormat writes the header: it invents the master key, wraps a copy of it with your first passphrase into slot 0, and marks the rest of the device as the data segment. It does not encrypt the existing contents of the device. Whatever bytes were there before are still there, now sitting inside what will become the encrypted area — readable in principle by anyone who later opens the vault, and partly readable to forensic tools before that. Two consequences:

  • Format a new device (or one whose old contents you do not mind keeping inside the vault), or overwrite the device with random data first if the old contents must die.
  • Never format a device whose current contents you need. There is no undo and no recycle bin; the filesystem that was there is gone the moment the header lands.

On real hardware the command also asks you to type YES in capitals before it proceeds. That ceremony is the last speed bump before destruction — read the device name it shows you, twice.

The format

The lab's passphrase for slot 0 lives in a small file, pass1.txt, so the commands can be scripted and repeated; on your machine you will type it interactively instead, and cryptsetup will ask twice to be sure. The passphrase itself — orange lantern festival 42 — is a lab fixture, chosen to be typed in transcripts, not a suggestion for yours (chapter 6 talks about choosing well).

cryptsetup luksFormat --type luks2 \
  --key-file pass1.txt vault.img

It prints nothing and exits 0: silence is success for most of cryptsetup. --type luks2 is stated for clarity; on any cryptsetup 2.x it is the default. Leave it out and the same vault results.

Reading the result: luksDump

cryptsetup luksDump vault.img

The lab's real output, trimmed of its salt and digest hex (which are long, random and different for every vault):

LUKS header information
Version:        2
Epoch:          3
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           032cf058-d263-40fe-9005-257e1e2752ad
Label:          (no label)

Data segments:
  0: crypt
    offset: 16777216 [bytes]
    length: (whole device)
    cipher: aes-xts-plain64
    sector: 4096 [bytes]

Keyslots:
  0: luks2
    Key:        512 bits
    Priority:   normal
    Cipher:     aes-xts-plain64
    Cipher key: 512 bits
    PBKDF:      argon2id
    Time cost:  12
    Memory:     105484
    Threads:    2
    AF stripes: 4000
    AF hash:    sha256
    Area offset: 32768 [bytes]
    Area length: 258048 [bytes]
    Digest ID:  0

Read it against chapter 2's diagram:

  • Metadata + keyslots total 16,777,216 bytes — the 16 MB header. The data segment's offset is exactly that number: the encrypted data starts where the header ends.
  • Cipher aes-xts-plain64 with a 512-bit key. XTS mode spends the 512 bits as two 256-bit AES keys — chapter 11 benchmarks it and explains why it is the default.
  • Sector 4096 — the vault encrypts in 4 KB blocks, matching modern disks; on old 512-byte-sector media a format can choose otherwise.
  • Keyslot 0 holds the wrapped master key. Its PBKDF is argon2id, calibrated on this machine to time cost 12 and about 103 MB of memory, so one guess costs roughly two seconds. AF stripes: 4000 is anti-forensic splitting: the wrapped key is smeared across 4000 stripes so that overwriting the slot leaves nothing recoverable — this is what makes killing a slot in chapter 6 a real death and not a polite note.
  • Epoch counts header rewrites. It was 3 after formatting and rose to 11 by the end of the lab's key games — a quiet counter of everything the later chapters did.

Below the keyslots, the full dump (in the transcript) shows a Digests section: a PBKDF2 checksum of the unwrapped master key, which is how an unlock attempt knows it succeeded — the passphrase that reproduces this digest opened the right key.

The LUKS1 version of the same vault

The lab formatted a second file as LUKS1 for comparison (transcript t06). Its dump is plainer and shows its age: hash sha256, payload offset 4096 — in 512-byte sectors, so 2 MB — and its slots printed as a roll call, Key Slot 0: ENABLED, slots 1 to 7 DISABLED, each with PBKDF2 iteration counts in the millions. Nothing about LUKS1 is broken — devices formatted a decade ago still open — but it has no second header copy, no Argon2, no labels or tokens, and its 2 MB header carries all eight slots or nothing. Format new vaults as LUKS2; meet LUKS1 with respect when an old disk introduces itself.

Checks before you move on

cryptsetup isLuks vault.img; echo $?
cryptsetup luksUUID vault.img

isLuks answers with its exit code — 0 for yes — which makes it the test your scripts should use. The UUID is the name the rest of the system will know this vault by; chapter 9 puts it in /etc/crypttab, because device letters change and UUIDs do not.