Replace broken disk in RAID1 with mdadm

I have a server at home for providing LAN and working as a backup proxy server. It is using RAID1 (software RAID by mdadm) configuration with two disks. Last week the second disk died and started making annoying sound (bad bearing tells my hearing).

Switching was easy once I got a disk with identical size. A bigger disk would have been ok, the excess disk space just would have been left unused. But with a smaller disk, I would have had to first copy data from the last active disk to a new smaller disk and then build a new RAID1 array and finally copy data back. Luckily I didn't have to go that route.

So, first I removed the broken disk from the array:

sudo mdadm --manage /dev/md0 --remove /dev/sdb1

Then, after replacing the broken disk with a new one, I copied the partitions from the active disk (/dev/sda) to the new disk (/dev/sdb):

sudo sh -c 'sfdisk -d /dev/sda | sfdisk /dev/sdb'

I installed GRUB to the new disk, to ensure I can boot from it if the other disk fails:

sudo grub-install /dev/sdb

And finally, I added the new disk to the array and watched /proc/mdstat until the new disk was fully synchronized:

sudo mdadm --manage /dev/md0 --add /dev/sdb1
watch /proc/mdstat


Comments powered by Disqus