Chapter 14. Capacity Changes and Storage Migration

A storage stack is not a single object. A disk publishes a block device, a partition table slices it, md RAID may combine several slices, LUKS may encrypt the result, LVM may pool it into named volumes, and a filesystem sits on top. Changing capacity means changing every layer that stands between the physical medium and the files. A layer can only use space that the layer below it has already made visible, and an outer layer can only be reduced after the data inside it has been moved or shrunk. The order is therefore not a matter of preference; it is what keeps the filesystem from being truncated.

This chapter applies that order to growth, reduction, and migration. It also covers the point where the device name changes: fstab, crypttab, service dependencies, initramfs, and the boot loader. The examples use one Debian 13 system named migrate (kernel 6.12.86+deb13-amd64), whose root filesystem remains on /dev/vda1. Thirteen disposable virtual disks are attached for the exercises:

Device Size Role
/dev/sda 2 GiB, SCSI GPT partition and ext4 growth; expanded to 4 GiB later
/dev/vdb 2 GiB XFS growth, then a duplicate-identifier exercise
/dev/vdc, /dev/vdd 2 GiB each RAID1 members under LUKS and LVM
/dev/vde 2 GiB old LVM physical volume for pvmove
/dev/vdf 4 GiB replacement LVM physical volume
/dev/vdg, /dev/vdh 2 GiB each two-device Btrfs filesystem
/dev/vdi 2 GiB Btrfs replacement device
/dev/vdj 4 GiB replacement RAID1 member
/dev/vdk, /dev/vdl 2 GiB each file-migration source and target
/dev/vdm 2 GiB disposable new-root disk

Every byte on these disks is erased during the exercises. Use spare disks or a disposable machine, and do not follow the destructive steps on a disk that holds data you have not backed up. The identifiers in the captured output - UUIDs, array UUIDs, timestamps, and momentary progress figures - belong to one run; repeating the sequence produces new values with the same shape.

Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker is not typed. john's account and sudo access were established during installation (Chapter 2) and are described in Chapter 5. From john's shell, sudo -i enters a root shell and exit leaves it. A single elevated command is written $ sudo command. The examples assume the device-inspection and mount habits from Chapter 11, the filesystem-specific tools from Chapter 12, and the layer concepts from Chapter 13.

Create the reader workspace before the first example:

$ mkdir -p ~/debian-handbook/storage-migration

The command prints nothing.

$ cd ~/debian-handbook/storage-migration

Changing directory prints nothing. The tools come from packages beyond a base installation; install them with the ordinary interactive procedure from Chapter 6 and answer the confirmation prompt:

$ sudo apt install lvm2 mdadm cryptsetup cryptsetup-initramfs btrfs-progs xfsprogs rsync acl attr parted gdisk initramfs-tools grub-pc-bin grub2-common

gdisk supplies sgdisk, parted supplies the partition editor, btrfs-progs and xfsprogs supply the filesystem-specific commands, and acl and attr supply getfacl, setfacl, getfattr, and setfattr. cryptsetup-initramfs is only a suggestion of cryptsetup, so apt does not install it on its own; its hook is what places the encryption module and tools in the initramfs. grub-pc-bin supplies the BIOS GRUB modules used in Section 14.5.2, and grub2-common supplies update-grub, which that section also runs. apt prints its usual plan and progress; the exact lines depend on what is already installed and are not repeated here.

The examples also need an encrypted practice volume. Its key material is kept in a root-owned file rather than in john's home, because a file that unlocks a volume is a secret even when the volume is disposable:

# install -d -m 700 /etc/luks-keys

The command is silent.

# head -c 64 /dev/urandom > /etc/luks-keys/stack.key

The redirection writes 64 random bytes to the file and prints nothing.

# chmod 400 /etc/luks-keys/stack.key

The command is silent. ls -l /etc/luks-keys/stack.key would show mode -r-------- and root ownership. The --pbkdf-memory 262144 option used when formatting the practice volume keeps its Argon2 cost within a machine with 2 GiB of RAM; on a production volume, use the default cryptsetup selects for the host.

In this section