Skip to content

Resizing and Other Surgery

Outcome: you know which operations on a living vault are safe, which are possible, and which order to do them in. Mixed evidence, labelled as it goes: conversion and labels ran in the lab (transcripts t09–t11); resizing works on an open device, so on the lab's machine it met the same device-mapper wall as chapter 5 (t08) and is taught from the documentation.

Growing a vault

The one-sentence version: the container grows first, then the mapping, then the filesystem — each layer can only expand into space the layer beneath has already granted. Concretely, for a vault in a file (or an LVM volume, or a partition you have already enlarged with a partition editor):

  1. Enlarge the underlying thing — more bytes in the file, a bigger logical volume, a grown partition.
  2. With the vault open, tell device-mapper the device is longer now: bash sudo cryptsetup resize vault (Optionally --size to grow by an exact amount instead of to the end.)
  3. Grow the filesystem into the new room: resize2fs /dev/mapper/vault for ext4, xfs_growfs for XFS, btrfs filesystem resize max for Btrfs.

Shrinking is the same film backwards — filesystem first, then mapping, then container — and is the operation most likely to eat a filesystem if a step is hurried or the arithmetic is off by a sector. The standing advice: grow freely, shrink reluctantly, and let chapter 8's backup habit precede either. Note also what resizing never touches: the header does not move, and the data segment simply extends — no slot, key or passphrase notices anything happened.

The lab's resize attempt, for the record, is in transcript t08: Cannot initialize device-mapper, exit 4 — the sandbox boundary again, not a property of the command.

Converting LUKS1 to LUKS2

Old disks deserve the second header and the better derivation. Conversion is header surgery that runs entirely on the closed device — the lab ran it for real (t10):

cryptsetup convert --type luks2 vault1.img

It asks for YES, and what comes back is instructive. The UUID is preserved — the vault's identity in /etc/crypttab and the world's records survives its own upgrade. The data offset is preserved too (2 MiB, where LUKS1 put it; the LUKS2 header learns to live in the room it is given, keyslot area and all), as is the 512-byte sector size. The passphrases all still test clean. What conversion does not do is upgrade the slots' derivation: the converted keyslot kept PBKDF2 with its original iteration count, because conversion moves the furniture without re-deriving anyone's keys.

That last step is a separate tool, and it also ran (t11):

cryptsetup luksConvertKey \
  --key-file pass1.txt \
  --pbkdf argon2id vault1b.img

Slot 0 came back Argon2id; slot 1, untouched, still shows PBKDF2 — slots are independent citizens, and mixed derivation in one header is a normal state of affairs. Convert a device, then convert its keys at your leisure, proving each with --test-passphrase as you go. And per chapter 8's rule: a fresh header backup after the surgery, because the old backup now describes a LUKS1 device that no longer exists.

Labels

A LUKS2-only nicety, also run live (t09):

cryptsetup config \
  --label 'practice vault' vault.img

The label lives in the header's metadata and shows in every luksDump. It changes nothing about security or unlocking; it is the difference between a drawer of disks named by UUID and a drawer of disks that introduce themselves. On a multi-disk machine, that difference is worth the ten seconds it costs.

The operation this chapter won't teach

cryptsetup reencrypt exists: it changes the master key itself, rewriting every byte of the data segment in the process — hours on a large disk, with the machine one power cut away from a state no chapter can save. It has legitimate uses (a master key believed compromised) and its own documentation, written by people who support it. This guide's position is the honest one: know that it exists, know that it is the only operation that changes the master key, and treat the need for it as a restore-from-backup conversation first. Everything else in this guide was designed, by the slot machinery itself, so that you would never need it for ordinary key hygiene.