Configure "Raid 5" in Linux

RAID level 0, 1, 5, 6 and 10 | Advantage, disadvantage, use

Configuring RAID 5 on CentOS 9 involves combining multiple disks into a single RAID array that provides both redundancy and improved performance through parity striping. Here’s a step-by-step guide on how to set up RAID 5 using mdadm, a utility commonly used for managing software RAID in Linux:

Step-by-Step Guide to Configure RAID 5 on CentOS 9

Step 1: Install Required Packages

Ensure that mdadm (the utility for managing RAID arrays) is installed on your CentOS system. If it's not installed, you can install it using the following command:

sudo dnf install mdadm

Step 2: Identify Disks

Identify the disks that you want to use for RAID 5. For this example, let's assume you have three disks: /dev/sda, /dev/sdb, and /dev/sdc.

Step 3: Partition Disks

If your disks are new or need reconfiguration, you should partition them appropriately. You can use tools like fdisk, parted, or gdisk to create partitions on each disk. For RAID 5, we typically use partitions of similar size across all disks.

sudo fdisk /dev/sda
# Create a new partition (e.g., /dev/sda1) covering the desired space

sudo fdisk /dev/sdb
# Create a new partition (e.g., /dev/sdb1) covering the desired space

sudo fdisk /dev/sdc
# Create a new partition (e.g., /dev/sdc1) covering the desired space

Step 4: Create RAID 5 Array

Now, create the RAID 5 array using mdadm. RAID 5 requires at least three disks:

sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1
  • /dev/md0 is the name of the RAID device.

  • --level=5 specifies RAID level 5 (striping with distributed parity).

  • --raid-devices=3 specifies the number of devices in the RAID array (in this case, three disks).

  • /dev/sda1, /dev/sdb1, and /dev/sdc1 are the partitions we created earlier on /dev/sda, /dev/sdb, and /dev/sdc.

Step 5: Verify RAID Configuration

Check the status of the RAID array to ensure it was created successfully:

sudo mdadm --detail /dev/md0

This command provides detailed information about the RAID array md0, including its status, devices, and RAID level.

Step 6: Create a Filesystem

Next, create a filesystem on the RAID array. For example, to create an ext4 filesystem:

sudo mkfs.ext4 /dev/md0

Step 7: Mount the RAID Array

Create a mount point and mount the RAID array:

sudo mkdir /mnt/raid5
sudo mount /dev/md0 /mnt/raid5

Step 8: Configure Mount at Boot

To ensure the RAID array mounts automatically at boot time, add an entry to /etc/fstab:

echo '/dev/md0   /mnt/raid5   ext4   defaults   0 0' | sudo tee -a /etc/fstab

Step 9: Test and Verify

Reboot your system to test if the RAID array mounts automatically and correctly. After rebooting, verify that the RAID array is still operational:

sudo mdadm --detail /dev/md0

Ensure that all disks (/dev/sda1, /dev/sdb1, /dev/sdc1) are active and in sync (U state).

Additional Notes:

  • Always replace /dev/sda1, /dev/sdb1, /dev/sdc1, etc., with the appropriate partitions on your disks.

  • Customize RAID level (--level), RAID device name (/dev/md0), filesystem type (ext4), and mount point (/mnt/raid5) as per your requirements.

  • RAID 5 provides both performance and redundancy benefits through striping and distributed parity. It can tolerate the failure of one disk without data loss.

  • Monitor the RAID array regularly (sudo mdadm --detail /dev/md0) to ensure all disks are functioning properly and to detect any potential issues early.

By following these steps, you can successfully set up RAID 5 on CentOS 9 using mdadm, providing both data redundancy and performance improvements for your storage solution.