Replace a failed disk when mdadm RAID1 shows [U_] (degraded)
Read [U_] and (F) in /proc/mdstat, replace the dead disk with fail, remove and add, then watch the resync run. Based on the mdadm man page and kernel.org wiki.
A _ in the status field of /proc/mdstat means one disk is missing from the array. Data stays readable from the remaining disk, but there is no redundancy until you replace it. The mdstat output below is copied from the Linux RAID wiki; device names are assumed to be /dev/md0, /dev/sdb1 and /dev/sdc1.
[1] Look at the array.
# cat /proc/mdstatThe status field has one character per device: U for up, _ for down. A failed device gets (F) after its name. The wiki's example (a six-disk RAID1) looks like this:
md1 : active raid1 sde1[6](F) sdg1[1] sdb1[4] sdd1[3] sdc1[2] 488383936 blocks [6/4] [_UUUU_][2] Get the details with mdadm --detail. The wiki says it shows spare and failed disks clearly; a failed device is reported as faulty.
# mdadm --detail /dev/md0[3] Work out which physical disk died. Do not trust /dev/sdb alone: compare serial numbers, because names can change across reboots.
# ls -l /dev/disk/by-id/ | grep -E 'sdb|sdc'[4] Mark the disk failed, then remove it. The man page says: to remove an active device, it must first be marked as faulty. The wiki's replacement line makes --fail optional by putting it in brackets.
# mdadm /dev/md0 --fail /dev/sdb1 --remove /dev/sdb1[5] Replace the disk and partition the new one. Partitioning tools and sizing rules are outside this article; assume /dev/sdb1 is created to match the existing member.
[6] Add the new partition to the array.
# mdadm /dev/md0 --add /dev/sdb1Per the man page, if the array is degraded, a device added with --add immediately starts to rebuild. A device that does not look like a recent member is added as a hot-spare.
[7] Watch the resync. The progress line has the form recovery = percent (copied/total) finish=estimate speed=rate.
md127 : active raid5 sdh1[6] sdg1[4] sdf1[3] sde1[2] sdd1[1] sdc1[0] 1464725760 blocks level 5, 64k chunk, algorithm 2 [6/5] [UUUUU_] [==>..................] recovery = 12.6% (37043392/292945152) finish=127.5min speed=33440K/sec[8] To hear about the next failure sooner, set up mail alerts. The wiki's example is mdadm --monitor --daemonise --mail=root@localhost --delay=1800 /dev/md2: it mails critical events and fatal errors, and --delay is the polling interval in seconds. Check separately that mail delivery works on the machine.
[9] If you reuse the removed disk for something else, wipe its old md metadata. --zero-superblock overwrites a valid md superblock with zeros. ★In steps 5–6 **the new disk became /dev/sdb1**, so running this on that name wipes the disk you just added. Use the name the old disk gets in another slot or machine (/dev/sdX1 below), and first confirm it is not part of any array in cat /proc/mdstat.
# cat /proc/mdstat# mdadm --examine /dev/sdX1# mdadm --zero-superblock /dev/sdX1The one thing you can check against a plain image file is --examine on a file with no superblock:
$ mdadm --examine disk.imgmdadm: No md superblock detected on disk.img.