January 29

Replacing the HDD in software raid (mdadm tool)

I have faced the issue on one of my servers where I am using software RAID5.
One of the drives has died, so we replace it with a new one.

However, after that, we need to put it to a raid and recover the normal work, so:

1. We need to create exactly the same structure on the new drive that we are using for the rest of them:

sfdisk -d /dev/sda | sfdisk /dev/sdc
Where SDA is an old one inside the RAID and SDC is a new one (we are copy structure to it)

2. Also, the second issue was discovered – one of the arrays (MD0) is going to an inactive state. To fix it need to do the following:

2.1 stop it
mdadm --stop /dev/md0

2.2 assemble them once again
mdadm --assemble --force /dev/md0 /dev/sd[abd]1

3. readd the new HDD to a RAID array:
mdadm --manage /dev/md0 --add /dev/sdc1
mdadm --manage /dev/md1 --add /dev/sdc2
mdadm --manage /dev/md2 --add /dev/sdc3

Note: Better to start from the small arrays because it can be synced only in a step by step mode. So we can sync small arrays quickly.