Step-by-step guide
- Mark the drive as failed
1$ sudo mdadm --manage /dev/md0 --fail /dev/sdb1 - Remove the drive from the array
1$ sudo mdadm --manage /dev/md0 --remove /dev/sdb1 - View the mdadm status
1$ cat /proc/mdstat - If you prefer to shut down the system for a cold swap, do it now. Before the hot swap, put the drive into standby with the following command
1$ sudo hdparm -Y /dev/sdb
Make sure you know which drive you are going to remove before issuing this command. Operations to the disk will wake up the drive again. - Remove the SATA signal cable first and then the SATA power cable.
- Mount the new drive and connect SATA power. I let the drive spin up for 5-10 seconds before connecting the SATA signal cable. If you did a cold swap, power on the system at this point.
- Identify the new drive and what device name it has. In my case, the new drive was conveniently named /dev/sdb, the same as the old one.
- Copy the partitioning setup from the other drive in the array to the new disk. (This is for a RAID1 setup)
Make sure the order is correct, otherwise we will erase the operational drive!
1$ sfdisk -d /dev/sdc | sfdisk /dev/sdb - Add the new drive to the RAID array
1$ sudo mdadm --manage /dev/md0 --add /dev/sdb1 - The RAID array will now be rebuilt and the progress is indicated by the
1$ cat /proc/mdstat
output. To have a more dynamic update of the progress use the following:
1$ watch cat /proc/mdstat