In this lesson, you will learn how to configure "hot spares" in mdadm to ensure your RAID array automatically repairs itself the moment a drive fails.
The Concept of a Hot Spare
When you manage a RAID array, the most stressful moment is when a disk fails. Without a hot spare, your array enters a "degraded" state, where it is vulnerable to data loss if a second drive fails before you manually intervene to replace the broken one.
A hot spare is an extra, idle disk connected to your system that sits in "standby" mode. It is not used for everyday read/write operations, but mdadm constantly monitors it. If one of the active disks in your array drops out, the kernel immediately recognizes the failure and triggers the RAID controller to swap the dead disk for the hot spare. The recovery process—rebuilding the data onto the spare—begins instantly, without you needing to wake up at 3:00 AM to swap physical hardware.
Implementing a Hot Spare
You can add a hot spare to an existing RAID array using the --add flag. Suppose you have a RAID 5 array (/dev/md0) and you have a new, unused disk (/dev/sdd) ready to act as a spare:
sudo mdadm --manage /dev/md0 --add /dev/sdd
Once added, mdadm will mark /dev/sdd as a spare. You can verify this by checking the array status:
cat /proc/mdstat
In the output, you will see your active disks and the new device listed as (S), indicating it is a standby spare. If an active disk fails, the system will automatically remove the failed disk and start syncing data to /dev/sdd in its place.
Why Use Spares?
This approach allows for zero-touch recovery. While the spare does consume a physical port and costs money to keep idle, the "sparse" usage pattern provides a massive safety net. It effectively transforms a potential system outage into a background background task that the operating system handles autonomously.
Key Takeaway: A hot spare is an idle, "standby" drive that allows a RAID array to automatically initiate a rebuild process the moment an active drive fails, minimizing the window of vulnerability during disk replacement.