How to Set Up RAID 1 on Linux with mdadm (A Mirror That Survives a Dead Drive)

ZFS (tutorial 97) is the richer choice, but there are reasons to use plain Linux software RAID instead: you want ext4 with tools you already know, the machine is low on RAM, or you're mirroring the system disk. mdadm builds a RAID 1 mirror from two drives; the result is one block device you format and mount as normal, and when one drive dies the server doesn't notice until you read the email.
Quick reference
| Task | Command | |
|---|---|---|
| Install | sudo apt install mdadm -y | |
| Create a mirror | sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc | |
| Watch it build | cat /proc/mdstat | |
| Save the config | `sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf + update-initramfs -u` |
| Status | sudo mdadm --detail /dev/md0 | |
| Replace a disk | --fail, --remove, then --add the new one |
1. Install and identify
sudo apt install mdadm -y
lsblk -d
Two drives, ideally the same size. Everything on them will be erased. Confirm sdb and sdc are the right ones (lsblk -f shows anything mounted).
2. Create the array
sudo wipefs -a /dev/sdb /dev/sdc
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
cat /proc/mdstat
It starts syncing the two drives immediately ([==>....] with a time estimate). You can use the array straight away; the sync carries on in the background. A 4 TB mirror takes several hours.
3. Format and mount
sudo mkfs.ext4 -L data /dev/md0
sudo mkdir -p /mnt/data
sudo mount /dev/md0 /mnt/data
sudo chown john:john /mnt/data
4. Make it survive a reboot
Without this, the array may come back as /dev/md127 or not at all:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
Then fstab, by UUID as always (tutorial 22):
sudo blkid /dev/md0
sudo nano /etc/fstab
UUID=... /mnt/data ext4 defaults,nofail 0 2
sudo umount /mnt/data && sudo mount -a to prove it.
5. Get told when a drive fails
mdadm can email you, using the server's mail setup (tutorial 49):
sudo nano /etc/mdadm/mdadm.conf
MAILADDR you@example.com
sudo systemctl restart mdmonitor
sudo mdadm --monitor --scan --test --oneshot
The last command sends a test email. From now on a degraded array emails you within a minute. Also add cat /proc/mdstat to your monthly review (tutorial 39).
6. When a drive fails
cat /proc/mdstat shows [U_] instead of [UU], and mdadm --detail /dev/md0 names the faulty device. The data is fine and still mounted. Swap the drive (shut down if the box isn't hot-swap), then:
sudo mdadm --manage /dev/md0 --fail /dev/sdc # if it isn't already marked
sudo mdadm --manage /dev/md0 --remove /dev/sdc
sudo mdadm --manage /dev/md0 --add /dev/sdc # the new drive, same name or whatever it got
cat /proc/mdstat
It resyncs onto the new disk. Until that finishes, you're on one drive — don't delay.
RAID is not backup
A mirror protects against a dead drive. It cheerfully mirrors a deleted folder, a ransomware encryption and a typo'd rm -r onto both disks instantly. Keep the backups (tutorials 23, 54, 55).
RAID 1 or ZFS mirror?
| mdadm RAID 1 | ZFS mirror | |
|---|---|---|
| Silent corruption | not detected | detected and repaired |
| Snapshots | no (LVM on top can) | yes, instant |
| RAM | tiny | likes a few GB |
| System disk | yes, easily | possible, fiddly |
| Tools | ext4, everything you know | its own, worth learning |
Data drives: ZFS. A mirrored boot disk or a low-memory box: mdadm.
Troubleshooting
Array came up as /dev/md127. The config wasn't saved to mdadm.conf / initramfs. Do step 4; fstab by UUID still works either way.
"Device or resource busy" on create. Something is using the disk — an old array signature. wipefs -a and mdadm --zero-superblock on each drive.
Sync is slow. Normal for spinning drives. echo 200000 | sudo tee /proc/sys/dev/raid/speed_limit_min to prioritise it.
Both drives from the same batch failed within a month. It happens. Mix brands or purchase dates for the two halves of a mirror.
Wrapping up
Install, create the mirror, format, save the config, fstab with nofail, MAILADDR for the alert. The array is just a disk to everything else on the server, and the day a drive dies you'll find out from an email, not from a server that won't boot.
