Linux software RAID
From DevOps Notebook
Replace failing drive in software raid 1
Check which drive is failing
# cat /proc/mdstat Personalities : [raid1] md3 : active raid1 sda4[0] 1822442815 blocks super 1.2 [2/1] [U_] md2 : active raid1 sda3[0] 1073740664 blocks super 1.2 [2/1] [U_] md1 : active raid1 sda2[0] 524276 blocks super 1.2 [2/1] [U_] md0 : active raid1 sda1[0] 33553336 blocks super 1.2 [2/1] [U_] unused devices: <none>
Remove drive:
# mdadm /dev/md0 -r /dev/sdb1 # mdadm /dev/md1 -r /dev/sdb2 # mdadm /dev/md2 -r /dev/sdb3 # mdadm /dev/md3 -r /dev/sdb4
Backup mbr/gpt table MBR:
# sfdisk --dump /dev/sda > sda_parttable_mbr.bak
GPT:
# sgdisk --backup=sda_parttable_gpt.bak /dev/sda
Restore mbr/gpt table MBR:
# sfdisk /dev/sdb < sda_parttable_mbr.bak
GPT:
# sgdisk --load-backup=sda_parttable_gpt.bak /dev/sdb
Add new partitions to raid
# mdadm /dev/md0 -a /dev/sdb1 # mdadm /dev/md1 -a /dev/sdb2 # mdadm /dev/md2 -a /dev/sdb3 # mdadm /dev/md3 -a /dev/sdb4
Check if its rebuilding
# cat /proc/mdstat Personalities : [raid1] md3 : active raid1 sdb4[1] sda4[0] 1028096 blocks [2/2] [UU] [==========>..........] resync = 50.0% (514048/1028096) finish=97.3min speed=65787K/sec md2 : active raid1 sdb3[1] sda3[0] 208768 blocks [2/2] [UU] md1 : active raid1 sdb2[1] sda2[0] 2104448 blocks [2/2] [UU] md0 : active raid1 sdb1[1] sda1[0] 208768 blocks [2/2] [UU] unused devices: <none>
Install bootloader on new drive
# grub-mkdevicemap -n # grub-install /dev/sdb