Linux RAID Configuration and Details

What is RAID?

RAID (Redundant Array of Independent Disks) is a data storage virtualization technology that combines multiple physical drives into a single logical unit to improve performance, redundancy, or both.

Types of RAID

RAID Configuration Commands

Below are some common commands used to configure RAID in Linux:

Install mdadm

sudo apt install mdadm

Redhat base installation

sudo yum install mdadm

Create a RAID Array

sudo mdadm --create /dev/md0 --active yes --level=1 --raid-devices=2 /dev/sdX /dev/sdY

Options:

Check RAID Status

cat /proc/mdstat

Stop a RAID Array

sudo mdadm --stop /dev/md0

Remove a RAID Array

sudo mdadm --remove /dev/md0

Example RAID Configuration

To create a RAID 1 array with two devices:

sudo mdadm --create /dev/md0 --active yes --level=1 --raid-devices=2 /dev/sdX /dev/sdY

After creating the array, format it with a filesystem:

sudo mkfs.ext4 /dev/md0

Then mount it:

sudo mount /dev/md0 /mnt

Add a new disk in RAID configuration

To add a new disk to an existing RAID array, follow these steps:

  1. Identify the new disk (e.g., /dev/sdZ).
  2. Add the new disk to the RAID array:
  3. sudo mdadm --add /dev/md0 /dev/sdZ
  4. Resync the RAID array:
  5. sudo mdadm --grow /dev/md0 --raid-devices=3