RAID-5 in Ubuntu with mdadm

Couldn’t really find anyone who’d documented setting up a RAID 5 array with Linux and mdadm, so figured I’d jot down the method I used in Ubuntu 6.10. It basically boils down to four commands (I am assuming you have a fresh install):

sudo apt-get install mdadm
sudo mdadm --create /dev/md0 --raid-devices=5 /dev/sd[abcde]1 --level=raid5
sudo mke2fs -j /dev/md0
sudo mount /dev/md0 /mnt/raid

To explain a little:

The first command installs mdadm.

The second command creates the raid array /dev/md0, then sets how many disks – and their respective locations – there’ll be in the array. In my case, we have 5 750GB drives, which are /dev/sda through to /dev/sde. The 1 is the partition identifier. Level sets the raid level, which in this case is raid5.

The third command ‘sudo mke2fs -j /dev/md0 ‘ makes an ext3 filesystem on the array.

And finally ‘sudo mount /dev/md0 /mnt/raid‘ mounts the array to /mnt/raid (you can mount it wherever you like)

Note 1: Make sure you have mdadm installed. If you don’t: sudo apt-get install mdadm

Note 2: If you’re not using Ubuntu, su to root and run the commands without ’sudo’

Note 3: If you get an error stating ‘mdadm: error opening /dev/md0: No such file or directory’, you need to bypass udev and use this command instead: sudo mdadm --create /dev/md0 --raid-devices=5 /dev/sd[abcde]1 --level=raid5 --auto=yes

Note 4: To view the status of your array: sudo mdadm --detail /dev/md0

Note 5: If you need to view a list of your hard drives, try these commands: ls -l /dev/sd* or ls -l /dev/hd*

I am certainly no Linux expert. Corrections, and suggestions on how to improve this method are encouraged :)

Update: There’s a very thorough guide here, but it seems to cover some GUI elements – which wasn’t an option for me.

Related posts

5 Comments »

  1. Free Enterprise Search | Mind Circus said,

    21 March, 2007 at 12:35 pm

    [...] you follow this blog, you’ll know that I recently setup an Ubuntu box running Samba with a 2.7TB Raid5 array. Its job is to replace one of our 300GB Dell PowerEdge 715N NAS boxes which has become [...]

  2. Mind Circus » RAID on Linux with USB devices said,

    6 April, 2007 at 2:13 pm

    [...] ports on a system, you could just add more drives on the USB bus. this would be nice for the new RAID5 set up. Granted there’s the physical space/storage issues, but it’s still properly accessible [...]

  3. Johannes said,

    14 May, 2009 at 1:33 pm

    Worked like a charm on Ubuntu 9.10 Server with 4×1TB in Raid 5 using ext4

  4. Phil Wiffen said,

    14 May, 2009 at 4:32 pm

    Awesome :) Thanks for feeding back Johannes!

  5. Zvon said,

    1 June, 2009 at 1:58 pm

    Thanks for this, it works great, but you might need to expand it a little…. to include how to make it automatically come up on reboot.

    I followed these instructions, then when i rebooted the server, the raid array wasnt running.

    need to add settings into /etc/mdadm/mdadm.conf
    and also include an entry in fstab.

RSS feed for comments on this post · TrackBack URL

Leave a Comment