Creating RAID 5 (Striping with Distributed Parity) in Linux – Part 4

In RAID 5, data stripes are distributed across multiple drives with distributed parity. Splitting with distributed parity means that you will split parity information and band data across multiple disks, which will have good data redundancy.

Setup Raid 5 in CentOS
Setup Raid 5 in Linux

For the RAID level you must have at least three hard drives or more. RAID 5 is used in the large-scale production environment, where it is cost-effective and provides performance and redundancy.

What is parity?

Parity is the simplest common method for detecting errors in data storage. Parity stores information on each disk, let’s say we have 4 disks, on 4 disks a disk space will be divided across all disks to store parity information. If any of the disks fail, we can still get the data rebuilding from the parity information after replacing the failed disk.

Pros and cons of RAID 5

  1. Offers better performance
  2. Redundancy support and fault tolerance
  3. .

  4. Supports hot spare options
  5. .

  6. You will lose a single disk capacity to use parity information
  7. .

  8. There is no data loss if a single disk fails. We can rebuild from parity after replacing the failed disk.
  9. It adapts to a transaction-oriented environment, since the reading will be faster.
  10. Due to parity overhead, writing will be slow.
  11. Rebuilding takes a long time.

Requirements

A minimum of 3 hard drives are required to create Raid 5, but you can add more disks, only if you have a dedicated hardware RAID controller with multiple ports. Here, we are using the software RAID and the ‘mdadm‘ package to create a raid.

mdadm is a package that allows us to configure and manage RAID devices on Linux. By default there is no configuration file available for RAID, we must save the configuration file after creating and configuring the RAID configuration in a separate file called mdadm.conf.

Before proceeding, I suggest you review the following articles to understand the basics of RAID on Linux.

RAID Basics on Linux – Part 1 Creating RAID 0 (Stripe) on Linux – Part 2 Configuring RAID 1

  1. (Mirroring) on Linux –
  2. Part 3 Configuring

My Server

Operating System : CentOS 6.5 Final IP Address : 192.168.0.227 Hostname : rd5.tecmintlocal.com Disk 1 [20GB] : /dev/sdb Disk 2 [20GB] : /dev/sdc Disk 3 [20GB] : /dev/sdd

This article is Part 4 From a RAID series of 9 tutorials, here we are going to configure a RAID 5 software with distributed parity on Linux systems or servers using three 20GB disks named /dev/sdb, /dev/sdc and /dev/sdd.

Step 1: Installing mdadm and verifying drives

1. As we said earlier, we are using CentOS 6.5 Final version for this raid configuration, but the same steps can be followed for RAID configuration on any Linux-based distribution.

# lsb_release -a # ifconfig | grep inet

CentOS 6.5 Summary

2. If you are following our raid series, we assume you have already installed the ‘mdadm‘ package, if not, use the following command according to your Linux distribution to install the package.

# yum install mdadm [on RedHat systems] # apt-get install mdadm [on Debain systems]

3. After the installation of the ‘mdadm‘ package, let’s list the three 20 GB disks that we have added to our system using the ‘fdisk‘ command.

# fdisk -l | grep sd

Install mdadm Tool on CentOS
Install mdadm Tool

4. Now it’s time to scan the three connected drives for existing RAID blocks on these drives using the following command.

# mdadm -E /dev/sd[b-d] # mdadm -examine /dev/sdb /dev/sdc /dev/sdd

Scan drives for Raid
Scan drives for RAID

Note: The image illustrated above shows that no superblocks have been detected yet. Therefore, there is no RAID defined on all three drives. Let’s start creating one now.

Step 2: Partition the disks for RAID

5. First, we need to partition the disks (/dev/sdb, /dev/sd c and /dev/sdd) before adding them to a RAID, so let’s define the partition using the ‘fdisk’ command, before forwarding it to the next steps.

# fdisk /dev/sdb # fdisk /dev/sdc # fdisk /dev/sdd Create Partition /dev/sdb

Follow the instructions below to create a partition on the /dev/sdb drive

. Press ‘n’ to

  1. create a new partition
  2. .

  3. Then choose ‘P‘ for the primary partition. Here we are choosing Primary because there are no defined partitions yet.
  4. Then choose ‘1‘ to be the first partition. By default, it will be 1.
  5. Here for the cylinder size, we

  6. don’t have to choose the specified size because we need the entire partition for RAID, so just press Enter twice to choose the default full size.
  7. Next, press ‘p‘ to print the created partition.
  8. Change the type, if we need to know all the available types press ‘L‘.
  9. Here, we are selecting ‘fd‘ since my type is RAID.
  10. Then press ‘p‘ to print the defined partition.
  11. Then, again, use ‘p‘ to print the changes we’ve made.
  12. Use ‘w‘ to write the changes.
<img src="https://www.tecmint.com/wp-content/uploads/2014/11/Install-mdadm-Tool.png" alt=

“Create sdb partition” />Create sdb partition

Note: We need to follow the steps mentioned above to create partitions for sdc and sdd drives as well. Create Partition /dev/sdc Now partition the sdc and

sdd

