How to make software RAID in Linux

Quick How To Guide

Add new partition on the first physical disc:

# fdisk /dev/sda

Using the same option add new partition on the second physical disc:

# fdisk /dev/sdb

Create new RAID volume md0 type of RAID1 (raid level1):

# mdadm --create /dev/md0 --level=1 --raiddevices=2 /dev/sda7 /dev/sdb2

Check and verify addition:

# watch cat /proc/mdstat

Format the new RAID volume to ext3 filesystem:

# mkfs -t ext3 /dev/md0

Verify created RAID:

# mdadm --query /dev/md0

For more details enter:

# mdadm --query --detail /dev/md0

Create directory for mounting RAID volume:

# mkdir /mirror

Mount RAID volume md0:

# mount /dev/md0 /mirror

Verify:

# df -hT

Let's try to create directory /etc and file numbers.txt:

# cp –a /etc /mirror
# seq 10000000 > /mirror/cisla.txt

Verify:

# ls –ltr /mirror
# tail /mirror/subor.txt

You can anytime can monitor volume [UU]:

# cat /proc/mdstat

We need to configure automatic mounting volume md0 after system starts:

# cat /etc/mtab | grep md0
# joe /etc/fstab

Append next lines at the end of file /etc/fstab:

/dev/md0 /mirror ext3 defaults 0 0

Append next lines at the end of file /etc/mdadm.conf. If any error occured, system will send a email about it.

DEVICE /dev/sd[a-z]*
ARRAY /dev/md0 level=raid1 devices=/dev/sda7,/dev/sdb2
MAILADDR root@localhost

Turn the monitoring service on:

# service mdmonitor start

Try to make disc down:

# yes “We love linux.“ > /mirror/linux.txt

If you pull out disc during yes command you should get email with error message:

# mutt

We can see one disc is not available [_U]:

# cat /proc/mdstat

Removing paritions that physicaly don't exist:

# mdadm /dev/md0 –r detached

Removing paritions that physicaly exist:

# mdadm --manage /dev/md0 --remove /dev/sdb2

Connect physical disc and monitor how it is being synchronized:

# mdadm --manage /dev/md0 --add /dev/sdb2
# watch cat /proc/mdstat

Test RAID functionality. We should see "active raid1":

# cat /proc/mdstat

verify RAID:

# mdadm --detail /dev/md0

Disable RAID:

# umount /dev/md0
# mdadm --manage --stop /dev/md0

Test RAID functionality again, we should not see "active raid1":

# cat /proc/mdstat

RAID: removing

Unmount mounted partition:

# umount /mirror

Stop RAID (to start it again use --assemble --scan):

# mdadm --stop /dev/md0

Remove RAID:

# mdadm --remove /dev/md0

A RAID partitions are readable, we can mount it:

# mount /dev/sdb2 /mnt

We should see details about RAID:

# ls –ltrh /mnt

Unmount RAID partition:

# umount /dev/sdb2