Chapter 13. LVM, Software RAID, and Disk Encryption

A raw disk that Chapter 11 partitioned and Chapter 12 formatted can carry more than a filesystem. The kernel can combine several disks into one redundant device, wrap any device in an encrypted container, and pool the result into resizable named volumes - each layer consuming the block device below it and publishing a new one. Three Debian technologies do this work: the md (Multiple Devices) driver for software RAID, LVM for volume management, and LUKS2 for encryption through the device-mapper framework. This chapter builds each layer on its own practice disks, then combines them into one stack, and finally examines what happens when the stack has to assemble itself at boot or survive a failure.

The examples run on one Debian 13 system named layers (kernel 6.12.86+deb13-amd64, lvm2 2.03.31-2, mdadm 4.4-11, cryptsetup 2.7.5-2, thin-provisioning-tools 1.1.0-4+b1, e2fsprogs 1.47.2-3+b12, util-linux 2.41.5-0+deb13u1). Its root filesystem sits untouched on /dev/vda. Attached to it are six empty 2 GiB virtio disks, /dev/vdb through /dev/vdg, that every destructive example in this chapter targets. If you follow along, use spare disks or a disposable machine: everything written to these six devices is erased, sometimes several times over. Every captured output comes from one complete run of that sequence, so the identifiers the layers generate - PV, VG, LV, array, and container UUIDs - plus timestamps and momentary figures such as resync progress and pool usage belong to that run; following the same steps prints the same shapes with fresh values. The commands are identical on physical SATA, SAS, NVMe, and USB disks; the practice hardware being virtual only affects things like SMART health data, which Chapter 11 Section 11.1.4 already covered.

Device Size Role in this chapter
/dev/vdb, /dev/vdc 2 GiB each LVM physical volumes for the group vgdata (Section 13.2)
/dev/vdd, /dev/vde, /dev/vdf 2 GiB each RAID members: a RAID5 capacity check, then the RAID1 array md0 in which /dev/vde fails and /dev/vdf replaces it (Section 13.3), and finally the base of the combined stack (Section 13.5)
/dev/vdg 2 GiB LUKS2 encrypted data volume (Section 13.4)

Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker itself is not typed. From john's shell, sudo -i enters the root shell that most of this chapter works in, and exit leaves it. john's account and its sudo access were established during installation (Chapter 2 created them; Chapter 5 covers the sudo policy in depth). A single elevated command is written $ sudo command. The chapter assumes Chapter 3's shell operations - including pipelines, > and >> redirection, and quoting - plus Chapter 11's habits of identifying a device before writing to it and preferring stable names over /dev/vdb-style ones. Files created for the exercises belong to john under ~/debian-handbook/storage-layers, created before the first example needs it:

$ mkdir -p ~/debian-handbook/storage-layers
$ cd ~/debian-handbook/storage-layers

Neither command prints anything. The tools come from four packages beyond a base installation; install them with Chapter 6's ordinary interactive procedure and answer the confirmation prompt when it appears:

$ sudo apt install lvm2 mdadm cryptsetup thin-provisioning-tools

lvm2 provides the LVM commands and the device-mapper plumbing they build on; mdadm manages md arrays; cryptsetup pulls in cryptsetup-bin (the cryptsetup command) and cryptsetup-initramfs (the boot-time unlock integration examined in Section 13.5.1); thin-provisioning-tools supplies the thin-pool maintenance helpers that LVM invokes when activating thin pools. The ext4 tools (e2fsprogs) and lsblk, findmnt, blkid, wipefs, and fsfreeze (util-linux) are part of every Debian base system. apt prints its usual plan and download and configuration progress - Chapter 6 showed full install transcripts - and the exact lines depend on what is already installed, so they are not reproduced here.

In this section