leads by following the steps given in the screenshot or you can follow the steps above. # fdisk /dev/sdc Create sdc partitionCreate sdc partition Create partition /dev/sdd # fdisk /dev/sdd

Create sdd partition
Create sdd

6 partition. After creating partitions, check for changes to the three sdb, sdc, and sdd drives.

# mdadm -examine /dev/sdb /dev/sdc /dev/sdd or # mdadm -E /dev/sd[b-d]

Check Partition Changes
Check Partition

Changes Note: In the image above. representing the type is fd is that is, for RAID.

7. Now check the RAID blocks on the newly created partitions. If no superblocks are detected, we can move forward to create a new RAID 5 configuration on these drives.

Check Raid on Partition
Check Raid on Partition

Step 3: Create the md md0

8 device. Now create a RAID device ‘md0’ (i.e. /dev/md0) and include the raid level on all newly created partitions (sdb1, sdc1 and sdd1) using the following command.

# mdadm -create /dev/md0 -level=5 -raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 or # mdadm -C /dev/md0 -l=5 -n=3 /dev/sd[b-d]1

9. After creating the raid device, check and verify the RAID, included devices, and RAID level from the mdstat output.

# cat /proc/mdstat

Verify RAID device
Verify RAID device

If you want to monitor the current build process, you can use the ‘watch’ command, just go through the ‘cat/proc/mdstat’ with the watch command that will refresh the screen every 1 second. # clock -n1 cat /proc/mdstat

Monitor Raid ProcessMonitor Raid 5 Process<

img

src=”https://www.tecmint.com/wp-content/uploads/2014/11/Create-sdd-Partition1-383×450.png” alt=”Raid 5 Process Summary

” />
Raid 5 Process Summary

10. After raid creation, verify the RAID devices using the following command.

# mdadm -E /dev/sd[b-d]1

Check RAID level
Check RAID level

Note: The output of the above command will be a bit long as it prints the information of the three drives

.

11. Next, check the RAID array to assume that the devices we have included in the RAID level are running and started to re-sync.

# mdadm -detail /dev/md0

Verify Raid Array
Verify Raid Array

Step 4: Create the file system for md0

12. Create a file system for device ‘md0‘ using ext4 before mounting.

# mkfs.ext4 /dev/md0 <img src="https://www.tecmint.com/wp-content/uploads/2014/11/Verify-Raid-Device.png" alt="Create md0 file

system” />
Create md0 file system

13. Now create a directory in ‘/mnt’, then mount the file system created in /mnt/raid5 and check the files on the mount point, you will see the lost+found directory.

# mkdir /mnt/raid5 # mount /dev/md0 /mnt/raid5/ # ls -l /mnt/raid5/

14. Create some files under mount point /mnt/raid5 and add text in any of the files to verify the contents.

# touch /mnt/raid5/raid5_tecmint_{1..5} # ls -l /mnt/raid5/ # echo “tecmint raid setups” > /mnt/raid5/raid5_tecmint_1 # cat /mnt/raid5/raid5_tecmint_1 # cat /proc/mdstat

<img src="https://www.tecmint.com/wp-content/uploads/2014/11/Verify-Raid-Device-620×263.png" alt="Mount Raid 5 Device" />
Mount Raid Device

15. We need to add an entry in fstab, otherwise it will not show our mount point after the system reboot. To add an entry, we need to edit the fstab file and add the following line as shown below. The mount point will vary depending on your environment.

# vim /etc/fstab /dev/md0 /mnt/raid5 ext4 defaults 0

0 Raid 5 Automount

16. Next, run the ‘mount -av‘ command to check for errors in the fstab entry.

# mount -av <img src="https://www.tecmint.com/wp-content/uploads/2014/11/Raid-Process-Summary.png" alt="Check Fstab Errors

” />
Check Fstab Errors

Step 5: Save the Raid 5 17 configuration

. As mentioned earlier in the requirements section, by default RAID does not have a configuration file. We have to save it manually. If this step is not followed, the RAID device will not be at md0, it will be at some other random number.

Therefore, we must save the settings before the system restarts. If the configuration is saved, it will be loaded into the kernel during system reboot and RAID will also be loaded.

# mdadm -detail -scan -verbose >> /etc/mdadm.conf

<img src="https://www.tecmint.com/wp-content/uploads/2014/11/Raid-Process-Summary-620×187.png" alt="Save Raid 5 Configuration" />
Save Raid 5

Configuration Note: Saving the configuration will keep the RAID level stable on the md0 device

.

Step 6: Add spare units

18. What’s the use of adding a spare unit? It is very useful if we have a spare drive, if any of the disks fail in our array, this spare drive will activate and rebuild the process and synchronize the data from other disks, so we can see a redundancy here.

For more instructions on how to add a spare drive and check Raid 5 fault tolerance, read #Step 6 and #Step 7 in the following article.

  1. Add Spare Drive to Raid 5 Setup

Conclusion

Here in this article, we have seen how to set up a RAID 5 using three disks. Later in my next articles, we’ll look at how to troubleshoot when a disk fails in RAID 5 and how to replace it for recovery.

Contact US