RAID - Remove & Add

Remove / Add disk on a Software RAID easly with partition dump between good and replaced disk.

RAID - Remove & Add

There are a necessary few steps before replacing a disk on a software RAID.

Select the disk to remove, fail and remove the disk from each MD, replicate partitions and add the new disk to the same MD.

Those commands are simpler and all information is available on man documentation for mdadm command (man mdadm), however, when we need to do it, there's no time for reading.

For this explanation, we will use this information:

md0 : active raid1 sda1[1] sdb1[0]
498368 blocks super 1.2 [2/2] [UU]
md1 : active raid1 sda2[1] sdb2[0]
498368 blocks super 1.2 [2/2] [UU]
Disk /dev/sdb have bad sectors
  1. Remove a disk from an array

Because we can't remove a disk from the array, unless it is failed, we first need to fail it (if not already failed):

mdadm --fail /dev/md0 /dev/sdb1
mdadm --fail /dev/md1 /dev/sdb2

After this step, we will see the F on Failed drive. Let's remove it.

mdadm --remove /dev/md0 /dev/sdb1
mdadm --remove /dev/md1 /dev/sdb2

This two steps can be done in a single one, like this:

mdadm --fail /dev/md0 /dev/sdb1 --remove /dev/sdb1
mdadm --fail /dev/md1 /dev/sdb2 --remove /dev/sdb2
  1. Check the status of RAID arrays

You can use one of this commands:

mdadm --detail /dev/md0
mdadm --detail /dev/md1


cat /proc/mdstat

This will print the status of the RAID arrays similar to our example. Let's proceed!

  1. Copy partitions from good disk to the new

Ensure that you have a clean disk with no data. First, we need to replicate the same partitions from the present disk to the new disk (clean). To do this step, we will dump and write those to the new disk.

By the example, we have removed the /dev/sdb, so, we need to copy the partitions from /dev/sda to the new /dev/sdb.

sfdisk -d /dev/sda | sfdisk /dev/sdb
Before doing this step, ensure that /dev/sdb is the new disk with no data. If
not, check which letter have been assigned to the new inserted device.
  1. Add a disk to array

Now that we have the partitions created on /dev/sdb, we need to added.

mdadm --add /dev/md0 /dev/sdb1
mdadm --add /dev/md1 /dev/sdb2

In this step, first check the status of RAID to confirm which disk must be assigned to each array.

You can now see the rebuilding in action with:

cat /proc/mdstat