Setting up software RAID-5 on CentOS 6.5

Note: I’ve moved everything to a new server running CentOS 7 and everything works without any problems with the same instructions. The RAID-5 array works on the new server without any modifications.

The hard disk in my home server had a minor hick up recently reminding me of my sloppy backup policy. The error was big enough to force me to make some changes to the server so I decided to start from scratch. The server had previously had several jobs to do, it was a router/gateway, a dhcp server, a dns server and on top of that a virtual machine host running KVM. I had already moved all services other than the VM host to another devices so getting a clean start looked like a good idea.

I decided to set up a RAID-5 array to minimise the risk of data loss because of disk problems and after a little testing I decided to use the built in RAID support in Linux, assuming that it’s more than good enough for my needs.

So for the setup, there are four disks in the machine, one SSD disk for the host OS and three 2TB SATA HDD that will form the RAID array. The SSD disk is /dev/sda, and the disks that will build the array are /dev/sdb, /dev/sdc and /dev/sdd and the RAID array will be named /dev/md0. I will use these device names below, make sure you always substitute them with the correct devices for your setup.

After installing the host OS I started on the RAID. I found several sites and pages with information about how to build a RAID-5 array but no two of them seemed to have the same information so this became a trial and error solution for me, I’m not going to write up all the test I did, only what finally worked. Almost all of it came from this forum thread so most of the credit must go to the user “Nathan” – I’m not registered on this forum so I have no further information about him.

The first step is to create a partition table and one partition on each drive:

Now to create a partition, first take a look at the disk to get some information about it:

With the size information I then create the partition, I name the partitions according to which disk they are on, part1 on sdb, part2 on sdc and part3 on sdd:

Finally set the raid array flag on the partition, note that the “1” in the command is the partition number, it should always be 1 but you can check by printing the information about the device:

Now repeat this for the remaining disks, to jump to the next disk simply use select to jump to the next device and repeat the above steps for each disk:

After this was done I created a new RAID-5 array with mdadm, notice the list of partitions at the end, make sure you use the partitions and not the devices and that they match yours:

Now it may seem that the RAID array is ready but in fact it has only just started. To see how much remains try entering

The “Rebuild Status” line tells you how much of the array building is done. You’ll have to wait until this is at 100% before you can create a partition and format it. You have to run that command over and over until the rebuild is done or you can use a different method that helps you watch the rebuild:

This polls the rebuild process every two seconds and gives you an estimated remaining time as well

Once the RAID array is ready the next step is to create a partition and format it. Start parted up again and create a partition table:

The next step is to initialise the disk for the logical volume manager (LVM). First create the physical volume with pvcreate, then create the volume group with vgcreate and then take a look at the volume group with vgdisplay.

The important information here is the “Free PE / Size”, that’s what we’ll use when creating the logical volume. After that we view the volume information.

Now to format the newly created logical volume, this will take a while:

This next step is to write the raid information to the config file. It’s not strictly necessary but may help if the server is having some problems with the raid arrays or if you are running the md monitoring service you can store your e-mail address here for notification mails (see here).

Now try to mount the new volume somewhere. I want to mount it to a directory called data in the root. So the first thing to do is to create the directory and then mount the device manually to that directory:

This gave me no errors so I umount it again so I can try mounting it with fstab:

To do so I add this line to /etc/fstab:

and then mount it with mount -a and voila, the new RAID-5 array up and running and accessible. I have some more work to do before I can start running virtual machines from the RAID but the most difficult job is done.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.