Informational Website publish


News about our company, tutorials about IT and much more you will find in this page.

Install a Software RAID on Centos 5/6/7 via SSH

Janeiro 30th, 2018

Let’s say you have 3 disks: sda, sdb & sdc. The OS is mounted on the sda, so we’ll leave that alone, and we want to make a raid 1 / raid 0 with sdb and sdc. This tutorial goes over the very basic of how this is done.

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.

On CentOS 7

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

On CentOS 6

  • sudo 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 input for example:

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

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 email @" >> /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…

  • mkdir /storage
  • mount /dev/md0 /storage

The new mount point should now appear when you call df:

$ df or lsblk

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.

  • vi /etc/fstab

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

/dev/md0              /storage              ext4    defaults        0 2


Removing the RAID Array *Optional*

In case you no longer want to use your RAID Array, and instead want to use your drives separately or on another computer, follow the below instructions.

Important Note: This will remove all data stored on the RAID Array, so move the data you want to save to another partition/drive before proceeding.

First unmount the RAID Array:

  • umount -l /dev/md0

Now shutdown the array using:

  • mdadm –stop /dev/md0

Once deactivated, remove the RAID Array itself:

  • mdadm –remove /dev/md0

And to finish it off, zero the superblock on all devices that were associated with the particular array:

  • mdadm –zero-superblock /dev/sdb /dev/sdc

Your RAID Array is now deleted and the drives ready to be used on any other application.