Software RAID in Ubuntu
Introduction
This is a small tutorial to help you getting started with Software RAID in Ubuntu. It was tested on Ubuntu Server 6.06 but it will probably work on Breezy or even on Debian.
Actually, it could possibly work in any GNU/Linux flavour around but I won’t guarantee on that :-)
Please take in attention that you can loose your data! If it happens, don’t complain to me. Follow these guidelines on your own risk.
Why I became paranoid
Five years ago I lost an IBM 80G hard drive that was full of photos, past works and several other important stuff that really mattered to me. I almost cried.
Since then, I became a paranoid with keeping my data safe from harm. I have several machines and there’s a lot of files spawned among them. Call it “Distributed backuping”. Unfortunately, it’s not very useful so I decided I had to have a system that was yet easily usable.
RAID 1 was the answer.
What I bought
To accomplish such, I bought 2x Seagate Barracuda 7200RPM 160GB 8MB Cache. Seagate is well known for is fiability so I didn’t consider any other branch.
Software RAID vs Hardware RAID
Hardware RAID is a must for servers who have a high demand and need serious throughput. Not the case of my home server that’s acting as a fileserver!
Plus, I didn’t have any RAID controller around and sparing €140 on the hard drivers was enough for one day.
I won’t stand my claims (that Software RAID works great for a home server) since you can do it for yourself. Adaptec has some really nice research papers that should how good software RAID can be — although stating that their hardware RAID is better ;-)
Setting up the hardware
I don’t know in depth how the IDE controller works so I couldn’t conclude for myself (nor I had the time to investigate it any further :-) if setting up both hard drives on the same IDE connector (1x Master, 1x Slave) would be faster than having separate IDE connectors (1x Master, 1x Mater). I picked the latter. I’ll wait for some insightful response to this question.
Update
Here’s the response, from Carlos Rodrigues. Thanks Carlos :-)
An IDE channel is a shared bus, so only one drive may be pumping/receiving data at any given time, and some commands lock the bus (try having a CD-Writer and a CD reader on the same channel, and opening and closing the tray on the reader while the writer is recording… instant buffer underrun). Plus, changing directions (write a “read�? command/read data/write a “write�? command/…) is expensive over IDE, so software RAID on a single IDE channel is very bad performance-wise.
On the mean time, you can proceed with any of the approaches and revert it later.
Setting it all from the command line
The system was all set up prior to the Software RAID. Also, I don’t have any X server so all I did was through the command line. Actually, through an SSH session.
The hard work
The first thing I did was checking if both hard drives were being correctly detected on BIOS. They were, let’s move on.
Next, let’s set a partition on each disk and then set its type to Linux RAID. To do such, let’s first figure out which devices the disks got mapped to.
Type $ cat /proc/diskstats. Mine were detected as /dev/hda and /dev/hdc.
To set up a partitition, run fdisk twice, each one for each disk and do the following:
$ fdisk /dev/hdX
Type ‘n’, create a logic partition. Write down the cylinders you used because the partitions on the others disk have to fill the same exact ammount of space. Set it’s type to ‘fd’ by typing t. Finally, save the changes by typing w.
I’ll remember once again than you have to follow this procedure twice, once of earch hard drive.
Now it’s time to create the virtual disk. Make sure mdadm is installed. If it isn’t, I can lend you a hand on that. Just do
$ apt-get install mdadm
Then, fire up the following command
$ mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/hda1 /dev/hdc1
Congratulations, your virtual RAID1 hard drive has been successfully created!
Now we need to create a partition with a real file system instead of that virtual Linux RAID you set before.
We’re almost done. Restart the computer.
$ shutdown -r now
The disks are now being synced. You can’t use the virtual disk.. yet. Type
$ watch cat /proc/mdstat and wait until the rsync finishes. In the meanwhile, get a nice cup of coffee of your favourite beverage.
Did it finish? Great!
Format it:
$ mkfs -t reiserfs /dev/md0
Add the new virtual disk entry to /etc/fstab (explaining how /etc/fstab works is out of the scope of this article) and do issue
$ mount -a
Conclusions
You just set a Software RAID on GNU/Linux through the command line. Bottom line conclusions: Linux rocks! :-)
References
http://www.linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html
https://wiki.ubuntu.com/Raid?highlight=%28raid%29
http://www.howtoforge.com/linux_software_raid
Future work
There’s still a question to be answered. I also welcome any comments correcting grammar, syntax or any other kind of errors.




Hi,
Thanks for putting up this excellent howto! I followed it and am now cruising with my very own RAID1 array on my ubuntu server! Sa-weet!
Hello,
Great article :) Was hopeing you maybe able to help a newbie out? trying to set raid 0 with edgy 64 bit server. hardset on mobo and reads as it should 2X250 SATA2 as 1 500G
When I go to load though I was so confused on how to set up raid in the setup. Kept showing my disks as 2??
Any help would be greatly appreciated Many wasted days and headache from punding my head on this one.
Thanks
i want to create a RAID when i try to install ubuntu. in other words, create RAID in ubuntu partition… can u help me???
Hello! Cool guestbook, interesting information. Keep it UP.
Thank you!
Thanks so much for putting this together!
Just a quick note, though:
If anyone runs into the problem (as I did) of the system not being able to open up the file or device /dev/md0, try adding the “–auto=md” switch to the command line. It will create the md device if the system can’t find it.
As per your example,
mdadm –create –verbose /dev/md0 –auto=md –level=1 –raid-devices=2 /dev/hda1 /dev/hdc1
Thanks again!
Although a good cup of coffee is my favourite thing in this world, I think it’s okay to create your filesystems while your raid1’s are in the process of syncing. Because the metadisk is a block-device, it’s transparent to the filesystem. Use at your own risk, though; it can’t hurt to just wait it out, either…
Reminder, however, that RAID is NOT a backup solution. If a file in RAID gets corrupted, broken, whatever, it gets broken on the mirror as well.
The only way to be sure is to backup your important files to separate media (more than one, if you’re truly paranoid) and take those backups away from your home.
For raid 5- my command line was:
sudo mdadm –create –verbose /dev/md0 –level=5 –raid-devices=4 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2
The sync before format took about 2.4 hours for 1.3TB.
Thanks for a great quick how to.
Additional, when I formatted my raid 5 I used:
sudo mke2fs -b 4096 -R stride=16 /dev/md0
I had a stripe/chunk size of 64k. So 4096*16 will cause the file system to write a full stripe at a time.
Also the command in the previous post should be formatted like the author’s with double dashes. This comment system appears to have stripped them.
G
Thank you for posting an effective raid howto!
It was not easy to find reliable information about Ubuntu Raid, until this page.
Thanks again.
Yves
When I run the command to create the RAID, I get something about the devices being busy.
Hey. thank for the great guide. Worked like a charm.
Question:
Have you tried recovering since then?
Could you possibly write a guide on how to do that.
Thank you very much.
you left out an important step. you need to save the configuration.
mdadm –detail –scan –verbose >> /etc/mdadm.conf
if you are missing a md device you created, reassemble it using.
mdadm –assemble –verbose /dev/md0 /dev/hda1 /dev/hdc1