Having recently built a new PC and experiencing a torrid time with faulty disks, I searched the net for some simple instructions on array reconstruction. None of them made it totally obvious to me in words of one syllable, and so felt the need for this section.
Firstly, I’m basing this on the mdadm tool rather than the older raidtools. This is simply because mdadm is already on my machine and raidtools is not. I guess one superceeded the other.
Right, so you have a RAID1 machine and one of the disks in it has failed. You’ve sent it back to the supplier and a nice new one has arrived in the post. What happens next:-
Plug in the new disk. If you want an easy life, plug it into the same interface as the failed disk. However, if you previously had both disks plugged into the same controller and the effect of one failing was to drag the entire bus down, you may now be considering splitting your array across two controllers! Yes, I am talking from experience: Every time I’ve suffered a disk failure on PATA or SATA, the failed disk has caused the controller to lock up.
Hopefully you now have the new disk installed, system rebooted and both disks available to the system.
Next you need to partition the new disk to make it identical to the one it’s going to mirror. For this, fdisk does the job very well indeed. Fancier tools might be out there, but my advice is, don’t use em.
Assuming sda is the operational disk and sdb is the new one:
fdisk -l /dev/sda
This will list all the partitions on sda. That’s a lowercase L not a 1 by the way.
fdisk /dev/sdb
Will enter the partitioning utility for the new disk.
Within this system, four commands are likely to be used:
n Create new partition
p Print current partition table
t Toggle partition type
w Write changes and exit
Most of these are pretty self explanatory and the commands offer simple choices as you go through it. Create the partition first, then toggle the type (fd is Linux RAID Autodetect). Check what you’ve done with Print, and then finally save it with Write. Job done!
Finally, you need to re-pair the two disks into the RAID1 sets:
cat /proc/mdstat
This will show the /dev/md partitions and their active components, something like the list below:
Personalities : [raid1]
md1 : active raid1 sda5[0]
15623104 blocks [2/1] [U_]
md2 : active raid1 sda6[0]
15623104 blocks [2/1] [U_]
md3 : active raid1 sda7[0]
15623104 blocks [2/1] [U_]
md4 : active raid1 sda8[0]
15623104 blocks [2/1] [U_]
md0 : active raid1 sda2[0]
15623104 blocks [2/1] [U_]
In no particular order, work through this list and reconstruct each pair using a command like the following:
mdadm /dev/md1 –add /dev/sdb5
If your RAID1 arrays are like mine, sd(x)5 will always pair with sd(y)5, although this isn’t strictly a must.
That’s it, when finished issuing a cat /proc/mdstat should now reveal that all disks are paired as the following list shows:
Personalities : [raid1]
md1 : active raid1 sdb5[1] sda5[0]
15623104 blocks [2/2] [UU]
md2 : active raid1 sdb6[1] sda6[0]
15623104 blocks [2/2] [UU]
md3 : active raid1 sdb7[1] sda7[0]
15623104 blocks [2/2] [UU]
md4 : active raid1 sdb8[1] sda8[0]
15623104 blocks [2/2] [UU]
md0 : active raid1 sdb2[1] sda2[0]
15623104 blocks [2/2] [UU]
Dude. Why not just duplicate the partition table in one fell swoop. sfdisk allows you to dump a partion table and use that dump to repartition
Notice how the device is also output with the dump. A little simple sed 1 liner and you can duplicate to /dev/sdb
Example:
$ sudo sfdisk -d /dev/sda
========
unit: sectors
/dev/sda1 : start= 1, size …..
……
========
$ sudo sfdisk -d /dev/sda | sed “s/sda/sdb/” | sudo sfdisk /dev/sdb
Magic!
just curios how would I set up a warning so I get an email if one of the HDs fails? kinda automated warning system?