RAID in Linux

RAID (Redundant Array of Independent Disks) combines multiple drives to get speed, redundancy, or both. Linux's software RAID via mdadm gives you enterprise-grade storage without expensive hardware controllers. But picking the wrong RAID level can leave you with false security or terrible performance.

RAID Levels Compared

LevelMin DisksRedundancyCapacityPerformanceUse Case
RAID 02None — 1 disk fails, all data lost100% (N disks)Read+Write fast (stripes)Scratch space, cache, temp data
RAID 12N-1 disks can fail50% (1 disk effective)Read fast, write same as 1 diskBoot drives, critical small data
RAID 531 disk can fail(N-1) disks usableRead fast, write penalty (parity)General purpose with some redundancy
RAID 642 disks can fail(N-2) disks usableRead fast, higher write penaltyLarge arrays where rebuild risk is real
RAID 1041 disk per mirrored pair50% of totalBest of all — fast reads+writesDatabases, high-perf + redundancy

How Each Level Stores Data

RAID 0 — Striping (no redundancy, pure speed) Disk1: [A1][A3][A5] ← data striped across disks Disk2: [A2][A4][A6] ← lose either disk = lose all data RAID 1 — Mirroring (full copy on each disk) Disk1: [A1][A2][A3] ← exact duplicate Disk2: [A1][A2][A3] ← same data, lose either, survive RAID 5 — Striping + distributed parity Disk1: [A1][B1][P_C] ← P = parity block Disk2: [A2][P_B][C1] ← parity distributed across disks Disk3: [P_A][B2][C2] ← lose any 1 disk, reconstruct from parity RAID 10 — Mirror pairs, then stripe across pairs Pair1: Disk1=[A1] Disk2=[A1] ← mirrored pair Pair2: Disk3=[A2] Disk4=[A2] ← mirrored pair Stripe across pairs for speed, mirror for redundancy

Setting Up RAID with mdadm

# Install mdadm apt install mdadm # Debian/Ubuntu dnf install mdadm # Fedora/RHEL # Create RAID 1 (mirror) with 2 disks mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc # Create RAID 5 with 3 disks mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd # Create RAID 10 with 4 disks mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde # Watch the build progress (initial sync can take hours) watch cat /proc/mdstat # md0 : active raid5 sdd[2] sdc[1] sdb[0] # 2095104 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU] # [=======>.............] resync = 37.5% (393216/1047552) ... # Create filesystem on the array mkfs.ext4 /dev/md0 mount /dev/md0 /data

Making RAID Persistent Across Reboots

# Save RAID configuration mdadm --detail --scan >> /etc/mdadm/mdadm.conf # Add to /etc/fstab for auto-mount /dev/md0 /data ext4 defaults 0 2 # Or use UUID (safer — device names can change): blkid /dev/md0 # /dev/md0: UUID="abc-123-..." TYPE="ext4" # /etc/fstab: UUID=abc-123-... /data ext4 defaults 0 2 # Update initramfs so RAID assembles at boot update-initramfs -u # Debian/Ubuntu dracut --force # RHEL/Fedora

Monitoring and Repairing RAID

# Check RAID status cat /proc/mdstat mdadm --detail /dev/md0 # Example failed disk output: # md0 : active raid5 sdc[1] sdb[0] sdd[4](F) # ^^ F = failed # Remove failed disk and add replacement: mdadm /dev/md0 --fail /dev/sdd # mark as failed mdadm /dev/md0 --remove /dev/sdd # remove from array mdadm /dev/md0 --add /dev/sde # add replacement # Rebuild starts automatically — watch /proc/mdstat # Add a hot spare (stays idle, auto-replaces on failure): mdadm /dev/md0 --add-spare /dev/sde # When any disk fails, spare immediately starts rebuilding # Email alerts on failure: # In /etc/mdadm/mdadm.conf: # MAILADDR admin@example.com # Start monitoring daemon: systemctl enable --now mdmonitor

RAID Is Not a Backup

If RAID protects against disk failure, why do I still need backups? RAID protects against hardware failure of one or two drives. It doesn't protect against: accidental deletion (both mirrors delete), ransomware (encrypts data on all disks simultaneously), filesystem corruption (propagates to all disks), theft (entire server stolen), or catastrophic failure (multiple disks die in same power surge). Always have backups to a separate location.

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.