How to manage a Software RAID with mdadm on Debian

Table of contents :

  • Show the details of the RAID
  • Add a hard drive to the cluster
  • Replace a hard drive

Show the details of the RAID

With an example of a cluster /dev/md0 :

sudo mdadm --query --detail /dev/md0

A shorter command line for the same result is :

sudo mdadm -D /dev/md0

You can also observe the RAID system live :

cat /proc/mdstat

For each of its command line, you can began with the command “watch” to be able to observe in real time what’s going on

watch cat /proc/mdstat

Add a hard drive to the cluster

Adding a new 4th hard drive /dev/sdd to the cluster /dev/md0 need 3 steps :

  1. Adding the new hard drive to the cluster
  2. Extend the RAID to the 4 hard drives
  3. Resize the RAID capacity
sudo mdadm --manage /dev/md0 --add /dev/sdd
sudo mdadm --grow /dev/md0 -n 4
sudo resize2fs /dev/md0 

You can do this only for testing, but… the test will be very… very… very long. In my case, I add just one hard drive of 500GB to a RAID 5 of 4 other hard drives. It took several hours…

Replace a hard drive

In the following example, we’ll consider the hard drive /dev/sdc as defaulting

1. Declare the hard drive as “faulty”

With the following command line, the cluster will ignore the hard drive /dev/sdc. The RAID system will continue to work in degrated mode.

sudo mdadm --manage --set-faulty /dev/md0 /dev/sdc

If everything’s ok, the result is :

mdadm: set /dev/sdc faulty in /dev/md0

2. Remove the hard drive from the cluster

sudo mdadm --manage /dev/md0 -r /dev/sdc

If everything’s ok, the result is :

mdadm: hot removed /dev/sdc from /dev/md0

3. Replace physicaly the hard drive by a new one

The command line previously seen for checking hard drive health can help you to identify the right one with details as :

  • Model Family
  • Device Model
  • Serial Number
  • etc…
sudo smartctl -a /dev/sdc

4. Add the new hard drive to the cluster

sudo mdadm --manage /dev/md0 --add /dev/sdc

If everything’s ok, the result is :

mdadm: added /dev/sdc

Right after, the RAID system will instantly start to synchronise the cluster with the new hard drive.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *