Software RAID in Ubuntu

This is a small tutorial about software RAID in Ubuntu - but the method is probably the same in most of the other Linuxes out there.

Since I recently moved, I was looking through some boxes and found a couple of USB memory sticks, a Kingston DataTraveler I 4GB and a Kingston DataTraveler 8 GB, and I got this pretty silly idea, that I should make a software RAID across them. Yeah, don't ask. ;-)

So, here is how I did it and how you can do it.

First, you need to install mdadm which is the program that we use to manage the software RAID with. :::bash sudo aptitude install mdadm

Next, you should identify what device the disks get mapped to in the /dev/ directory: cat /proc/diskstats In my case they were mapped to /dev/sdb and /dev/sdi.

To prepare the devices for being used in the RAID, first set up a partitition on each disk using fdisk like this:

bredsaal@semtex:~$ sudo fdisk /dev/sdb

Command (m for help): d
Selected partition 1
Command (m for help): n
Partition type:
  e   extended
  p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1021, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1021, default 1021):
Using default value 1021
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!

Basically, first you delete every partition on the device, and then you create a new partition that fills out the entire device. Last, you set the partition-type to Linux raid. Remember to do this to every device you want to use in your RAID.

When that is done, you should create the virtual RAID device: mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdi1

If you, like me uses discs with different sizes, mdadm will ask you if you are sure that you want to create the disc array. Of course, press Y and then enter. If you would like to make another type of RAID than RAID1, you should set the --level flag to whatever RAID level you want.

Now all you have to do is to make a filesystem on the newly created RAID device: sudo mkfs.ext3 /dev/md0 and you should be ready to mount your RAID device. Of course, you can put a line in /etc/fstab to mount it automatically on every boot.

Written by Jannich Brendle ons 18 november 2009 In How to