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

9 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/sdb2
mdadm --manage /dev/md2 --fail /dev/sdb3

mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm --manage /dev/md1 --remove /dev/sdb2
mdadm --manage /dev/md2 --remove /dev/sdb3

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]
md2 : active raid1 sda3[0]
      4594496 blocks [2/1] [U_]

md1 : active raid1 sda2[0]
      497920 blocks [2/1] [U_]

md0 : active raid1 sda1[0]
      144448 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

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          18      144553+  fd  Linux raid autodetect
/dev/sda2              19          80      498015   fd  Linux raid autodetect
/dev/sda3              81         652     4594590   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 /dev/sdb doesn't contain a valid partition table

Disk /dev/md0: 147 MB, 147914752 bytes
2 heads, 4 sectors/track, 36112 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

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

Disk /dev/md1: 509 MB, 509870080 bytes
2 heads, 4 sectors/track, 124480 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

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

Disk /dev/md2: 4704 MB, 4704763904 bytes
2 heads, 4 sectors/track, 1148624 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md2 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    289169     289107  fd  Linux raid autodetect
/dev/sdb2        289170   1285199     996030  fd  Linux raid autodetect
/dev/sdb3       1285200  10474379    9189180  fd  Linux raid autodetect
/dev/sdb4             0         -          0   0  Empty
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/sdb2
mdadm --zero-superblock /dev/sdb3

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

mdadm -a /dev/md0 /dev/sdb1
mdadm -a /dev/md1 /dev/sdb2
mdadm -a /dev/md2 /dev/sdb3

Now take a look at

cat /proc/mdstat

server1:~# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sdb3[2] sda3[0]
      4594496 blocks [2/1] [U_]
      [======>..............]  recovery = 30.8% (1416256/4594496) finish=0.6min speed=83309K/sec

md1 : active raid1 sdb2[1] sda2[0]
      497920 blocks [2/2] [UU]

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

unused devices: <none>

Wait until the synchronization has finished:

server1:~# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sdb3[1] sda3[0]
      4594496 blocks [2/2] [UU]

md1 : active raid1 sdb2[1] sda2[0]
      497920 blocks [2/2] [UU]

md0 : active raid1 sdb1[1] sda1[0]
      144448 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.


10 Links

Share this page:

7 Comment(s)

Add comment


From: at: 2008-01-19 19:37:09

In general, I replaced Disk Id's of Ubuntu Gutsy by devices and is working great. I'm writing from my Gutsy destop.

A few weeks ago I lost my /home partition. As consultant, I also works in home therefore I don't have time for backup, thus I think is a good solution to have a RAID1.

First, I used Debian Etch, but it doesn't support easily my ATI Radeon 9200 video card, and caused problems with vmware.

I redo all the process but for Ubuntu Gutsy Gibbon 7.10, replacing the Disk ID's by devices. Also, for mnemotecnic reasons and easy recovery, I used md1 (boot) md2 (swap) and md5 (root).


From: Jairzhino Bolivar at: 2009-02-22 19:41:32



I just wanted to thank the team/person that putthis tutorial together, this is a very valuable tutorial.  I follow it using debian 5.0 (lenny) and everything works very nicely   I could not enjoy more looking at the syncing process and testing process of the system booting even after i removed the drive (hd1) This really allow everybody to protect their data from hard drive failures. Thank you!!!  Sooo!  Much!!

I notice that when you run the command to install  mdadm "citadel" install as well. Is there away I can run the command apt-get install mdadm skipping "citadel"?

 Again this is greatand very simple.  I am using the same tutorial to create two more disks raid1 for array storage.

This is just cool!!! 

From: L. RIchter at: 2010-01-27 22:01:12

This Howto really worked out of the box. This was my first RAID installation using Debian stable 5.03 and after wasting my time with the installer to set up a RAID this worked straight without any complaints. Really a good job, well done,



From: Franck78 at: 2010-03-25 18:28:36

Just follow steps adjusting number of 'md' and partitions and disks.

Maybe more details about the swap partition on each disk.

Usefull or useless to have an md made of swaps.....?


mkswap /dev/mdX

swapon -a

swapon -s



From: Anonymous at: 2010-08-31 17:34:56

Excellent tutorial. Thank you.

From: Leo Matteo at: 2013-05-01 22:35:20

A very clear "manual" to set up a RAID1 in a running system.

I will try it in a while. I hope all will run well. (if yes or no, I will anyway comment  results.

Thank you (from Uruguay).


From: Max at: 2013-09-14 05:26:00

Aren't md0, md1 and md2 supposed to be operational after disk failure? Contents of /proc/mdstat suggest that raid1 is still running with one disc but subsequent call to fdisk shows that there are no valid partitions on md0, md1 and md2.

Might it be copy-paste error?

Otherwise very good tutorial.