Linux Software RAID with mdadm: Complete Setup Guide
RAID (Redundant Array of Independent Disks) combines multiple disks to achieve either performance (RAID 0), redundancy (RAID 1), or both (RAID 5, 10). On Linux, you can build Software RAID for free using mdadm — no hardware RAID controller required.
Any VPS with multiple block storage volumes can use mdadm to create a RAID array. I've run RAID 1 on a production server for years — once a disk failed silently in the middle of the night, the server kept serving traffic without interruption and rebuilt itself by morning.
RAID Level Comparison
| RAID | Min Disks | Performance | Fault Tolerance | Usable Space |
|---|---|---|---|---|
| RAID 0 | 2 | Read/Write 2x faster | None — one failure loses everything | 100% |
| RAID 1 | 2 | Faster reads, slight write overhead | Up to n-1 disk failures | 50% |
| RAID 5 | 3 | Fast reads, moderate writes | 1 disk failure | (n-1)/n |
| RAID 6 | 4 | Fast reads, slower writes than RAID 5 | 2 disk failures | (n-2)/n |
| RAID 10 | 4 | Fastest overall | 1 per mirror pair | 50% |
Install mdadm
# Ubuntu / Debian
apt update && apt install -y mdadm
# CentOS / AlmaLinux / Rocky
dnf install -y mdadm
# Verify
mdadm --version
Create a RAID 1 Array (Mirroring)
RAID 1 is the best choice for data disks on a VPS — data is written identically to both drives. If one fails, the other has a complete copy:
Step 1 — Prepare the Disks
# List available disks
lsblk
# Remove any existing RAID superblocks
mdadm --zero-superblock /dev/sdb /dev/sdc
# Wipe partition tables
wipefs -a /dev/sdb
wipefs -a /dev/sdc
Step 2 — Create the RAID 1 Array
# Create RAID 1 from /dev/sdb and /dev/sdc
mdadm --create /dev/md0 \
--level=1 \
--raid-devices=2 \
/dev/sdb /dev/sdc
# Type 'y' to confirm
# Check status
cat /proc/mdstat
Step 3 — Format and Mount
# Format as ext4
mkfs.ext4 /dev/md0
# Create mount point
mkdir -p /data
# Mount
mount /dev/md0 /data
# Save mdadm config (critical — needed for boot)
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
# Update initramfs
update-initramfs -u
# Add to /etc/fstab
echo '/dev/md0 /data ext4 defaults,nofail 0 2' >> /etc/fstab
nofail in fstab so the system boots normally even if the RAID array has issues, instead of dropping to an emergency shell.Create a RAID 5 Array (Striping with Parity)
RAID 5 requires at least 3 disks and gives you (n-1)/n usable space — e.g., three 1TB disks yields 2TB of usable storage:
# Create RAID 5 from 3 disks
mdadm --create /dev/md1 \
--level=5 \
--raid-devices=3 \
/dev/sdb /dev/sdc /dev/sdd
# Monitor initial sync (this will take time)
watch cat /proc/mdstat
Add a Hot Spare Disk
A hot spare sits idle in the array and automatically begins rebuilding as soon as a member disk fails:
# Add a hot spare to RAID 1
mdadm --add /dev/md0 /dev/sdd
# Verify spare status
mdadm --detail /dev/md0
Simulate and Rebuild a Failed Disk
# Mark a disk as faulty (simulates failure)
mdadm --manage /dev/md0 --fail /dev/sdb
# Remove the failed disk
mdadm --manage /dev/md0 --remove /dev/sdb
# Check status (will show [_U] = degraded)
cat /proc/mdstat
# Add replacement disk (rebuild starts automatically)
mdadm --manage /dev/md0 --add /dev/sdb
# Watch rebuild progress
watch -n5 cat /proc/mdstat
Configure Email Alerts
# Edit /etc/mdadm/mdadm.conf
# Add this line
MAILADDR [email protected]
# Enable mdmonitor service
systemctl enable --now mdmonitor
# Test the alert
mdadm --monitor --test /dev/md0
Verify RAID Is Working Correctly
# Check all arrays at once
cat /proc/mdstat
# Detailed status of a specific array
mdadm --detail /dev/md0
# Inspect superblock on a disk
mdadm --examine /dev/sdb
# List all arrays
mdadm --detail --scan
# Confirm filesystem is mounted
df -hT /data
# Check RAID event logs
journalctl -u mdmonitor --since "1 hour ago"
/proc/mdstat, [UU] means all disks are healthy. [_U] means the array is degraded (first disk failed) — address this immediately to restore redundancy before a second failure causes data loss.Troubleshooting Common Errors
Error: "mdadm: Cannot open /dev/sdb: Device or resource busy"
The disk is in use or retains an old RAID superblock from a previous setup.
# Check for open file handles
lsof /dev/sdb
umount /dev/sdb 2>/dev/null
# Remove old RAID superblock
mdadm --zero-superblock /dev/sdb
# Wipe all partition signatures
wipefs -a /dev/sdb
# Retry array creation
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
Error: Array doesn't assemble after reboot
The mdadm.conf was never written, or initramfs wasn't updated after creating the array.
# Assemble manually
mdadm --assemble --scan
# Or specify devices explicitly
mdadm --assemble /dev/md0 /dev/sdb /dev/sdc
# Regenerate the config file
mdadm --detail --scan > /etc/mdadm/mdadm.conf
# Rebuild initramfs
update-initramfs -u # Debian/Ubuntu
dracut --force # CentOS/RHEL
Error: "mdadm: /dev/md0 appears to contain an ext2fs file system"
mdadm detected an existing filesystem on the device and is asking for confirmation before overwriting it.
# Force creation (ALL DATA WILL BE LOST)
mdadm --create --force /dev/md0 \
--level=1 --raid-devices=2 \
/dev/sdb /dev/sdc
RAID is degraded and rebuild is extremely slow
The default kernel speed limits throttle rebuilds to protect I/O performance. Raise the limits:
# Check current limits
cat /proc/sys/dev/raid/speed_limit_min
cat /proc/sys/dev/raid/speed_limit_max
# Raise limits (KB/s)
echo 50000 > /proc/sys/dev/raid/speed_limit_min
echo 200000 > /proc/sys/dev/raid/speed_limit_max
# Make permanent in /etc/sysctl.conf
echo 'dev.raid.speed_limit_min = 50000' >> /etc/sysctl.conf
echo 'dev.raid.speed_limit_max = 200000' >> /etc/sysctl.conf
Error: "no devices found for /dev/md0" after kernel update
The initramfs doesn't include the updated mdadm configuration.
# Boot into rescue mode, then run
mdadm --detail --scan > /etc/mdadm/mdadm.conf
update-initramfs -u
reboot
Frequently Asked Questions
How does Software RAID differ from Hardware RAID?
Hardware RAID uses a dedicated controller card to compute parity independently, offloading work from the server CPU. Software RAID uses the kernel's md driver, consuming CPU cycles on the host. The advantage: it's free, portable (move disks to another machine instantly), and not tied to proprietary drivers. Modern Linux Software RAID performs comparably to hardware RAID for most sequential workloads.
Can I use RAID 1 with cloud block storage volumes on a VPS?
Yes. Cloud block volumes (e.g., AWS EBS, Hetzner Volumes) behave like regular block devices to the OS. That said, most cloud providers already have redundancy at the infrastructure level (Ceph, SAN). RAID 1 on top still benefits read performance since mdadm can serve reads from both mirrors simultaneously.
Does RAID replace backups?
No. RAID protects against disk hardware failure only. Accidental deletion, filesystem corruption, ransomware, or a mistyped rm -rf will replicate instantly across all RAID members. You need both RAID for hardware protection and backups for everything else. See VPS Backup Strategy for a complete approach.