204.1 Configuring RAID (weight: 3)

Tech Tutorial: 204.1 Configuring RAID (weight: 3) #

Introduction #

Redundant Array of Independent Disks (RAID) is a data storage virtualization technology that combines multiple physical disk drive components into one or more logical units. The purpose of RAID is to enhance data redundancy and improve performance. In this tutorial, we will delve into configuring RAID on a Linux system, covering all essential commands and procedures necessary to achieve a robust setup.

Key Knowledge Areas: #

  • RAID concepts
  • Levels of RAID
  • Tools required to configure RAID
  • Configuring different types of RAID
  • RAID maintenance

Utilities: #

  • mdadm
  • mdmon

Prerequisites #

This tutorial assumes that you have a basic understanding of Linux commands and that you have superuser (root) access on your Linux system. You should also have at least two spare hard drives (or virtual hard drives in a virtual environment) to configure RAID.

Step-by-Step Guide #

1. Installing mdadm #

mdadm is the utility used to manage software RAID arrays. To install mdadm, use the package manager applicable to your distribution:

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install mdadm

For Red Hat/CentOS:

sudo yum update
sudo yum install mdadm

2. Checking the Disks #

Before configuring RAID, check the disks available on your system:

lsblk

You’ll see output similar to this:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   100G  0 disk 
sdb      8:16   0   100G  0 disk 
sdc      8:32   0   100G  0 disk 

3. Creating Different Levels of RAID #

RAID 0 (Striping) #

To create a RAID 0 array, use the following command:

sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc

Verify the RAID:

cat /proc/mdstat

RAID 1 (Mirroring) #

For RAID 1 setup:

sudo mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

Verify the RAID:

cat /proc/mdstat

RAID 5 (Striped with Parity) #

To configure RAID 5, you need at least three disks:

sudo mdadm --create --verbose /dev/md2 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

Verify the RAID:

cat /proc/mdstat

4. Configuring the Filesystem #

After creating the RAID, format it to use a filesystem:

sudo mkfs.ext4 /dev/md0

Mount the RAID:

mkdir /mnt/raid0
sudo mount /dev/md0 /mnt/raid0

5. RAID Maintenance #

Adding a new disk to an existing RAID:

sudo mdadm --add /dev/md0 /dev/sde

Removing a disk:

sudo mdadm --fail /dev/md0 /dev/sde
sudo mdadm --remove /dev/md0 /dev/sde

Monitoring RAID:

sudo mdadm --detail /dev/md0

6. Configuring mdadm.conf #

Update or create mdadm.conf to ensure RAID arrays are reassembled at boot:

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

Update initramfs:

sudo update-initramfs -u

Conclusion #

Configuring RAID in Linux using mdadm provides a flexible and robust solution for enhancing data storage reliability and performance. Whether you’re setting up a new server or looking to improve an existing system, understanding RAID configurations will greatly benefit your data management strategies. Remember to regularly monitor and maintain your RAID arrays to ensure data integrity and system performance.