The design of this site is being fiddled with. Any strange sights and sounds are to be welcomed, not feared.

Software RAID 5 on Ubuntu 9.04

June 13th, 2009

I’ve been playing with FreeNAS for a few days and I can’t say that I like it. I can’t put my finger on it, apart from a general feeling of working with over-padded mittens. I’ve therefore decided to go at it from scratch with Ubuntu.

The core of any decent NAS server is a bank of drives configured in a RAID array, so I’m going to start off my NAS building by configuring a level 5 software RAID set.

My scenario is that of an established Ubuntu setup, booting from a single SATA drive that I wish to add a large RAID array to, creating a large storage area that can be mounted anywhere on the filesystem, independent of the main OS and its partitions. For now I’m not intending to mount the OS itself on a RAID device - that’s another topic - but it would really make sense to have the OS sitting on a desperate RAID 1 device, benefiting from the additional redundancy. The nice thing here is that you just need a small drive to hold only the OS. Grab a couple of 5GB drives off Ebay for a fiver and use them!

For now this is all taking place inside a VirtualBox VM, but it should work just as well on a physical system.

So, first of all create a regular VM, with four SATA drives attached to it. The first one of these (on port 0) should be your OS drive. The other three (on ports 1,2 & 3) should be equally sized drives - I used drives of 5 GB for this test, but they can be as large or small as you want, it don’t matter, just as long as they are of equal size (and even then, it doesn’t matter too much as we’re gonna partition them) - these form your RAID array.

Install Ubuntu Server onto the first drive. During the install just look for a device called “sda”  and choose “Guided partitioning” for that. If you’re unsure, just connect the first drive by itself, install, shutdown, connect the RAID drives and reboot.

Once the OS is installed you can use

cat /proc/diskstats

to see all the physical drives and partitions on your system. Each drive on your system should show up in /dev/ as something like

/dev/sdx

where x is a letter starting with “a”, onwards.

Your OS drive should show as /dev/sda and you should also see something like /dev/sda1, /dev/sda2, /dev/sda5  and so on. sda represents the physical drive (well, as physical as it can be on a VM) and the numbered “sda”s afterwards represent partitions on the drive. Your OS drive is obviously already partitioned and formatted, but your array drives will likely have nothing to show but the plain unnumbered versions, as they are unpartioned as yet.

To start the process of building the RAID you’ll want to format the three drives of your array. If you’re using the command-line (you Linux warrior, you) then use fdisk to partition and format each drive. Run

sudo fdisk /dev/sdb

which will take you into the interactive fdisk programme. It’s a little confusing so for now just type “n” (for new) and then “enter” to create a new partition. Following this choose “p” for Primary partition and then type “1″ to create partition 1. You’ll be asked what cylinder to start the partition on. I just accept the default (1) and also accept the default for the end cylinder (which will depend on the size of drive that you created). You’ll now need to mark the partition as wanting to be part of a RAID array. Type “t” (for type) and then enter “fd” for, erm, RAID array (it was logical up until then). Then write these changes to the drive with “w” (for write - yay, consistency returns).

You’ll need to repeat this for every physical drive that you want to be part of the array. You’ve already done /dev/sdb, so now get /dev/sdc and /dev/sdd done.

The only problem you might encounter here is if for some reason there is already a partition on the drives. If this is the case then before using fdisk to do any of the above steps, type “d” (for delete) to remove the already existing partition - then carry on as outlined.

Okay, so your drives are all ready to be RAIDed up! Time to install ::drumroll:: mdadm

sudo apt-get install mdadm

This is the package that allows you to create and control software RAID arrays. We’ll use it initially to create your RAID set

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

With that command you’ve said “create a RAID disk device at /dev/md0, comprised of three disks, called sdb1, sdc1 and sdd1″. Notice that we specified the partitions to use on your three SATA drives, not the drives themselves. Be sure to get the number of RAID devices correct - it’ll just cause heartache later on if you get it wrong.

Hopefully everything should go okay with that. If it has, then the system should already be syncronising the partitions with each other, in the background. You can watch this process and see when it’s complete with the most fantastic watch command

watch cat /proc/mdstat

You’ll see the percentage compeleted slowly creeping upwards. This could take minutes to hours, depending on the size of the drives and the numbers used. Why not go bake a cake while you’re waiting? Raspberry jam, for preference, as I love raspberries.

After a period of time equal to n the drives should be syncronised and the array built.

You’ll have to tell the mdadm configuration file about the new RAID that you’d like it to manage. The following command will output details about your new array and add it to the config file.

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

Okay, we’ve got a RAID array! It is currently sitting at /dev/md0, looking like a regular drive device to the OS. However it isn’t formatted or mounted just yet, so lets format it.

