How in the Tech
Quick and dirty linux software RAID5

I recently migrated my network storage server, running Ubuntu Linux incidently, to a software RAID 5 configuration. RAID level 5 requires atleast 3 harddrives; giving you in total N-1 storage, where N is the number of disks in the array. For my deployment, I used 3 120GB drives (mixing IDE and SATA, Linux is indifferent here) giving me effectively 240GB. The missing 120GB is the parity information that allows transparent data recovery when 1 disk in the array fails. I’ve glossed over a lot of the details regarding RAID 5 but a quick google should fill in the blanks if need be.
Here is how I accomplished this under Ubuntu Dapper.
- Install mdadm using apt-get, or your favorite package manager. mdadm is the tool used to administer Linux md device arrays (software RAID).
- Partition your drives as appropriate using cfdisk /dev/. Ensure that all partitions are of equal size and the partition type is set to Linux raid autodetect.
- Using mdadm create your RAID-5 device:
- mdadm –create /dev/md0 –chunk=64 –level=raid5 –raid-devices=3 /dev/hdc1 /dev/hde1 /dev/sda1; substituting for your own /dev/ devices.
- Good Good.
- # cat /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sda1[0] hdc1[1] hde1[2]
234371968 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
- Format your newly created /dev/md0 device.
- Create a mount point for your RAID-5 array and add it to /etc/fstab so it is mounted automagically on the next reboot.
- /dev/md0 /storage ext3 defaults 0 1
- Getting detailed info about your array.
- Managing the RAID device.
- Setting a disk faulty/failed:
# mdadm –fail /dev/md0 /dev/hdc1
- Removing a faulty disk from an array:
# mdadm –remove /dev/md0 /dev/hdc1
- Clearing any previous raid info on a disk:
# mdadm –zero-superblock /dev/hdc1
- Adding a disk to an array:
# mdadm –add /dev/md0 /dev/hdc1
RAID can be an intimadating piece of technology but it’s benefits are plainly obvious. Hopefully this framework howto is enough to ease your fears.
Related Posts
Recent Posts
July 17, 2008
By Adam Myers
July 10, 2008
By Adam Myers
July 9, 2008
By Adam Myers
July 7, 2008
By Adam Myers
July 4, 2008
By Adam Myers
Random How in the TECH
July 6, 2006
By Adam Myers
December 3, 2005
By Adam Myers
May 22, 2008
By Adam Myers
April 21, 2008
By Adam Myers
September 1, 2005
By Adam Myers
[...] After reading way too many articles on RAID and mdadm and lvm, I finally came across this article. This article was definitely a eureeka moment, and within 5 mins I had set up my raid array (not counting the 2hrs of formatting…). Cool stuff! [...]
I found this guide very quick and easy. Thanks very much for taking the time to write it up
I Have to try this with Ubuntu 6.06 LTS server. I have 4 x 250Gt ATA disk and 160Gt install disk for ubuntu.
Have just done this on Gutsy (Ubuntu 7.10 64bit). Worked fine, thanks a lot. As a tip, I used System->Administration->Synaptic Package Manager to get the mdadm command installed.
Does anyone know how to set up the server to email (or alert another way) for disk failures or array degradation? I have read a few other tutorials but none of them cover proactive disk monitoring.
Thanks,
-Ivan
Found it! http://linux-raid.osdl.org/index.php/Detecting%2C_querying_and_testing#Monitoring_RAID_arrays
Thanks Ivan! I should have probably included something like this.
Guide worked great except my system wouldn’t startup on reboot. I had to use a Recovery Disk to edit out the line in /etc/fstab just so it would boot. It seems there’s one step missing, at least it was required for Fedora 8 x86_64. Anyways. Before rebooting you’ll probably want to:
mdadm –detail –scan –verbose > /etc/mdadm.conf
if you want your system to startup. Like I said could just be a Fedora thing, but I’m betting otherwise. I found this here:
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch26_:_Linux_Software_RAID
I also used fdisk instead of cfdisk.
Hi Bando,
That step doesn’t appear to be necessary in Ubuntu - I don’t recall doing anything other than the above. I’ll be doing another raid5 setup in the next week or so with Hardy Heron. I’ll update my findings then.
Anyways, thanks for the comment!
Great howto easiest one I have found. Hopefully someone can take this and GUIfy it for new users.
FYI small typos need fixing
–create*
–raid*
–level*
–chunk*
One dash wont work.
Still kick ass article otherwise. Works great in Ubuntu 8.04 and 7.10.
@Paradexes
Thanks, yeah I’ve noticed that but for some reason my wordpress theme gunks out the double dash.
Glad it proved useful nonetheless!
Edit: I fixed the double dash problem in Wordpress