Installing Software RAID on Centos 5/6/7 via SSH 11

Considering number of dedicated server rentals that just gives JBOD, setting up your own software raid is quite handy. This tutorial goes over the very basic of how it’s done.

All of this should be done under root.
Let’s say you have 3 disks: sda, sdb & sdc. The OS is mounted on the sda, so we’ll leave that alone and make a raid 1 with sdb and sdc.

Use mdadm to create your software raid

First, make sure mdadm is installed.

yum install mdadm

Assuming that the disks sdb & sdc are unmounted & unused, we can create a raid with the two of them by telling mdadm to create the partition.

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

If you have more disks, adjust the raid devices parameter and more devices listed at the end. Other levels of RAID can be setup as well like 0, 10, etc just by changing the –level parameter. So, if you were making a raid0 of 3 disks, you could call

mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

for example.

You can confirm the setup by looking at mdstat.

cat /proc/mdstat

Now we add the device information to a configuration file for mdadm so that they’re always available.

echo "DEVICE /dev/sdb /dev/sdc" > /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf
echo "MAILADDR youremailaddress@example.com" >> /etc/mdadm.conf
mdadm -As /dev/md0

Including MAILADDR is critical for getting notifications, but it’s also critical for getting the monitor running. On newer versions (7’s repo), the monitor will not run without MAILADDR parameter.

mdmonitor for your RAID

Now that we have a RAID array, they need to be monitored. This can be done through the mdmonitor service.

service mdmonitor start
chkconfig mdmonitor on

If you’re on Centos 7, you’ll need to use the new systemctl instead.

systemctl start mdmonitor
systemctl enable mdmonitor

Making the file system & mounting it

Next, we’ll create the file system that uses this raid array and call it /dev/md0 with the file system ext4

mkfs -t ext4 /dev/md0

You can now mount md0 to any folder you want. Like…

mount /dev/md0 /home/grumpyland

The new mount point should now appear when you call df

df

We want the mount to be always there when we start up the server, so, we need to add it to fstab too using your favorite editor. I always found nano to be the most newbie friendly with the instruction on the bottom.

nano /etc/fstab

There, you’ll want to add a line about the md0 we just made. Note that the directory to be mounted must already exist!

/dev/md0                /home/grumpyland           ext4    defaults        0 0

That’s it! I hope this simplified tutorial was helpful. For further information on mdadm, check out its man pages.

11 thoughts on “Installing Software RAID on Centos 5/6/7 via SSH

  1. Reply Michael Mba Aug 18,2014 12:02 pm

    Totally helpful. Thanks very, very much for taking the time to write and share this.

    😀

  2. Reply NavazKhan Sep 22,2014 11:48 am

    Hi,

    Is there any way to perform this in GUI…

    Regards,

    Navaz Khan

    • Reply Grumpy Sep 22,2014 12:10 pm

      During your initial centos install, there is a partition manager that does this with GUI.

      If you already have the system installed, I’m not sure if you can bring that back up, but there are third party partition managers like Palimpsest, KDE Partition Manager (kde based), and GParted (gnome based).

      There is also a bit of a convoluted (assuming you don’t have webmin) solution of doing it via webmin.

  3. Reply Adriaan Oct 2,2014 4:10 pm

    Thanks, the guide helped me setup my raid 5 on 4 x WD 2TB Black drives!

  4. Reply Hadi Oct 11,2014 6:00 am

    Hello
    It was useful and I am going to translate and put it on my website http://www.irwebhost.com

    Thank you

  5. Reply azed Oct 18,2014 3:16 pm

    Hello,

    I have a server with two HD, sda and sdb. I changed sda recentely.

    How can I Raidsoft the server now please?

    • Reply Grumpy Oct 19,2014 7:28 pm

      This method is about installing raid on unused drives. It doesn’t work if it’s already being used. You will have to setup the raid during os install, not after. If you have setup partitions, you can also use the partitions instead of the full drive by adding the respective partition name instead of the drive name.

  6. Reply Bill Oct 26,2014 8:21 am

    Many thanks for the simple guide. Just as a note, works perfectly on CentOS 7 (virtualized) with 1 boot disk (virtual), 3 other virtual disks.

  7. Reply Vivek Jun 15,2015 8:52 am

    After reboot there is no raid device !!!!

    please help

  8. Reply vivek Aug 28,2015 7:11 am

    mdadm: cannot open /dev/sde: Device or resource busy

    OS : centos 6.5

    installing raid 0, please help

Leave a Reply