degraded software RAID 1

Restore a degraded software RAID 1 array on a linux debian wheezy system. That is, replace the failed Hard Drive.

Someone removed the broken Hard Drive from the system and added a working used Hard Drive with the same specs at the same Serial ATA port with the failed Hard Drive.

The system
# uname -a
Linux kernel 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u1 x86_64 GNU/Linux
# cat /etc/debian_version 
7.6


Multiple Devices Device(s) Status
~# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda2[0]
      1949474624 blocks super 1.2 [2/1] [U_]
      
unused devices: 



What we are working with?
# grep -v "#" /etc/fstab
UUID=a16c558f-47ec-40ca-8989-5e12ce34a5af /               ext4    errors=remount-ro 0       1
UUID=7e96f64f-2f0b-40ac-9de2-4b4f3ff95376 none            swap    sw              0       0
UUID=15ee3ef4-9097-4b04-a154-076972d2f560 none            swap    sw              0       0
/dev/sdc1       /media/usb0     auto    rw,user,noauto  0       0


# blkid 
/dev/sda2: UUID="fc20fbc0-faef-29d6-9666-35454cbf4447" UUID_SUB="852ff6bf-04a5-bbcd-5b3a-b542a61372a6" LABEL="kernel:0" TYPE="linux_raid_member" 
/dev/sda5: UUID="7e96f64f-2f0b-40ac-9de2-4b4f3ff95376" TYPE="swap" 
/dev/md0: UUID="a16c558f-47ec-40ca-8989-5e12ce34a5af" TYPE="ext4" 
/dev/sdb2: UUID="CEE46C0AE46BF2DF" TYPE="ntfs" LABEL="System Reserved" 



# fdisk -l

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00029b1e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1      3899215870  3907028991     3906561    5  Extended
/dev/sda2   *        2048  3899213823  1949605888   fd  Linux raid autodetect
/dev/sda5      3899215872  3907028991     3906560   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xdf90f657

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sdb2          206848   409602047   204697600    7  HPFS/NTFS/exFAT
/dev/sdb3       409602048  3907024895  1748711424    7  HPFS/NTFS/exFAT

Disk /dev/md0: 1996.3 GB, 1996262014976 bytes
2 heads, 4 sectors/track, 487368656 cylinders, total 3898949248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

It seems like I am going to hose an old windows system drive (sdb).

A look at the superblock information for /dev/sdb
# mdadm --examine /dev/sdb
/dev/sdb:
   MBR Magic : aa55
Partition[0] :       204800 sectors at         2048 (type 07)
Partition[1] :    409395200 sectors at       206848 (type 07)
Partition[2] :   3497422848 sectors at    409602048 (type 07)


Copy the partition table of sda to sdb
# sfdisk -d /dev/sda | sfdisk --force /dev/sdb


write grub to sdb
# grub-install /dev/sdb
Installation finished. No error reported.


look at the new sdb partition table
# fdisk -l /dev/sdb

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xdf90f657

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1      3899215870  3907028991     3906561    5  Extended
Partition 1 does not start on physical sector boundary.
/dev/sdb2   *        2048  3899213823  1949605888   fd  Linux raid autodetect
/dev/sdb5      3899215872  3907028991     3906560   82  Linux swap / Solaris

Partition table entries are not in disk order


Add sdb to the RAID 1 array
# mdadm --add /dev/md0 /dev/sdb2


check MD status
# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sdb2[2] sda2[0]
      1949474624 blocks super 1.2 [2/1] [U_]
      [>....................]  recovery =  0.3% (7625152/1949474624) finish=431.5min speed=75000K/sec
      
unused devices: 





replace failed HD in a degraded linux RAID 1 array