A disk has died in your mdadm array and the machine is still up, which is exactly what RAID is for — but a degraded array has no redundancy left, so the clock is running. The order matters: read the real array state, prove which physical disk failed before you touch the chassis, mark it failed and remove it, swap it, copy the partition layout onto the replacement, add it back, and watch the resync to 100%. If the dead disk was in the boot path there is one more step almost everyone skips and discovers at the next reboot: reinstall the bootloader. Every command below is paired with the output that tells you it worked.
What you’ll accomplish
- A correct read of the array state from
/proc/mdstatandmdadm --detail: degraded, rebuilding, or fine. - The failed member mapped to a serial number and a physical bay before anything is unplugged.
- A replacement disk partitioned like the survivor, added to the array, and resynced back to
[UU]. - A bootloader on both disks, so the machine still starts when the other one dies.
- Failure notifications wired up, so you learn about the next dead disk by email rather than by outage.
Prerequisites
- Root or
sudo,mdadm4.1 or newer (mdadm --version), andsmartmontoolsinstalled. - For GPT disks,
gdisk(which providessgdisk); for MBR disks,sfdiskfromutil-linux. Check which you have withsudo parted /dev/sda print | head -6— thePartition Table:line readsgptormsdos, and the cloning command differs for each. - Know whether your hardware is hot-swap: SAS and SATA backplanes with drive trays generally are, a desktop with disks screwed to a cage is not. If unsure, power the machine off — nothing here requires the array to stay online.
- A replacement disk at least as large as the partition it replaces; larger is fine, and the extra space sits unused until you grow the array.
- A backup you have restored from at least once. A rebuild is the most demanding thing you will ever ask the surviving disks to do, and a bad moment to discover the backup never worked.
- If you are building the mirror rather than repairing one, start from our mdadm RAID1 setup guide instead.
How it works
An md array is a kernel block device assembled from members that each carry a small superblock — metadata version 1.2 sits 4 KB from the start of the partition. It records the array UUID, this member’s slot number, the array state, and an event counter that increments on every state change. Assembly is a vote: the kernel gathers every device carrying that UUID, compares event counters, and admits the ones that agree. A member that missed writes is refused.
When a member starts returning I/O errors, md marks it faulty and drops it from the array. The array keeps serving from the remaining members — this is the degraded state, [U_] in /proc/mdstat instead of [UU]. Nothing is lost, but nothing is protected either.
Adding a replacement starts a recovery: on RAID1 and RAID10 that copies every block from a survivor onto the new member; on RAID5 and RAID6 it reads every block of every survivor and recomputes the missing stripe. Until it reaches 100% you are still degraded, and a read error on a survivor mid-recovery is exactly the failure mode that kills arrays.
In /proc/mdstat, resync makes existing members agree after an unclean shutdown, recovery fills in a new member, and check is a scrub that counts mismatches without changing anything.
Step-by-step
1. Read the array state before doing anything else. /proc/mdstat is the fastest true answer:
cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1](F) sda1[0]
1953382464 blocks super 1.2 [2/1] [U_]
bitmap: 8/15 pages [32KB], 65536KB chunk
unused devices: <none>
[2/1] means two members expected, one present. [U_] shows slot 0 up and slot 1 down. The (F) after sdb1[1] is the faulty flag. If you see [UU] and no (F), the array is fine and your problem is elsewhere.
2. Confirm with the full detail view. It gives the array UUID and the per-slot table:
sudo mdadm --detail /dev/md0
Version : 1.2
Array Size : 1953382464 (1862.89 GiB 2000.26 GB)
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
UUID : 9b6b4c2e:3a1f7d05:88c1e4aa:5f20d3b7
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
- 0 0 1 removed
1 8 17 - faulty /dev/sdb1
State : clean, degraded with one faulty row is the expected picture. If it says active, degraded, recovering, a rebuild is already running — let it finish before touching anything.
3. Prove which physical disk failed. This step separates a routine swap from a total loss. Kernel names such as /dev/sdb are assigned in discovery order and can change across reboots; serial numbers cannot.
lsblk -o NAME,SIZE,TYPE,SERIAL,MODEL
ls -l /dev/disk/by-id/ | grep -w sdb
sudo smartctl -i /dev/sdb
lrwxrwxrwx 1 root root 9 Aug 3 02:41 ata-ST2000NM000A-2MP166_WFL2K8YQ -> ../../sdb
Device Model: ST2000NM000A-2MP166
Serial Number: WFL2K8YQ
Write that serial down. A dead drive often will not answer smartctl at all; then identify by elimination — read the serials of every disk that does answer, and the missing one is what you pull. To catch the next failure earlier, see our guide to monitoring disk health with smartctl.
4. Mark the member failed, then remove it. The kernel usually sets the faulty flag itself, but --remove refuses a member still considered active, so run both:
sudo mdadm --manage /dev/md0 --fail /dev/sdb1
sudo mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0
mdadm: hot removed /dev/sdb1 from /dev/md0
cat /proc/mdstat should now show no reference to sdb1 at all. If the disk holds partitions belonging to several arrays, repeat this for each one before pulling it.
5. Detach and swap the disk. On a hot-swap chassis, tell the kernel to let go first, so it stops retrying I/O against a disk that is about to vanish:
echo 1 | sudo tee /sys/block/sdb/device/delete
lsblk | grep sdb
The lsblk line should return nothing — the device is gone from the kernel’s view. Now pull the tray whose serial matches and slide the replacement in. Without hot-swap, shut down cleanly (sudo shutdown -h now), swap, and boot; the array comes up degraded, which is expected.
6. Copy the partition layout onto the new disk. The replacement arrives blank, so clone the survivor’s table: the new partitions land in the same places with the same type codes. For GPT, sgdisk replicates the table and then gives the copy fresh identifiers — skip the second command and two disks claim the same GUIDs, which confuses blkid and the boot process:
sudo sgdisk --replicate=/dev/sdb /dev/sda
sudo sgdisk --randomize-guids /dev/sdb
sudo partprobe /dev/sdb
The operation has completed successfully.
For MBR disks, sfdisk does it in one pipe:
sudo sfdisk --dump /dev/sda | sudo sfdisk /dev/sdb
Verify before continuing:
lsblk /dev/sda /dev/sdb
Both disks should show the same partition names and sizes. If the new disk was previously in another array, clear its stale metadata with sudo mdadm --zero-superblock /dev/sdb1, or the kernel may assemble something you did not ask for.
7. Add the new member. One command starts the rebuild:
sudo mdadm --manage /dev/md0 --add /dev/sdb1
mdadm: added /dev/sdb1
8. Watch the recovery and tune it if you need to. The progress line appears immediately:
cat /proc/mdstat
md0 : active raid1 sdb1[2] sda1[0]
1953382464 blocks super 1.2 [2/1] [U_]
[==>..................] recovery = 12.7% (248451072/1953382464) finish=142.3min speed=199642K/sec
speed= and finish= are the numbers that matter. md throttles rebuilds so they do not starve production I/O, using two sysctls in KB/s per device; the defaults (floor 1000, ceiling 200000) are conservative today. Raise the floor when the array is idle and the rebuild is crawling:
sudo sysctl -w dev.raid.speed_limit_min=100000
sudo sysctl -w dev.raid.speed_limit_max=500000
dev.raid.speed_limit_min = 100000
dev.raid.speed_limit_max = 500000
Watch speed= change within a few seconds. Raising the floor really does take bandwidth from applications, so put it back afterwards. To block a script until the rebuild finishes, use sudo mdadm --wait /dev/md0.
9. Reinstall the bootloader on the new disk. md mirrors partition contents, not the boot code that lives outside any partition. A new disk has an empty boot sector, so if the survivor dies before you fix this, the machine will not boot even though the data is intact. On a BIOS/MBR system:
sudo grub-install /dev/sdb
sudo update-grub
Installing for i386-pc platform.
Installation finished. No error reported.
On UEFI the layout differs from the BIOS example used so far. The EFI system partition is plain FAT on each disk rather than an md member — typically partition 1, with the md member on partition 2 — so on a UEFI host the array you rebuilt above would be /dev/sdb2, not /dev/sdb1. Confirm your own layout before running any mkfs, because formatting an md member instead of an ESP destroys the copy you just resynced:
lsblk -f /dev/sdb
The ESP is the small vfat partition; the md member shows a linux_raid_member filesystem type. With that confirmed, rebuild the ESP copy on the new disk and register it:
sudo mkfs.vfat -F32 /dev/sdb1
sudo mount /dev/sdb1 /mnt
sudo rsync -a /boot/efi/ /mnt/
sudo umount /mnt
sudo efibootmgr -v
efibootmgr -v should list a boot entry per disk. On Debian and Ubuntu, sudo dpkg-reconfigure grub-efi-amd64 lets you tick both ESPs so kernel updates keep them in step.
10. Handle a dying-but-alive disk differently. If SMART is warning you but the disk still reads, do not fail it. --replace copies onto the incoming member while the outgoing one is still in the array, so you never drop to degraded:
sudo mdadm --manage /dev/md0 --add /dev/sdc1
sudo mdadm --manage /dev/md0 --replace /dev/sdb1 --with /dev/sdc1
cat /proc/mdstat
md0 : active raid1 sdc1[2](R) sdb1[1] sda1[0]
1953382464 blocks super 1.2 [2/2] [UU]
[=>...................] recovery = 6.1% (119537216/1953382464) finish=161.2min speed=189421K/sec
The (R) flag marks the incoming replacement, and the array stays [UU] throughout. When the copy finishes, md drops the old member automatically and you remove it at your leisure. This needs a free port for the incoming disk — the whole reason to leave one empty.
11. Arm the monitor so you hear about the next one. Set MAILADDR in mdadm.conf — /etc/mdadm/mdadm.conf on Debian and Ubuntu, /etc/mdadm.conf on RHEL-family systems — then prove the path works rather than assuming it:
sudo mdadm --monitor --scan --test --oneshot
sudo systemctl status mdmonitor.service
A test message should land in your inbox, and the unit (mdmonitor.service on RHEL family, mdadm.service on Debian family) should read active (running). An alert nobody receives is why most degraded arrays sit degraded for months.
Validate it works
Confirm the array is whole again:
cat /proc/mdstat
sudo mdadm --detail /dev/md0 | grep -E 'State|Devices'
md0 : active raid1 sdb1[2] sda1[0]
1953382464 blocks super 1.2 [2/2] [UU]
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
[UU] with no progress line, State : clean, and zero failed devices is the finish line.
Confirm both members agree on identity and event counters:
sudo mdadm --examine /dev/sda1 /dev/sdb1 | grep -E 'Array UUID|Events|Device Role'
Both should print the same Array UUID, the same Events value, and two different Device Role slots. Divergent counters on a clean array mean something is still wrong.
Confirm the machine can boot from either disk. On BIOS the new boot sector should not be empty:
sudo dd if=/dev/sdb bs=512 count=1 2>/dev/null | strings | head -3
Seeing GRUB there is the confirmation; on UEFI, sudo efibootmgr -v should list an entry per disk. The real test is booting with the survivor disconnected during a scheduled window — untested boot redundancy is a guess.
Finally, scrub during a quiet period to check the copies actually match:
echo check | sudo tee /sys/block/md0/md/sync_action
cat /sys/block/md0/md/mismatch_cnt
0 is what you want. A non-zero count on RAID1 means the mirrors disagree somewhere and deserves investigation.
Troubleshooting
- You pulled the wrong disk. Stop. Do not add anything, do not reboot, and never run
--create. Put it back in the same bay; md will usually acceptsudo mdadm --manage /dev/md0 --re-add /dev/sdX1, which replays only the changed regions via the bitmap. If it refuses,sudo mdadm --assemble --force /dev/md0 /dev/sda1 /dev/sdX1can bring up an array from members with mismatched counters — a last resort that can surface stale data, so mount read-only and copy off what matters first. - The rebuild is crawling at a few MB/s. Check
dev.raid.speed_limit_minfirst, then look for competing work such as acheckrunning at the same time. Then readdmesg -T | tail -40: repeated ATA resets ormedium errorlines mean the surviving disk is struggling, and the answer is to image it withddrescuerather than push harder on a failing drive. --addrefuses the new disk as too small. Two disks sold as “2 TB” can differ by a few hundred MB, and md needs the new member to be at least the size in the superblock. If the gap is small, shrink the filesystem and then the array withsudo mdadm --grow /dev/md0 --size=...before adding. At build time, a small unpartitioned tail on every disk avoids this entirely.- The array comes back as
/dev/md127. It was assembled with no config file to say what name you wanted. Regenerate the entry withsudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf, thensudo update-initramfs -uon Debian family orsudo dracut -fon RHEL family, and check for duplicateARRAYlines afterwards. - The new disk gets kicked mid-rebuild.
dmesgsays which device threw errors. If it is the new one, the replacement is bad — return it. If it is the survivor, recovery has hit an unreadable sector: stop, image the survivor withddrescueonto a good disk, and rebuild from the image. Retrying just re-reads the same bad sector. - A member vanished for a transient reason — a loose cable, a controller reset. The disk is fine, it just missed writes. Reseat it and use
--re-add, not--add. With a bitmap present it finishes in seconds.
When this is the wrong approach
mdadm handles block-level redundancy and nothing else. It has no checksums, so it cannot tell you which copy is right when two mirrors disagree — a scrub counts mismatches, it does not resolve them. If silent corruption is your real concern, ZFS and Btrfs checksum every block, repair from the good copy automatically, and replace a disk by copying only allocated space.
With a hardware RAID controller, do not use these commands at all. The controller owns the disks, and its own tooling (storcli, perccli, ssacli) marks a drive failed, blinks the bay LED, and starts the rebuild.
Be honest about RAID5 on large drives. A rebuild reads every sector of every surviving member — on a five-disk array of 16 TB drives, roughly 64 TB of reads with no redundancy underneath. At consumer unrecoverable-read-error rates the chance of hitting one mid-rebuild is not small, and on RAID5 a single URE during recovery can abort it. Above a few terabytes per disk, use RAID6 or RAID10 and keep a hot spare.
Most importantly: RAID is not a backup. It protects against a disk dying, and does nothing about rm -rf, ransomware, a bad migration, or a fire. If the array is your only copy, replacing a failed disk is not the problem you should be solving today.
The authoritative references are the mdadm(8) man page and the kernel’s md documentation, which describes the sysfs interface used above.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.