Creating a software raid using mdadm


Installation on Gentoo:

emerge mdadm
rc-update add mdadm default
/etc/init.d/mdadm start

Installation on Debian/Ubuntu:

apt-get install mdadm

Installation on RedHat/Fedora:

yum install mdadm

You can activate the kernel module by executing:

modprobe raid1

First of all, we are going to create some nodes:

mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2
mknod /dev/md3 b 9 3
mknod /dev/md4 b 9 4

Then you can create new raid devices:

mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/hda1 /dev/hdb1
mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 /dev/hda2 /dev/hdb2
mdadm --create --verbose /dev/md3 --level=1 --raid-devices=2 /dev/hda3 /dev/hdb3
mdadm --create --verbose /dev/md4 --level=1 --raid-devices=2 /dev/hda4 /dev/hdb4

After the creation, the drives are synchronised. This may take some time. You can watch the status using for example this command:

watch cat /proc/mdstat

When the synchronisation has finished you can format the new partitions:

mke2fs -j /dev/md1
mke2fs -j /dev/md2
mke2fs -j /dev/md3
mke2fs -j /dev/md4

You should save your new raid configuration using the following command:

mdadm --detail --scan >> /etc/mdadm.conf

(the path may vary, depending on the underlying system it may also be /etc/mdadm/mdadm.conf)

Now you should add your new devices to /etc/fstab.

Now you can partition (fdisk) and mount your drives and you have your raid running!