Raid5 exchange 1 of 3 harddrives


I want to exchange a Harddrive which is in a pre-failing state, (some reallocated sectors)
which is used in a raid5 array with 3 disks (software raid with mdadm).

Is it possible to set a new harddrive as a hot-spare and initialize a takeover from the failing to the spare drive?

Some methods suggest to add the drive and then set a drive failure command.
As I know, in this state the raid5 is degraded and a drive failure would end up in….

so is there a possibility to "copy" the data live (or rebuild the raid) from the failing drive to the spare (without take its parity function away), and as the copy or rebuild process is finished, remove the failing drive.

Best Answer

Yes, you can (provided you have a 3.2+ kernel). First, add a new drive as a spare:

mdadm /dev/md0 --add /dev/sdc1

(replace md0 and sdc1 with your RAID and disk device, respectively).

Then, initiate a copy-replace operation like this:

echo want_replacement > /sys/block/md0/md/dev-sdd1/state 

Where md0 is, again, your RAID device, and sdd1 is the failing drive. (Actually, sdd1 is a partition on the failing drive -- I prefer to create RAID sets on partitions rather than on raw disks).

The system will copy all readable blocks from sdd1 to sdc1. If it comes to an unreadable block, it will reconstruct it from parity. Once the operation is complete, the former spare (here: sdc1) will become active, and the failing drive will be marked as failed (F) so you can remove it.

Related Question