Create a Linux software RAID array

Posted by Al Banks in Linux

This recipe is a spin-off from my blog entry on building an inexpensive storage server, if you want more commentary, see my blog.


Note, I’ve done this on an Ubuntu system – other distributions may be slightly different.

First thing, the mdadm utility is needed. sudo apt-get install mdadm will grab this for you.

Next, we’ll need some disk partitions. These can be on the same physical disk (mdadm may gripe about this), good for testing, but for “real” data, use partitions on separate physical disks.

In this example, I have /dev/sda3, /dev/sdb3, and /dev/sdc4, all are are 1175GB.

Now, let’s build…

sudo mdadm --create /dev/md0 --level=RAID5 --raid-devices=2 /dev/sda3 /dev/sdb3 /dev/sdb4

There are other levels which may be more appropriate to your situation.

Give this a little bit of time to run, you can check progress with sudo mdadm -D /dev/md0 or cat /proc/mdstatThese will give you a good idea of the time remaining in the array construction.

Let mdadm run its course for a while, then you can go ahead and format the drive. I did this before the build was complete, but you can wait if you want.

I chose jfs, but there are other filesystems that may be appropriate for your needs. mkfs.jfs /dev/md0

Once the filesystem is done, mount the device to use it. I created a directory, /mnt/raid, and mounted the device there:mount /dev/md0 /mnt/raid

If desired, an entry can be created in fstab to make this easier.

The Conversation

Follow the reactions below and share your own thoughts.

  • Robert

    no.
    first, why are you making a raid of paritions of the hard drives. you use full drives, and only full drives to make your raid arrays. second, make sure to use parted and put a GUID table on. youre probably still running around with an MS-DOS partition table (fdisk). anything beyond 2TB will be useless if yore using fdisk-type partition tables.

    First, backup your data, and wipe all 3 hard drives clean. You don’t want to raid parts of each hard drive. Its useless. do parted /dev/sda, mklabel, gpt. GPT is the GUID partition table, far greater than the MSDOS part. table in both capacity and usefulness otherwise (contains redundancy, etc. wiki it.)

    Anywho, wipe the 3 hard drives, put the GUID partition table and whatever filesystem you like (XFS is my personal favorite when handling music/video files….it handles large files better. If youre going for small files, use Reiserfs. These are the only two filesystems you should consider. Ever.) Now you have /dev/sda1 created with XFS, on the whole drive, and two blank drives. Then, do mdadm –create /dev/md0 -l5 -d3 /dev/sda1 /dev/sdb /dev /sdc, itll take time, obviously, then youre ready to mount.

    If you’re using the partitions because you have different sized drives, you shouldnt be making a raid anyways. RAID requires planning, and obviously you didnt.

    In short, if you’re still using ubuntu, and you think you can try some cool server admin stuff, youre probably wrong. Ubuntu is linux for human beings. Server admins aren’t human beings. Don’t try to be like them.

  • Linux beginner

    Thanks for this GREAT post. It cleared up so many of my RAID problems that other just didn’t mention in their RAID-How-Tos! Unfortunately others appear to have missed your point entirely and played the: I am great at Linux now so you are stupid for having to start somewhere, card!

  • please use ubuntu only at home – not for enterprise server

    I say one word only: Slackware