sudo mke2fs -j /dev/md0

This formats /dev/md0 with an ext3 filesystem.  It’s a nice command as it handles all the settings for you and makes sensible assumptions. BTW, if you want the filesystem as ext2 then just leave off the -j option.

So now we’ve got a formatted device device we’ll have to mount it on the filesystem. You can mount it anywhere you want really, but for now I’m sticking it in /var/, so that it’s accessible to all users. You’ll need to create a mount point, which is just a directory that the to-be-mounted device will take over, like a Goa’uld or something:

sudo mkdir /var/media/

So that our RAID mounts on every boot we’ll need to add it to the fstab file, whereUubuntu keeps all the dirt on what drives it should take care of. Open fstab in nano:

sudo nano /etc/fstab

and add the following line to he bottom of the file:

/dev/md0 /var/media auto defaults 0 3

Now if you want to you can reboot the system and see that the RAID will get mounted on /var/media, but we can use the “Mount all” command to make it happen right now:

mount -a

Hopefully your RAID device should now be mounted at /var/media. Go on, have fun - copy some files to it. Copy them back. Delete them. Just go crazy.

I’ll hopefully follow this up with configuring alerts for failing drives in your system.

References

Where am I?

June 7th, 2009

It’s so long since I last blogged that I almost considered deleting this blog and putting up a holding page. I’ve decided against such drastic action for now and if I gather the blogging motivation I’ll post something soon.

In the meantime I’ve found myself Twittering a lot. You can follow me via @SonniesEdge.

Ubuntu 9.10

November 17th, 2008

I want it to be called Kinky Koala…

Drupal as intranet

November 10th, 2008

One of my upcoming projects is to get a staff portal up and running, one that will allow news to be posted, discussions in forums and allow our own custom code to be integrated.

I was going to repurpose Moodle for this (yes, wince with me) for the sole reason that most of our staff are familiar with it on one way or another. However, I’m being drawn towards Drupal, due to its content-orientated approach, massive support and ability to integrate custom code as modules.

University

October 29th, 2008

I’m sitting in class learning how to write a shopping cart in PHP, yet I was hacking OScommerce nearly a decade ago.

Life is weird.

Just testing

October 28th, 2008

Just testing a tool which allows me to post directly from the GNOME desktop…

Samsung Q210 + Ubuntu Intrepid Ibex + wifi

October 19th, 2008

I couldn’t go any longer without my own computer, so after a few days intensive research I’ve gone and splunged down the money for a Samsung Q210 ultraportable.

Naturally, the first thing I did after pulling faces at the pre-installed Vista was to install the latest Ubuntu Intrepid Ibex release. As always with Ubuntu things went swimmingly - booted from a USB key image and Ubuntu was installed.

However, getting wifi working (using FOSS and not ndiswrapper ::spit:: ) took a bit of figuring out, but is actually quite simple.

Step 1: Disable native drivers

Goto System => Administration => Hardware Drivers and deactivate the “Support for Atheros 802.11.wireless LAN cards” option.

Step 2: Install prerequisites

  • sudo apt-get update
  • sudo apt-get install build-essential
  • sudo apt-get install subversion

Step 3: Download MadWifi drivers via svn

There is a patched version of MadWifi that enables support for the Q210s wireless card, the Atheros AR242x.

  • cd /usr/src
  • sudo svn checkout http://svn.madwifi.org/madwifi/branches/madwifi-hal-0.10.5.6 madwifi-hal-0.20.5.6

This may be updated in the future, so keep an eye on this thread to see how things progress.

Step 4: Install

  • cd madwifi-hal-0.10.5.6
  • sudo make
  • sudo make install
  • sudo modprobe ath_pci

Finally,tell Ubuntu to load the appropriate module at boot:

  • sudo gedit /etc/modules

and add this to the end of the file:

  • ath_pci

You should now be able to reboot and see your locla wireless networks in Network Manager!

Need my own laptop

October 12th, 2008

I really need my own laptop now, as Kay may well kill me if I keep on stealing hers.

I’m trying to wait just a couple more weeks before buying one, in case Apple release something pretty at their October 14th press event. If they disappoint again then it’s probably going to be the Packard Bell 12″ BG45-U-300 netbook.

Moodle Heritage Block

July 18th, 2008

As part of our integration project at work I’ve created a Moodle block that integrates with the Heritage library management system. It parses an XML feed outputted by Heritage and obtains a list of current loans, along with their due dates and media type.

If this kinda think floats your boat you can download it here.

It’s the middle of July…

July 18th, 2008

…and I have the fire on.

Global warming, my arse.


ClickHeat : track clicks