How to add hot spare to software RAID1?

I have a CentOS 7 server. It is running a software RAID 1 mirroring three disks. I want to add a 4th disk to act as a hot spare. My intention is that in the event of a failure of one of the three disks being mirrored that the hot spare would automatically be populated from one of the remaining working disk, and take its place from the failure drive.

For the hot spare, other than formatting the new drive what else needs to be done to it? I assume it remains with no data on it until it is needed and starts syncing to replace the bad drive?


If you really want to use 4 disks for a RAID1 array, I suggest you to go with a 4-way RAID1 array. In this manner, should a disk fail, you continue to have triple-protection (3-way array) without needing any rebuild.

If you really want a 3-way mirror + hot spare, you can use mdadm --manage --add-spare to add a spare to the RAID1 array. For example, lets start from this 3-way array (note: I am using loopback devices, while you want to use real disks):

[root@localhost test]# cat /proc/mdstat 
Personalities : [raid1] 
md127 : active raid1 loop2[2] loop1[1] loop0[0]
      7168 blocks super 1.2 [3/3] [UUU]

Adding a spare is quite simple:

[root@localhost test]# mdadm --manage /dev/md127 --add-spare /dev/loop3
mdadm: added /dev/loop3

Lets check /proc/mdstat now:

[root@localhost test]# cat /proc/mdstat 
Personalities : [raid1] 
md127 : active raid1 loop3[3](S) loop2[2] loop1[1] loop0[0]
      7168 blocks super 1.2 [3/3] [UUU]

Again, be sure to use the correct device name (rather than blindly copy/pasting the above commands). And take a confirmed-working backup first.

However, I consider a 4-way or 3-way+hotspare RAID1 array overkill. While for extremely important data a 3-way RAID1 mirror can be justified, you should really plan for failure scenarios in which the entire server is down. In other words, don't skip on regular backups simply because you have mirrored disks.