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

27 comments:

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

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

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

    ReplyDelete
  4. 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
  5. Nice article Thank you for sharing. We are providing Best Red hat Linux Online Training. for more Visit Red Hat Linux Online Training

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

    ReplyDelete
  7. 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
  8. Really it was an awesome article...very interesting to read..You have provided an nice article..We also visit here linux training,red hat training ..Thanks for sharing..

    ReplyDelete
  9. It was a very useful Information.... Thanks for sharing.
    Linux Training in Noida

    ReplyDelete
  10. I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.

    Php Institute in Gurgaon
    Php Course in Gurgaon
    Php Training in Gurgaon
    Java Institute in Gurgaon
    Java Course in Gurgaon
    Java Training in Gurgaon
    C++ Institute in Gurgaon
    C++ Course in Gurgaon
    C++ Training in Gurgaon

    ReplyDelete
  11. Thank you for sharing such great information very useful to us.
    Linux Training in Noida

    ReplyDelete
  12. To do my best in the exam I chose Pass4sure Microsoft dumps for my preparation. It gave me a comprehensive understanding about every concept of the field in a way that I was able to answer each question in the final exam. I am fully satisfied with my selection of Microsoft dumps.

    ReplyDelete
  13. APTRON has designed its RHCE training for IT professional and wannabes who seek to achieve practical skills of networking and security administration. Our RHCE training project is armed with the faculties who are IT professional with more 10 year experience in core area and filled with technical knowledge and real world experience with the significant spotlight on practical knowledge with the end goal of giving required skills to a Linux administrator's job assignments.
    For More Info:- Linux Training in Gurgaon

    ReplyDelete
  14. Thanks for sharing, nice post! Post really provice useful information!

    Công ty vận chuyển hàng nước ngoài gửi hàng đi mỹ, gửi hàng đi nhậtgửi hàng đi đài loan và dịch vụ chuyển phát nhanh đi hàn quốc uy tín, giá rẻ

    ReplyDelete
  15. Thank you for such useful information on Linux. It was really very useful.

    ReplyDelete
  16. Thanks for the great article this is very useful info thanks for the wonderful post.

    Best Linux Online Training Institute

    ReplyDelete
  17. I am really impressed. you have written really nice a blog. Thanks for sharing.

    Best Linux Course in Mumbai

    ReplyDelete
  18. The article is so appealing. You should read this article before choosing the Big Data Solutions Developer you want to learn.

    ReplyDelete
  19. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    Artificial Intelligence Training
    Java Training
    AWS Training
    Machine Learning Training
    Data Science Training
    DevOps Training

    ReplyDelete
  20. Great Post. Very informative. Keep Sharing!!
    Apply Now for Linux Training Classes in Noida
    For more details about the course fee, duration, classes, certification, and placement call our expert at 70-70-90-50-90

    ReplyDelete