Software RAID with mdadm
mdadm RAID levels 0/1/5/6/10, degraded arrays, rebuild monitoring, and replacing failed drives.
Overview
Overview Software RAID uses the Linux kernel's md (multiple devices) subsystem to combine physical disks into a logical array with redundancy, performance, or both. Unlike hardware RAID controllers, software RAID is transparent, portable, and doesn't tie you to proprietary firmware.
RAID Levels
RAID 0 — Striping. Data is split across all disks in stripes. Delivers maximum throughput (reads and writes scale with disk count) but zero redundancy — one disk failure loses everything. Use for scratch/temp storage where speed matters and data is ephemeral.
RAID 1 — Mirroring. Each disk is an exact copy of the other. Tolerates one disk failure. Read throughput doubles (each disk can serve reads independently); write throughput is limited to the slowest disk. Minimum 2 disks.
RAID 5 — Distributed Parity. Data and parity are striped across all disks. Can survive one disk failure. Minimum 3 disks; usable capacity is (N-1) disks. Parity computation adds write overhead — beware write hole on unclean shutdown (mitigated by write-intent bitmaps).
RAID 6 — Dual Parity. Like RAID 5 but with two independent parity blocks per stripe. Survives two simultaneous disk failures. Minimum 4 disks. Rebuild of a RAID 5 array can itself fail during the rebuild (URE on a second disk) — RAID 6 is safer for large arrays.
RAID 10 — Striped Mirrors. RAID 1 arrays striped together. Combines mirroring redundancy with striping throughput. Minimum 4 disks. Can survive multiple failures as long as no mirror loses both disks.
Key Files
- /proc/mdstat — live rebuild progress, array state, and per-device status
- /etc/mdadm/mdadm.conf — array configuration for boot-time assembly
Key concepts
- RAID 0
- Striping — maximum throughput, zero redundancy. Any single disk failure destroys all data. Use only for ephemeral scratch space.
- RAID 1
- Mirroring — exact copy on every disk. Tolerates one failure. Read throughput scales, write throughput does not. Minimum 2 disks.
- RAID 5
- Distributed parity — parity block rotated across all disks. Tolerates one failure, usable capacity = (N-1) disks. Minimum 3 disks. Risk of data loss during rebuild if a second disk fails (URE).
- RAID 6
- Dual parity — tolerates two simultaneous failures. Preferred for arrays with 6+ large disks where rebuild time is long and URE risk is high.
- RAID 10
- Striped mirrors — combines throughput of RAID 0 with redundancy of RAID 1. Minimum 4 disks. Best for OLTP databases.
- /proc/mdstat
- Live kernel view of all md arrays. Shows state (clean, degraded, recovering), rebuild speed, and ETA. Monitor with watch -n1 cat /proc/mdstat.
When to use it
- Replacing a failed disk in a production RAID 1 or RAID 5 array — mdadm --remove then --add
- Diagnosing why a server is running slow — degraded RAID array causes write penalty; check /proc/mdstat
- Deciding between RAID levels for a new database server — RAID 10 for OLTP, RAID 6 for capacity-optimised storage
- Monitoring rebuild progress after a disk replacement — watch /proc/mdstat or mdadm --detail
Interview questions
- How do you replace a failed disk in a software RAID 5 array using mdadm?
- What is the difference between RAID 5 and RAID 6, and when would you choose one over the other?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio