how to replace a failed disk on a linux raid array

for this discussion, the configuration is:

  • two disks, sda and sdb, in a raid1 setup: md0 = sda1 + sdb1 and md1 = sda2 + sdb2

  • assume 2nd disk needs replacement

commands:

  • get raid status:

cat /proc/mdstat

  • mark disk as failed:

mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md1 --fail /dev/sdb2
  • remove disk from arrays

mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm --manage /dev/md1 --remove /dev/sdb2
  • add new disk to arrays

mdadm --manage /dev/md0 --add /dev/sdb1
mdadm --manage /dev/md1 --add /dev/sdb2