Linux rebuild software RAID1

Set the bash field separator to newline:


See what disk and partitions are currently up, then generate commands to re-add the missing disk and partitions, then run them:

for i in `cat /proc/mdstat | grep md | cut -d [ -f1 | sed -e 's/\(md[0-9]\).*\(sd[a-z][0-9]\)/mdadm --add \/dev\/\1 \/dev\/\2/' | sed -e 's/sdb/sda/'`;  do eval $i; done;

TODO: make it determine which disk to add (/dev/sda or /dev/sdb)


copy partition table from one disk to another

When replacing a failed disk in a RAID 1 array, it’s necessary to get the new disk setup properly with an identical partition table matching the existing disk. In this case sda has failed and has been replaced with a spare. To copy the partition table from sdb to sda do this:

# sfdisk -d /dev/sdb | sfdisk /dev/sda --force

Make absolutely sure you know which disk is which, otherwise you will blow out the good partition table on the running disk, with whatever is on the spare (probably no partition table at all).