Recovering from a failed hard drive running Software Raid 1 - Mirror HowTo

Author:  John H. Bennett III bennett at thebennetthome.com
Contributor:
  Based on information found on the web and written by Abe Loveless (abe at lovelesscentral.org)
Release supported: SME 6.x
License: GPL
Last updated: Sunday, March 27, 2005 09:14 AM


Problem:  One of your disks in your raid 1 array has failed and you need to replace it and re-set up your raid.
Solution:
  Follow this HowTo

STEP 1: 

Replace your failed hard dive with one that is of equal or greater size.  Partition this drive exactly like the active one.

See add extra hard disk howto located at http://www.contribs.org/contribs/mblotwijk/HowToGuides/AddExtraHardDisk.htm

For a raid device you will also need to change your partition type to FD - Linux raid auto, for all partitions that were created.

     From the fdisk menu:

         Command (m for help): t
         Partition number (1-4): x
         Hex code (type L to list codes): fd

Also make your first partition bootable

     From the fdisk menu:

         Command (m for help): a
         Partition number (1-4): 1

Don't forget to write the changes to the disk.

  From the fdisk menu:

         Command (m for help): w

Or try the following method below:
mkdir -p /root/raidinfo
sfdisk -d /dev/sdx > /root/raidinfo/partitions.sdx on the active drive to save the partition information  (for IDE drives this would be hdx)
sfdisk -d /dev/sdx < /root/raidinfo/partitions.sdx on the replaced drive to partition it exactly like the active one (for IDE drives this would be hdx)


STEP 2: 

Add your raid devices back to your system according to the settings in /etc/raidtab

raidhotadd /dev/md0 /dev/sdb1
raidhotadd /dev/md1 /dev/sdb3
raidhotadd /dev/md2 /dev/sdb2

Here is a sample /etc/raidtab file:

raiddev /dev/md1
raid-level 1
nr-raid-disks 2
chunk-size 64k
persistent-superblock 1
nr-spare-disks 0
device /dev/sda3
raid-disk 0
device /dev/sdb3
raid-disk 1

raiddev /dev/md0
raid-level 1
nr-raid-disks 2
chunk-size 64k
persistent-superblock 1
nr-spare-disks 0
device /dev/sda1
raid-disk 0
device /dev/sdb1
raid-disk 1

raiddev /dev/md2
raid-level 1
nr-raid-disks 2
chunk-size 64k
persistent-superblock 1
nr-spare-disks 0
device /dev/sda2
raid-disk 0
device /dev/sdb2
raid-disk 1


STEP 3: 

cat /proc/mdstat

It should tell you that the /dev/md0, /dev/md1, and /dev/md2 devices haves been started, that the mirror is being reconstructed, and an ETA of the completion of the reconstruction.

Notes:  You can also run these commands to get a status of your raid devices:

mdadm --detail /dev/mdx  
lsraid -a /dev/mdx
        x = drive number