Software RAID (mdadm) in practice: building RAID1, simulating a disk failure online, and hot rebuilding
What you will learn
Section titled “What you will learn”The complete mdadm software-RAID operations loop: build → use → disk dies → rebuild online. Everything was measured on loopback devices (no real disks affected), and the method transfers directly to production disks.
Building RAID1
Section titled “Building RAID1”dnf install -y mdadmmdadm --create /dev/md0 --level=1 --raid-devices=2 --run /dev/sdb /dev/sdccat /proc/mdstat# md0 : active raid1 sdb[0] sdc[1]# 101376 blocks super 1.2 [2/2] [UU][UU] = both disks healthy. A newly created array shows resync=PENDING — a background-sync backlog that does not block IO.
mdadm --detail /dev/md0 | grep -E "Raid Level|State|Active Devices"# Raid Level : raid1# State : clean, resyncing (PENDING)# Active Devices : 2The filesystem works as usual:
mkfs.ext4 /dev/md0 && mount /dev/md0 /mnt && echo ok > /mnt/t.txtThe dead disk and hot rebuild (the main act)
Section titled “The dead disk and hot rebuild (the main act)”mdadm /dev/md0 --fail /dev/sdc # mark failed (simulating a bad disk)mdadm /dev/md0 --remove /dev/sdc # pull it outmdadm --detail /dev/md0 | grep -E "State|Active"# State : active, degraded, resyncing (PENDING)# Active Devices : 1The degraded state stays readable and writable (raid1 keeps serving from the single disk) — this is RAID1’s moment of value. Swap in a new disk:
mdadm /dev/md0 --add /dev/sdd # hot-insert and joinmdadm --detail /dev/md0 | grep -E "State|Active"# State : active, rebuilding# Active Devices : 2 ← rebuilding online, no umount neededThe rebuild completes back to [UU]. Service never interrupted throughout (measured: the ext4 mount stayed available).
Operations quick reference
Section titled “Operations quick reference”| Task | Command |
|---|---|
| The global view | cat /proc/mdstat |
| One array’s details | mdadm --detail /dev/md0 |
| Which array owns a disk | mdadm --examine /dev/sdb |
| Persist the config (auto-assembly after reboot) | mdadm --detail --scan >> /etc/mdadm.conf |
| Trigger a full check manually | echo check > /sys/block/md0/md/sync_action |
Evidence and limits on this page
Section titled “Evidence and limits on this page”- Measured: the RAID1 full cycle (build/write/degrade/hot rebuild) on loopback devices (E3);
- Not measured: real physical-disk hot-swap, RAID5/10 topologies, bitmap acceleration;
- Sources:
mdadm(8), OL10 storage documentation.