Skip to content

RAID and Profiles

This chapter puts one filesystem on several disks, and chooses how the copies are laid out. The outcome: a profile choice you can defend, made at mkfs time or changed later by conversion. The lab built real multi-device filesystems at mkfs time — RAID1 over two images and RAID10 over four (transcript t02) — because that half needs no mount. Losing a disk on purpose, adding devices and converting a live filesystem are mounted operations, and are documented-only here, honestly labelled.

Profiles, plainly

From chapter 2, the choices that matter:

profile devices copies survives
single 1+ 1 nothing
DUP 1 2, same disk a rotten patch
RAID0 2+ 1, striped nothing
RAID1 2+ 2, mirrored one device
RAID10 4+ 2, striped mirrors one per mirror pair
RAID5/6 3+/4+ parity one/two devices, with a warning

Data and metadata carry separate profiles. The pairing most keepers choose for anything that matters is RAID1 for both — or RAID10 where there are disks and a need for speed. The mirroring is what turns chapter 2's checksums from detection into repair: a bad block with a good twin is a bad block fixed.

At mkfs time

sudo mkfs.btrfs -L vault -d raid1 -m raid1 /dev/sdX /dev/sdY

-d sets the data profile, -m the metadata profile. The lab's transcript t02 shows the resulting report: one filesystem, 800 MiB across two 400 MiB images, every profile RAID1 — and half the raw space usable, which is the honest price of a copy of everything.

Adding, removing, converting (documented-only)

On a mounted filesystem, devices join and leave while it runs:

sudo btrfs device add /dev/sdZ /mnt/vault
sudo btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt/vault
sudo btrfs device remove /dev/sdY /mnt/vault

Adding a device adds its space to the pool but does not, by itself, restripe anything — the balance (chapter 9) is what rewrites chunks under the new profile, and device remove first moves the departing disk's chunks elsewhere. A filesystem also runs degraded — one device missing, mounted with -o degraded — which is how you keep working while a replacement disk is in the post, at the price of having no second copy until it arrives.

The RAID5 and RAID6 warning, unsoftened

Btrfs's parity profiles carry a flaw with a name, the write hole: a crash or power cut in the middle of updating a stripe can leave data and parity disagreeing in a way later writes can turn into permanent corruption. Work in recent kernels (a stripe tree, in the 7.0 cycle) narrows the hole but, at the time of writing, the upstream advice has not changed: do not trust RAID5 or RAID6 with data you cannot replace, and never use them for metadata. If you need parity's space efficiency, the neighbours in chapter 13 — ZFS's RAID-Z, or mdadm under a different filesystem — solve the same problem without this particular hole. Checksums still detect parity trouble on btrfs, which is more than some filesystems offer; detection is not the same as safety, as chapter 1's rule keeps saying in different words.