In this lesson, you will learn how to safely scale your storage capacity and swap out failing hardware in an mdadm RAID array without interrupting your system's availability.
The Logic of Hot-Swapping and Expansion
In Linux software RAID, you don't need to take your server offline to manage your drives. Because RAID manages redundancy at the block level, we can signal the kernel to add new members or mark existing ones for removal while data continues to be read and written.
Adding a Drive to Expand
If you have a RAID array (for example, a RAID 5 setup) and you want more space, you first add a new physical drive to the array. Once added, you instruct mdadm to "grow" the array to include the new capacity.
To add a new drive (/dev/sdd) to an existing array (/dev/md0):
# Add the drive as a spare
sudo mdadm --manage /dev/md0 --add /dev/sdd
# Grow the array to include the new drive
sudo mdadm --grow /dev/md0 --raid-devices=4
The system will now begin a "reshape" process, redistributing the parity and data across the new device in the background.
Replacing a Failing Drive
If a drive is failing, you must mark it as faulty before removing it. This tells the kernel to stop using that drive and rely entirely on the parity/mirrored data to serve requests.
- Mark as faulty:
sudo mdadm --manage /dev/md0 --fail /dev/sdb1 - Remove the drive:
sudo mdadm --manage /dev/md0 --remove /dev/sdb1 - Insert the replacement: Physically swap the drive and add the new one as shown in the previous section.
If you have a "hot spare" configured in your array, mdadm will automatically detect the failure and begin rebuilding the data onto the spare drive immediately, keeping your data protected without you lifting a finger. Always verify the rebuild status by checking /proc/mdstat.
Key Takeaway: By using mdadm to flag drives as failed or to trigger a grow operation, you can maintain constant data availability while upgrading hardware or recovering from a physical drive failure.