Monday, April 22, 2013

Linux RAID (RedHat,CentOS,Fedora,SELinux)

Hi Everyone,
Today, I am going to explain that how you can create a software RAID in Linux (RedHat families). In this case, I am creating a RAID-5 with 3 disks and each disk has only 1 Giga bytes capacity. As you probably know, for RAID-5, we need at least 3 disks with the same size. So, RAID-5 writes data blocks to N-1 disks, in this case 2, and parity blocks to N disk which is 3 in this case. This means that we have 2 Giga bytes to use and RAID-5 always uses one disk for parity. And you may say that we are wasting 1 Giga bytes or 1 disk here, however you protect the system against the failure of one disk. Therefore, if one disk fails, you can replace it easily by another disk without being worry about losing data. Of course, RAID-5 has its own advantages and disadvantages but it is not related to this topic now.

So, I added 3 new raw disks. I can confirm that by running the fdisk -l command (Figure 1).

                                                                                Figure 1

The md command (Multiple Disks)is used to create a software RAID. The following command builds a RAID-5 array from my 3 disks (Figure 2) and activates it:

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

                                                                               Figure 2

/proc/mdstat contains a summary of RAID/Array status. Run the following command:
cat /proc/mdstat (Figure 3)


                                                                             Figure 3

Also, take a look at the /var/log/messages file (Figure 4):

                                                                     Figure 4

Now, we need to dump the current RAID setup into a configuration file. Then, the configuration file can be read at startup or shutdown to esaily manage the array. Run the following commands (Figure 5):

echo "DEVICE /dev/sdb /dev/sdc /dev/sdd" > /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf


                                                                     Figure 5

The following command enables array to read the /etc/mdadm.conf file at startup:
mdadm -As /dev/md0

To stop the array manually, run the following command:
mdadm -S /dev/md0

To monitor our array and send notifications for any problems by email, add a MAILADDR line to the /etc/mdadm.conf. Then, start the service (Figure 6):

echo "MAILADDR root@localhost.localdomain" >> /etc/mdadm.conf
service mdmonitor start


To start mdmonitor at boot time, run the following command:
chkconfig mdmonitor on



                                                                        Figure 6

To simulate a failed disk, run the following command and then read the email notifications (Figure 7,8):
mdadm /dev/md0 -f /dev/sdc

Figure 7

Figure 8

Also, take a look at /var/log/messages file (Figure 9):

                                                                         Figure 9

To remove the disk from array and array configuration, run the following command (Figure 10):
mdadm /dev/md0 -r /dev/sdc

Now, replace the disk (if it supports Hot-swap drive hardware, otherwise turn off system) and run the following command to add the disk back to array (Figure 10):

mdadm /dev/md0 -a /dev/sdc

Take a look at the log file again (Figure 10):

                                                                         Figure 10

In order to use this RAID5 array, we need to format it and then mount it. Afterward, use df -h command to verify it (Figure 11):

                                                                             Figure 11

To mount the array at boot time, edit /etc/fstab and add the following line (Figure 12):
/dev/md0    /media/RAID5    ext4    defaults    0 0

                                                                          Figure 12

And that's all.
Hope you enjoyed.
Khosro Taraghi

12 comments:

  1. Thanks I'm new to Linux and this was a huge help.

    ReplyDelete
  2. hi...Im student from Informatics engineering nice article,
    thanks for sharing :)

    ReplyDelete
  3. what is the best book to refer the Linux commands and basic concepts for the fresher???? pls help me

    ReplyDelete
  4. Very nice explanation... its helps a lot. thanks for sharing

    ReplyDelete
  5. Thanks for review, it was excellent and very informative.
    thank you :)

    ReplyDelete
  6. The Red Hat Linux Online Training Certification is a week-long course, provides intensive system administration training enabling participants to develop the skills they need to effectively administer Red Hat Enterprise Linux.
    We are providing Best Red Hat Linux Online Training. for more visit this link
    Red hat Linux Online Training

    ReplyDelete
  7. Nice article Thank you for sharing. We are providing Best Red hat Linux Online Training. for more Visit Red Hat Linux Online Training

    ReplyDelete
  8. This course relates to Red Hat Enterprise Linux 7 and is for IT professionals without previous Linux administration experience. Red Hat Training

    ReplyDelete
  9. Thanks for nice topic. Very useful information.
    IthubOnlineTraining are good in giving the <a href=" http://www.ithubonlinetraining.com/red-hat-linux-online-training/ redhatlinux onlineTraining</a>

    ReplyDelete
  10. Your blog is much effective and thanks for sharing information.. Here we are providing training & materilas and dumps for those who are preparing for cca 175 spark and hadoop developer certification exam and in the related fields of cloudera hadoop developer certification exam.
    cca 175 certification
    cloudera hadoop developer certification

    ReplyDelete
  11. Swiming is the best exercise in summer and running in winter
    QU-IT & QU

    ReplyDelete