Tuesday, 23 June 2009

Software RAID on 10.04 Lucid Lynx

Software RAID is a bit of a pain, but hardware RAID controllers that work properly in Linux are too damned expensive for a simple home server.

Here's some notes.
To use RAID, you need to have two or more drives partitioned as Linux RAID members and you need to note down which of these devices will become members of your array. This guide will not cover how to partition drives suffice to say that you can do it using fdisk (console) or gparted (gui). Remember, as always, Google is your friend!

The first step (after partitioning your target drives) is to install the Linux raid utils package.

sudo apt-get install mdadm

This is the command I use to create a 4 drive RAID0 (stripe, no parity) array

sudo mdadm --create /dev/md0 --level=0 --raid-devices=4 /dev/sdd /dev/sde /dev/sdf /dev/sdg

Simply change the "level" to make a RAID5 (stripe with parity) array

sudo mdadm --create /dev/md0 --level=5 --raid-devices=4 /dev/sdd /dev/sde /dev/sdf /dev/sdg

To add another drive later on use this command;

sudo mdadm /dev/md0 --add /dev/sdh

It seems that every time I have to rebuild a system with a pre-existing array I have trouble with it automagically mounting an array called /dev/md_d0 at reboot and everything gets borked until you manually fix it. This is what I have to do;

Logon as su (you need to do this in order to run the mkconf)

sudo -i

Stop the automagic array

mdadm --manage /dev/md_d0 --stop

Re-create the array properly

mdadm --create /dev/md0 --level=0 --raid-devices=4 /dev/sdd /dev/sde /dev/sdf /dev/sdg

Recreate the mdadm config for the array

/usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf

I prefer to use UUID rather than discrete devices whenever possible;

Find the UUID of the array.

blkid /dev/md0

This will return something like this;

/dev/md0: UUID="895c982b-5d2c-4909-b5bf-4ba5a1d049e9" TYPE="ext3"

Add a line to automatically mount the array in /etc/fstab

vi /etc/fstab

Here is a typical line

UUID=895c982b-5d2c-4909-b5bf-4ba5a1d049e9 /store ext3 defaults,relatime,errors=remount-ro 0 2
You need to change the the UUID to the one that was returned by the above blkid command as well as the mount point that you want to mount it on. Make sure you create the appropriate mount point too!

Once this is all done you should be up and running.

To permanently remove raid member disks;

sudo mdadm --zero-superblock /dev/sdX

Good luck and have fun with the penguin!

(last revised 12/08/2010)


ray said...

very useful, helped me sort out my raid weirdness on crunchbang. cheers!

kettlepotblack said...

I think you mean:

/usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf

Brett said...

Oops, well spotted. I've edited the post accordingly, thanks.