Setting Up Raid on Linux Using Mdadm

Posted on Feb 9, 2025

Introduction

Redundant Array of Independent Disks (RAID) is a technology that enhances storage performance, redundancy, or both. While hardware RAID has been around for decades, Linux users commonly employ mdadm (Multiple Device Admin) to create and manage software RAID arrays.

In this guide, we will explore RAID’s history, its early challenges, and how to set up various RAID levels (RAID 0, 1, 5, 10) using mdadm in Linux.

A Brief History of RAID

RAID was first conceptualized in 1987 by David A. Patterson, Garth A. Gibson, and Randy H. Katz at UC Berkeley. Their paper, “A Case for Redundant Arrays of Inexpensive Disks,” introduced multiple RAID levels, each balancing speed, fault tolerance, and cost-effectiveness.

Before RAID became mainstream, storage solutions relied on single large expensive disks (SLEDs). Failures meant complete data loss, and expanding storage was cumbersome. RAID allowed combining smaller, cheaper disks into more reliable and efficient storage solutions.

Understanding RAID Levels

Here are some of the most commonly used RAID levels:

  • RAID 0 (Striping): Focuses on performance; no redundancy.
  • RAID 1 (Mirroring): Provides redundancy by duplicating data.
  • RAID 5 (Striping with Parity): Balances performance and fault tolerance.
  • RAID 10 (Mirrored Striping): A combination of RAID 0 and RAID 1 for speed and redundancy.

Installing mdadm

Before setting up RAID, ensure mdadm is installed on your system:

sudo apt update && sudo apt install mdadm -y  # Debian-based systems
sudo yum install mdadm -y                     # RHEL-based systems

Setting Up RAID with mdadm

RAID 0: Striping (No Redundancy, Maximum Speed)

RAID 0 improves performance by striping data across multiple disks. However, if one disk fails, all data is lost.

Steps to Create RAID 0:

sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sd[b-c]

--level=0: RAID 0 level. --raid-devices=2: Uses two disks (e.g., /dev/sdb and /dev/sdc).

RAID 1: Mirroring (High Redundancy)

RAID 1 duplicates data across two drives, providing redundancy but at the cost of usable storage space.

Steps to Create RAID 1:

sudo mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sd[d-e]
  • If one drive fails, replace it and reassemble RAID with:
sudo mdadm --add /dev/md1 /dev/sdX  # Replace sdX with the new disk

RAID 5: Striping with Parity (Balanced Performance & Redundancy)

RAID 5 requires at least three disks. It offers a balance between performance and fault tolerance.

Steps to Create RAID 5:

sudo mdadm --create --verbose /dev/md5 --level=5 --raid-devices=3 /dev/sd[f-h]
  • RAID 5 can survive one disk failure.
  • If a disk fails, replace it and rebuild RAID:
sudo mdadm --add /dev/md5 /dev/sdX  # Replace sdX with the new disk

RAID 10: Mirrored Striping (Best Performance & Redundancy)

RAID 10 requires at least four disks and combines striping and mirroring.

Steps to Create RAID 10:

sudo mdadm --create --verbose /dev/md10 --level=10 --raid-devices=4 /dev/sd[i-l]
  • Offers speed of RAID 0 with redundancy of RAID 1.
  • Can tolerate up to one failed disk per mirrored pair.

Formatting and Mounting RAID Arrays

Once RAID is set up, format and mount the RAID array:

sudo mkfs.ext4 /dev/md0   # Replace md0 with your RAID array
sudo mkdir /mnt/raid0
sudo mount /dev/md0 /mnt/raid0

To make it persistent across reboots:

echo "/dev/md0 /mnt/raid0 ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab

Verifying RAID Status

To check the RAID status:

cat /proc/mdstat
sudo mdadm --detail /dev/md0

Stopping and Removing a RAID Array

If you want to remove a RAID array:

sudo umount /mnt/raid0
sudo mdadm --stop /dev/md0
sudo mdadm --remove /dev/md0

Conclusion

Using mdadm, Linux users can create robust RAID arrays for improved performance, redundancy, or both. Understanding RAID’s history, benefits, and setup process empowers system administrators to implement storage solutions tailored to their needs.

Would you like to explore RAID troubleshooting or RAID monitoring next? Let us know in the comments!