Friday, January 29, 2010

External RAID 5 with Ubuntu 9.04 and Gnome notifications

Recently I lost a drive after 6 months, and all my data disappeared. That was a Maxtor 1 Touch 1.5 TB.

So after that disappointment, I decided to get a safer solution. So I wanted to have an external RAID 5 and I found those very nice little towers that go for around $150: TowerRaid from Sans Digital. See the picture on the right to see what it looks like. Basically the front panel opens and you just slide your drives in. Fix them with the side screws and you're done.
This box also came with an PCIe card that provides 2 eSATA ports, of which only needs to be used to connect to that box.

Preparting the drives for RAID
I decided not to use the functionality of the card which offers RAID 5 amongst other RAID flavors and simply use Linux software RAID which is a lot more widespread and documented that the chipset on the card. By default, the card was reporting the drives as JBOD (Just a Bunch Of Disks). So I simply started gparted to find the names of the devices (e.g. the drives inserted in the box).

In my case, I found they were
/dev/sde
/dev/sdf
/dev/sdg
/dev/sdh

Ok, the next step was to create partitions on them since they didn't even have a partition table. For each drive, I used fdisk to create a primary partition of type Linux (83).
Now I had 4 partitions, one for each drive. They were named /dev/sde1, /dev/sdf1, etc...

The actual RAID setup
The RAID configuration couldn't be easier. I simply did.
sudo mdadm --create /dev/md0 -n 4 -l 5 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1

The options are quite simple:
/dev/md0 is the name of device (since it was my only raid array, I set it to md0)
-n 4 because there are 4 drives in the box
-l 5 is for RAID 5
and then you pass the list of partitions.

And that's all. Isn't it amazingly simple ?

Creating a file system on the RAID array
From this point on, you can simply treat /dev/md0 just like any partition. So I decided to create an ext4 file system on it.
sudo mkfs.ext4 /dev/md0

And that will create the file system.

Next I mounted it.
sudo mkdir /myraiddisk
sudo mount /dev/md0 /myraiddisk

And now, I could just save files on my new RAID disk.

Checking everything works !
It's always safe to check that everything works as expected. There's a simple command to do that.
sudo mdadm -D /dev/md0

That will report the status of your RAID array. Now for me, at the beginning the RAID array was showing as degraded, rebuilding. I assumed it was organizing the data. After 1 day of work, the status became Active, Clean.

Get a desktop notification on Gnome if a drive fails
The advantage of RAID 5 is that if a drive fails, then you can replace it and the array rebuilds/auto-corrects itself. But, first you need to be aware that a drive failed. For that purpose, there's a great blog post from TomTheGeek that explains just how to do that.
The only difference I found in Ubuntu 9.04 was that the notify-send command was not in notification-deamon package, it was in libnotify-bin.

No comments:

Post a Comment