Sharing a Hot Spare Device in Software RAID - Red Hat Linux



Have you ever wondered if you could share a hot spare device between two software RAID arrays? Yes, You can share a hot spare device if you put mdadm in daemon mode and have it poll your RAID arrays.

Let's assume that you have two RAID 1 arrays with one hot spare configured in this manner:
                        
                              /dev/md0 RAID
                              --
                              /dev/sda1
                              /dev/sdb1
                              /dev/md1 RAID1
                              --
                              /dev/sdc1
                              /dev/sdd1
                              /dev/sde1 (Hot Spare)


This setup shows /dev/md0 with two devices, and /dev/md1 with three devices, with /dev/sde1 as a
hot spare. In this scenario, you want to share /dev/sde1 with /dev/md0 if it should need it. To do that,
you must configure the /etc/mdadm.conf file and define a spare-group name.

In /etc/mdadm.conf, start off by listing all of the devices:

           echo "DEVICE /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1" >> /etc/mdadm.conf

Scan the RAID arrays for the current details, and add it to the file:

           mdadm -D -s >> /etc/mdadm.conf

/etc/mdadm.conf should now contain something like the following:

           # Caution, the ARRAY and UUID should be on the same line.

                       DEVICE /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
                       /dev/sde1
                      ARRAY /dev/md0 level=raid1 num-devices=2
                      UUID=29bc861f:6f1c72b0:162f7a88:1db03ffe
                      devices=/dev/sda1,/dev/sdb1
                      ARRAY /dev/md1 level=raid1 num-devices=2
                      UUID=aee2ae4c:ec7e4bab:51aefe40:9b54af78
                      devices=/dev/sdc1,/dev/sdd1,/dev/sde1


At this point, you need to create a spare-group entry for each array. The name does not matter, as long as it is the same for each array that you want to share the hot spare device(s).

Here, we choose "shared" as the name of the spare-group and add an entry for each ARRAY in the
/etc/mdadm.conf file:

             # Caution, the ARRAY and UUID should be on the same line.
 
          DEVICE /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 

          /dev/sde1
          ARRAY /dev/md0 level=raid1 num-devices=2
          UUID=29bc861f:6f1c72b0:162f7a88:1db03ffe
          devices=/dev/sda1,/dev/sdb1
          spare-group=shared
          ARRAY /dev/md1 level=raid1 num-devices=2
          UUID=aee2ae4c:ec7e4bab:51aefe40:9b54af78
          devices=/dev/sdc1,/dev/sdd1,/dev/sde1
          spare-group=shared


Once the configuration file is ready, mdadm can run in daemon mode and poll the devices. If mdadm determines that a device has failed, it will look for an array in the same spare-group that contains all of the standard devices plus a hot spare device. If it finds any, it will move the hot spare to the array that needs it. In our case, if /dev/md0 were to lose a device, it would look at /dev/md1 and find the two devices of the array plus a hot spare, and it will move the hot spare device to /dev/md0 and begin the rebuild process.

Run mdadm in daemon mode and have it monitor and scan the arrays:
                        
                          mdadm -F -s -m root@localhost -f

The default poll time is 60 seconds, but can be changed using the -d option (e.g., -d 300 would poll every 5 minutes).

Now test out this feature by failing and removing a device from /dev/md0:
                          
                           mdadm /dev/md0 -f /dev/sda1 -r /dev/sda1
 
The next time that mdadm polls the devices, it should determine that /dev/md1 has a spare device, and it should move /dev/sde1 to /dev/md0 and rebuild the array. You can then add in /dev/sda1 and it
will become your hot spare device:
                          
                           mdadm /dev/md0 -a /dev/sda1 



* * * * *