How-To: Software RAID 1 setup on a new Debian Lenny system

RAID 1 (Mirroring) is a great solution for preserving data integrity. If one disk fails, data will still remain on a second disk.
Although hardware RAID is a better solution in most cases, software RAID has a few advantages: it doesn't require additional hardware, and disks can have different sizes.

Installation process on Lenny is easy:

Select Manual Partitioning method:
![partitioning_method][]

Select first disk and create desired partitions. Choose 'physical volume for RAID' for type and set Bootable flag for partition that will contain bootable files (/ in my case)
![raid_partition][]

In this example I will use 2GB for / and 512MB for swap.
![partition_list][]

Select 'Configure software RAID' => Create MD device => RAID1 => Number of active devices: 2, Number of spare devices: 0 => active devices: /dev/hda1, /dev/hdb1

Do the same for the second MD device.  Result should be something like this:
![partition_list_raid][]

Set partition types and mount points for partitions, write changes and continue installation.
![partition_list_raid2][]

When installation completes, check status of RAID devices:

cat /proc/mdstat

You shold see something like this:

Personalities : [raid1]
 md1 : active (auto-read-only) raid1 hda2[0] hdb2[1]
 497920 blocks [2/2] [UU]

 md0 : active raid1 hda1[0] hdb1[1]
 1951744 blocks [2/2] [UU]

 unused devices: <none>

To view details about specific device:

mdadm --detail /dev/md0

Example output:

/dev/md0:
 Version : 00.90
 Creation Time : Mon Feb  1 19:15:17 2010
 Raid Level : raid1
 Array Size : 1951744 (1906.32 MiB 1998.59 MB)
 Used Dev Size : 1951744 (1906.32 MiB 1998.59 MB)
 Raid Devices : 2
 Total Devices : 2
 Preferred Minor : 0
 Persistence : Superblock is persistent

 Update Time : Tue Feb  2 20:20:26 2010
 State : clean
 Active Devices : 2
 Working Devices : 2
 Failed Devices : 0
 Spare Devices : 0

 UUID : 9bf62865:1a8ba74c:ab9fa95e:4176efc8
 Events : 0.5

 Number   Major   Minor   RaidDevice State
 0       3        1        0      active sync   /dev/hda1
 1       3       65        1      active sync   /dev/hdb1

Now we need to setup GRUB loader on both bootable partitions:

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

That's it...  if we remove one drive, system should start-up normally from another drive.

After you replace the drive, re-create paritions and issuse this command (replace partition names according to your scheme):

mdadm --add /dev/md0 /dev/hdb1

Useful tools / links