Set up RAID arrays with mdadm for performance and redundancy

Intermediate 45 min May 04, 2026 98 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Configure Linux software RAID arrays with mdadm to improve disk performance and protect against drive failures. Learn to create RAID 0, 1, 5, 6, and 10 configurations with automatic monitoring and management.

Prerequisites

  • Multiple unused storage devices (minimum 2 drives)
  • Root or sudo access
  • Basic understanding of Linux disk management

What this solves

Software RAID with mdadm lets you combine multiple physical drives into a single logical volume for better performance, redundancy, or both. This tutorial shows you how to create different RAID levels, configure automatic assembly on boot, and monitor array health for production systems.

Install mdadm and prepare storage devices

Install mdadm package

The mdadm utility manages software RAID arrays on Linux systems.

sudo apt update
sudo apt install -y mdadm
sudo dnf update -y
sudo dnf install -y mdadm

Identify available storage devices

Check which drives are available for RAID configuration. Look for unused devices without existing partitions.

lsblk
fdisk -l

This tutorial assumes you have drives at /dev/sdb, /dev/sdc, /dev/sdd, and /dev/sde. Adjust paths based on your system.

Wipe existing data from drives

Clear any existing partition tables or filesystem signatures from the drives you'll use for RAID.

Warning: This will permanently delete all data on the specified drives. Double-check device names before proceeding.
sudo wipefs -af /dev/sdb /dev/sdc /dev/sdd /dev/sde
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=10
sudo dd if=/dev/zero of=/dev/sdc bs=1M count=10
sudo dd if=/dev/zero of=/dev/sdd bs=1M count=10
sudo dd if=/dev/zero of=/dev/sde bs=1M count=10

Create RAID arrays with mdadm

Create RAID 0 array for maximum performance

RAID 0 stripes data across drives for best performance but provides no redundancy. One drive failure destroys the entire array.

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

Format the array with a filesystem:

sudo mkfs.ext4 /dev/md0
sudo mkdir /mnt/raid0
sudo mount /dev/md0 /mnt/raid0

Create RAID 1 array for data mirroring

RAID 1 mirrors data across drives, providing complete redundancy. You can lose one drive without data loss.

sudo mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdd /dev/sde

Format and mount the mirrored array:

sudo mkfs.ext4 /dev/md1
sudo mkdir /mnt/raid1
sudo mount /dev/md1 /mnt/raid1

Create RAID 5 array for balanced performance and redundancy

RAID 5 requires at least 3 drives and can survive the loss of one drive while maintaining data integrity.

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

Format the RAID 5 array:

sudo mkfs.ext4 /dev/md5
sudo mkdir /mnt/raid5
sudo mount /dev/md5 /mnt/raid5

Create RAID 6 array for dual drive fault tolerance

RAID 6 requires at least 4 drives and can survive the failure of any two drives simultaneously.

sudo mdadm --create --verbose /dev/md6 --level=6 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

Format and mount the RAID 6 array:

sudo mkfs.ext4 /dev/md6
sudo mkdir /mnt/raid6
sudo mount /dev/md6 /mnt/raid6

Create RAID 10 array for maximum performance and redundancy

RAID 10 combines mirroring and striping, requiring at least 4 drives. It provides excellent performance and can survive multiple drive failures.

sudo mdadm --create --verbose /dev/md10 --level=10 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

Format the RAID 10 array:

sudo mkfs.ext4 /dev/md10
sudo mkdir /mnt/raid10
sudo mount /dev/md10 /mnt/raid10

Configure automatic RAID assembly and monitoring

Save RAID configuration to mdadm.conf

Generate the configuration file so arrays are automatically assembled at boot time.

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

Update the initramfs to include RAID configuration:

sudo update-initramfs -u
sudo dracut --force

Configure permanent mount points

Add RAID arrays to /etc/fstab for automatic mounting at boot.

echo '/dev/md1 /mnt/raid1 ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab
echo '/dev/md10 /mnt/raid10 ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab

The nofail option prevents boot failures if a RAID array has issues.

Enable mdadm monitoring service

Configure email alerts for RAID events like drive failures or degraded arrays.

MAILADDR admin@example.com

Start and enable the monitoring daemon:

sudo systemctl enable --now mdmonitor
sudo systemctl status mdmonitor

Set up automated health checks

Configure monthly scrubbing to detect and correct errors proactively.

#!/bin/bash
for array in $(cat /proc/mdstat | grep -o 'md[0-9]*'); do
    echo check > /sys/block/${array}/md/sync_action
done

Make the script executable:

sudo chmod +x /etc/cron.monthly/raid-check

Monitor RAID health and manage failed drives

Check RAID array status

Monitor the health and performance of your RAID arrays with these commands.

cat /proc/mdstat
sudo mdadm --detail /dev/md1
sudo mdadm --detail /dev/md10

Look for State : clean and all drives showing as active sync status.

Simulate and handle drive failures

Mark a drive as failed to test your monitoring and replacement procedures.

sudo mdadm --manage /dev/md1 --fail /dev/sde

Remove the failed drive from the array:

sudo mdadm --manage /dev/md1 --remove /dev/sde

Add a replacement drive to rebuild the array:

sudo mdadm --manage /dev/md1 --add /dev/sdf

Monitor rebuild progress

Track the progress of array rebuilds and data synchronization.

watch -n 5 'cat /proc/mdstat'
sudo mdadm --detail /dev/md1 | grep -E "State|Rebuild Status"

Rebuilds can take several hours depending on drive size and system load.

Set up SMART monitoring integration

Combine RAID monitoring with disk health checks using smartmontools.

sudo apt install -y smartmontools
sudo dnf install -y smartmontools

Configure SMART monitoring for early drive failure detection:

/dev/sdb -a -m admin@example.com
/dev/sdc -a -m admin@example.com
/dev/sdd -a -m admin@example.com
/dev/sde -a -m admin@example.com
sudo systemctl enable --now smartd

Verify your setup

Confirm your RAID arrays are working correctly and will survive reboots.

cat /proc/mdstat
sudo mdadm --detail --scan
sudo mdadm --detail /dev/md1
df -h /mnt/raid1 /mnt/raid10
sudo systemctl status mdmonitor
sudo systemctl status smartd

Test write performance on different RAID levels:

sudo dd if=/dev/zero of=/mnt/raid1/testfile bs=1M count=1000 oflag=direct
sudo dd if=/dev/zero of=/mnt/raid10/testfile bs=1M count=1000 oflag=direct

Common issues

SymptomCauseFix
Array fails to assemble at bootMissing mdadm.conf or initramfs not updatedsudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf and rebuild initramfs
Drive shows as "spare" instead of "active"Array size mismatch or partition alignmentUse --force flag or repartition drives with identical sizes
Poor write performance on RAID 5/6No write cache or small chunk sizeEnable write cache with mdadm --readwrite /dev/mdX and tune chunk size
Email alerts not workingNo mail system configuredInstall and configure system logging or use external monitoring
RAID array marked as dirty after crashUnclean shutdown during write operationssudo mdadm --assemble --force /dev/mdX then run filesystem check

Next steps

Running this in production?

Want this handled for you? Setting up RAID arrays is straightforward. Keeping them monitored, maintaining spare drives, handling midnight rebuild alerts, and coordinating replacements across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed cloud infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.