Advanced Storage Device Administration
Advanced Storage Device Administration covers software RAID with mdadm, LVM's physical-volume/volume-group/logical-volume model, and the device-mapper layer beneath both.
RAID and LVM mechanics
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1builds a redundant array./proc/mdstatshows status;mdadm --detail /dev/md0gives detail.- Persist assembly with
mdadm --detail --scan >> /etc/mdadm.confand rebuild initramfs so the array assembles before root mounts. - Replace a failed disk with
--fail,--remove, then--add; grow with--grow --raid-devices=4plus a filesystem resize. - LVM stack:
pvcreate,vgcreate,lvcreate -L 20G -n data vg. Extend withlvextend -L +5G /dev/vg/dataor-l +100%FREE, then resize the filesystem. - Snapshots:
lvcreate -L 2G -s -n snap /dev/vg/data; size for changed blocks, not original data. pvmovemigrates extents;vgchange -a yactivates volume groups.
Worked example
Create RAID5, put LVM on it, and use all space: mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1; pvcreate /dev/md0; vgcreate vg /dev/md0; lvcreate -l 100%FREE -n lv vg; mkfs.ext4 /dev/vg/lv. Reasoning: mdadm supplies redundancy, LVM supplies flexible allocation; keep mdadm.conf and initramfs current so early boot can assemble /dev/md0.
Traps
- Forgetting initramfs after changing RAID or LVM root storage.
- Filling a snapshot, which invalidates it.
- Running
lvreducebefore shrinking the filesystem. - Treating RAID as a backup.