Creating a software RAID-1 array

RAID stands for Redundant Array of Inexpensive Disks and refers to the use of multiple hard disks to share or replicate data between drives. For RAID-1, you need two partitions of identical size on two separate disks which are not connected to the same IDE/Parallel ATA-bus. Use cfdisk to create the two partitions /dev/hdb1 and /dev/hdc1. Set their respective types to FD and do not set their bootable flags. Create the RAID-1 array with the following command:

user@ubuntu:~$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/hd[bc]1

Create a filesystem on the RAID device with the following command:

user@ubuntu:~$ sudo mke2fs -j /dev/md0

Create an empty directory /raid as a mount point and add the following line to /etc/fstab:

/dev/md0 /raid ext3 defaults 0 2

Mount your RAID array and check its status with the following commands:

user@ubuntu:~$ sudo mount /raid
user@ubuntu:~$ sudo mdadm --detail /dev/md0

Monitoring the RAID Array

If required, start by configuring Postfix to redirect mail for the local root user. Obtain the UUID of your RAID device with the following command:

user@ubuntu:~$ sudo mdadm -D /dev/md0

Create the file /etc/mdadm/mdadm.conf and add the following three lines, replacing 47d1eee2:2cbfr68v:34×75168:142ef912 with the UUID of your RAID:

DEVICE /dev/hdb1 /dev/hdc1
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=47d1eee2:2cbfr68v:34x75168:142ef912
MAILADDR root

Edit the file /etc/init.d/mdadm and append –test to the line beginning with start-stop-daemon -S:

start-stop-daemon -S -q -p $PIDFILE -x $MDADM -- -F -i $PIDFILE -m $MAIL_TO -f -s --test

Restart the mdadm daemon with the following command:

user@ubuntu:~$ sudo /etc/init.d/mdadm restart

Verify that the local root user has received a test message from the mdadm daemon. From now on, the mdadm daemon will monitor the integrity of the RAID array and, in the event of any problems, alert the local root user by email.
users.piuha.net/martti, www.tldp.net