How To Set Up Software RAID1 On A Running LVM System (Incl. GRUB Configuration) (Debian Lenny) - Page 4

On this page

  1. 8 Testing
  2. 9 Links

8 Testing

Now let's simulate a hard drive failure. It doesn't matter if you select /dev/sda or /dev/sdb here. In this example I assume that /dev/sdb has failed.

To simulate the hard drive failure, you can either shut down the system and remove /dev/sdb from the system, or you (soft-)remove it like this:

mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm --manage /dev/md1 --fail /dev/sdb5

mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm --manage /dev/md1 --remove /dev/sdb5

Shut down the system:

shutdown -h now

Then put in a new /dev/sdb drive (if you simulate a failure of /dev/sda, you should now put /dev/sdb in /dev/sda's place and connect the new HDD as /dev/sdb!) and boot the system. It should still start without problems.

Now run

cat /proc/mdstat

and you should see that we have a degraded array:

server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda5[0]
      4988032 blocks [2/1] [U_]

md0 : active raid1 sda1[0]
      248896 blocks [2/1] [U_]

unused devices: <none>

The output of

fdisk -l

should look as follows:

server1:~# fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0004a259

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          31      248976   fd  Linux raid autodetect
/dev/sda2              32         652     4988182+   5  Extended
/dev/sda5              32         652     4988151   fd  Linux raid autodetect

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/md0: 254 MB, 254869504 bytes
2 heads, 4 sectors/track, 62224 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table

Disk /dev/md1: 5107 MB, 5107744768 bytes
2 heads, 4 sectors/track, 1247008 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md1 doesn't contain a valid partition table

Disk /dev/dm-0: 4496 MB, 4496293888 bytes
255 heads, 63 sectors/track, 546 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 608 MB, 608174080 bytes
255 heads, 63 sectors/track, 73 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

Now we copy the partition table of /dev/sda to /dev/sdb:

sfdisk -d /dev/sda | sfdisk /dev/sdb

(If you get an error, you can try the --force option:

sfdisk -d /dev/sda | sfdisk --force /dev/sdb


server1:~# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now ...

Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1   *        63    498014     497952  fd  Linux raid autodetect
/dev/sdb2        498015  10474379    9976365   5  Extended
/dev/sdb3             0         -          0   0  Empty
/dev/sdb4             0         -          0   0  Empty
/dev/sdb5        498078  10474379    9976302  fd  Linux raid autodetect
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

Afterwards we remove any remains of a previous RAID array from /dev/sdb...

mdadm --zero-superblock /dev/sdb1
mdadm --zero-superblock /dev/sdb5

... and add /dev/sdb to the RAID array:

mdadm -a /dev/md0 /dev/sdb1
mdadm -a /dev/md1 /dev/sdb5

Now take a look at

cat /proc/mdstat

server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb5[2] sda5[0]
      4988032 blocks [2/1] [U_]
      [======>..............]  recovery = 31.1% (1556160/4988032) finish=0.6min speed=81903K/sec

md0 : active raid1 sdb1[1] sda1[0]
      248896 blocks [2/2] [UU]

unused devices: <none>

Wait until the synchronization has finished:

server1:~# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb5[1] sda5[0]
      4988032 blocks [2/2] [UU]

md0 : active raid1 sdb1[1] sda1[0]
      248896 blocks [2/2] [UU]

unused devices: <none>

Then run


and install the bootloader on both HDDs:

root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)

That's it. You've just replaced a failed hard drive in your RAID1 array.


Share this page:

1 Comment(s)

Add comment


From: palcica

And what should you do when you upgrade your system (kernel) with apt-get dist-upgrade?!?

 When I did it... raid doesn't work :( (when i unplugged one of disks, system can't boot)

 Thanks for answer!