RAID — Redundant Array of Independent Disks — combines
multiple physical disks into a single logical unit to achieve redundancy,
performance, or both. On Linux, software RAID is implemented by the kernel's
MD (Multiple Devices) subsystem and managed with mdadm.
RAID protects against disk failure — not against accidental deletion, filesystem corruption, or ransomware. It is a high-availability tool, not a backup solution. RAID and backups serve different purposes and both are needed in production.
Min disks: 2
Redundancy: None
Capacity: 100% of all disks
Read/Write: Fastest — parallel I/O
Data striped across all disks. One disk fails → all data lost. Pure performance play.
Min disks: 2
Redundancy: N-1 disks can fail
Capacity: 50% (one disk worth)
Read/Write: Fast reads, normal writes
Every disk is a complete mirror. Simplest redundancy. Good for boot/OS drives.
Min disks: 3
Redundancy: 1 disk can fail
Capacity: (N-1) disks
Read/Write: Good reads, slower writes
Parity distributed across all disks. Good balance of capacity and redundancy.
Min disks: 4
Redundancy: 2 disks can fail
Capacity: (N-2) disks
Read/Write: Good reads, slowest writes
Two parity blocks. Recommended for large arrays where rebuild time is long.
Min disks: 4
Redundancy: 1 per mirror pair
Capacity: 50% of all disks
Read/Write: Fastest with redundancy
Stripes across mirrored pairs. Best performance and redundancy — costs capacity.
# Install mdadm if not present sudo dnf install -y mdadm # RHEL/CentOS sudo apt install -y mdadm # Debian/Ubuntu # Create RAID 1 (mirror) from two disks sudo mdadm --create /dev/md0 \ --level=1 \ --raid-devices=2 \ /dev/sdb /dev/sdc # Create RAID 5 from four disks sudo mdadm --create /dev/md1 \ --level=5 \ --raid-devices=4 \ /dev/sdb /dev/sdc /dev/sdd /dev/sde # Create RAID 6 — double parity sudo mdadm --create /dev/md2 \ --level=6 \ --raid-devices=6 \ /dev/sd{b,c,d,e,f,g} # Create RAID 10 — four disks sudo mdadm --create /dev/md3 \ --level=10 \ --raid-devices=4 \ /dev/sdb /dev/sdc /dev/sdd /dev/sde # Confirm creation started (sync in progress) cat /proc/mdstat/proc/mdstat during initial sync:
cat /proc/mdstat
or watch -n5 cat /proc/mdstat.
# Format the RAID device like any block device sudo mkfs.xfs /dev/md0 sudo mkfs.ext4 /dev/md1 # Mount it sudo mkdir -p /data/raid sudo mount /dev/md0 /data/raid # Save mdadm configuration (essential for persistence) sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf # or on RHEL: sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf # Update initramfs so array assembles at boot sudo update-initramfs -u # Debian/Ubuntu sudo dracut --force # RHEL/CentOS # Add to /etc/fstab for automatic mount echo "/dev/md0 /data/raid xfs defaults 0 2" | sudo tee -a /etc/fstab # Verify sudo mount -a df -h /data/raid
# Quick status of all arrays cat /proc/mdstat # Detailed status of one array sudo mdadm --detail /dev/md0 # Status of all arrays sudo mdadm --detail --scan # Check individual disk status within array sudo mdadm --examine /dev/sdb # Watch sync/rebuild progress live watch -n5 cat /proc/mdstat # Enable email alerts for RAID events sudo vi /etc/mdadm/mdadm.conf # Add: MAILADDR admin@yourdomain.com # Test email alerting sudo mdadm --monitor --scan --test --oneshotmdadm --detail /dev/md0 output:
clean = healthy,
degraded = disk failed but array operational,
recovering = rebuilding after replacement,
resyncing = initial sync or check in progress,
failed = array non-functional.
# Mark a disk as faulty (simulate failure for testing) sudo mdadm /dev/md0 --fail /dev/sdb # Check degraded status cat /proc/mdstat sudo mdadm --detail /dev/md0 # Remove the failed disk from the array sudo mdadm /dev/md0 --remove /dev/sdb # Physically replace the disk, then add the new disk sudo mdadm /dev/md0 --add /dev/sdb # Watch the rebuild watch -n10 cat /proc/mdstat/proc/mdstat during rebuild:
U in the bracket represents an active disk.
An underscore _ means that disk position is failed
or missing. For RAID 1 with 2 disks: [UU] = both
healthy, [_U] = one failed but array still running.
A hot spare sits idle in the array and automatically begins rebuilding the moment a disk fails:
# Add a spare disk to an existing array sudo mdadm /dev/md0 --add /dev/sdd # Verify spare is listed sudo mdadm --detail /dev/md0 | grep -A5 "Spare" # Create array with spare included from the start sudo mdadm --create /dev/md1 \ --level=5 \ --raid-devices=4 \ --spare-devices=1 \ /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdfmdadm --detail showing spare:
# Add a new disk to RAID 5 (increases array size) sudo mdadm /dev/md1 --add /dev/sdf # Grow the array to use the new disk sudo mdadm --grow /dev/md1 --raid-devices=5 # Watch the reshape (can take hours on large arrays) watch -n10 cat /proc/mdstat # After reshape completes — resize the filesystem # ext4: sudo resize2fs /dev/md1 # XFS (must be mounted): sudo xfs_growfs /data/raid # Verify df -h /data/raid
# Stop a RAID array (unmount first) sudo umount /data/raid sudo mdadm --stop /dev/md0 # Manually assemble an array from its member disks sudo mdadm --assemble /dev/md0 /dev/sdb /dev/sdc # Auto-assemble all arrays from config sudo mdadm --assemble --scan # Completely destroy an array (DESTRUCTIVE) sudo umount /data/raid sudo mdadm --stop /dev/md0 sudo mdadm --zero-superblock /dev/sdb sudo mdadm --zero-superblock /dev/sdc # Now disks are clean — no RAID metadata remains
# Run a periodic array check (checks parity consistency) sudo echo check > /sys/block/md0/md/sync_action # Monitor the check progress cat /proc/mdstat # Enable weekly automatic checks (already set up on most distros) cat /etc/cron.d/mdadm # Debian/Ubuntu systemctl status mdmonitor # RHEL/CentOS # Start mdadm monitor daemon (alerts on failures) sudo mdadm --monitor --scan --daemonize --mailaddr=admin@example.com # Check SMART status of member disks sudo smartctl -a /dev/sdb | grep -E "Health|Reallocated|Pending" sudo smartctl -a /dev/sdc | grep -E "Health|Reallocated|Pending" # Full health check script for dev in /dev/sd{b,c,d,e}; do echo "=== $dev ===" sudo smartctl -H "$dev" | grep "overall-health" done
| Level | Min Disks | Usable Capacity | Can Lose | Best For |
|---|---|---|---|---|
| RAID 0 | 2 | 100% of all | 0 disks | Scratch/temp — maximum speed, no redundancy |
| RAID 1 | 2 | 50% | N-1 disks | OS/boot drives, small critical data |
| RAID 5 | 3 | (N-1)/N | 1 disk | General purpose — good balance |
| RAID 6 | 4 | (N-2)/N | 2 disks | Large arrays, long rebuild times |
| RAID 10 | 4 | 50% | 1 per pair | Databases, high I/O workloads |
| Command | What it does |
|---|---|
| mdadm --create /dev/mdN --level=N --raid-devices=N /dev/sd... | Create new array |
| mdadm --detail /dev/mdN | Detailed array status |
| mdadm --detail --scan | Status of all arrays |
| cat /proc/mdstat | Quick status and sync progress |
| mdadm /dev/mdN --fail /dev/sdX | Mark disk failed (testing) |
| mdadm /dev/mdN --remove /dev/sdX | Remove failed disk |
| mdadm /dev/mdN --add /dev/sdX | Add disk (replacement or spare) |
| mdadm --grow /dev/mdN --raid-devices=N | Grow array with new disk |
| mdadm --stop /dev/mdN | Stop array |
| mdadm --assemble --scan | Reassemble all arrays from config |
| mdadm --zero-superblock /dev/sdX | Wipe RAID metadata (destructive) |
| mdadm --detail --scan | tee -a /etc/mdadm.conf | Save config for persistence |
| echo check > /sys/block/mdN/md/sync_action | Run parity check |
| Layer | Role | Example |
|---|---|---|
| Hardware/mdadm RAID | Redundancy — protects against disk failure | 4 disks → /dev/md0 (RAID 10) |
| LVM on top of RAID | Flexibility — resize, snapshot, multiple LVs | /dev/md0 → PV → VG → LVs |
| Filesystem | Data organization | XFS or ext4 on each LV |