Linux - how to create RAID arrays in Linux using mdadm
Step 1: Install mdadm
Most Linux distributions don’t come with mdadm pre-installed.
sudo apt update # Debian/Ubuntu
sudo apt install mdadm
sudo yum install mdadm # RHEL/CentOS
Verify installation:
mdadm --version
Step 2: Check Available Disks
List all available disks and partitions:
lsblk
sudo fdisk -l
Important: Make sure the disks you plan to use do not have any important data, as creating RAID will erase them.
Step 3: Create Partitions (Optional)
You can use entire disks or create partitions. Example using fdisk:
sudo fdisk /dev/sdb
-
Type
n→ New partition -
Type
t→ Change type →fd(Linux RAID autodetect) -
Type
w→ Write changes
Repeat for each disk you want in the array.
Step 4: Create the RAID Array
The syntax for creating a RAID array:
sudo mdadm --create --verbose /dev/md0 --level=<RAID_LEVEL> --raid-devices=<NUM_DEVICES> /dev/sd[b-e]
Example: Create a RAID 5 array with 3 disks /dev/sdb, /dev/sdc, /dev/sdd:
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
RAID Levels:
-
0→ Striping (no redundancy, fast) -
1→ Mirroring (full redundancy) -
5→ Striping with parity (needs ≥3 disks) -
6→ Striping with double parity (needs ≥4 disks) -
10→ Mirrored + striped (needs ≥4 disks, multiple of 2)
Step 5: Monitor RAID Creation
Check progress of array creation:
cat /proc/mdstat
You should see syncing status.
Step 6: Create a Filesystem
Once RAID is ready, format it:
sudo mkfs.ext4 /dev/md0
You can use other filesystems like xfs or btrfs.
Step 7: Mount the RAID Array
Create a mount point and mount the array:
sudo mkdir -p /mnt/raid
sudo mount /dev/md0 /mnt/raid
Check:
df -h | grep md0
Step 8: Make RAID Mount Persistent
Add entry in /etc/fstab:
sudo blkid /dev/md0
Copy the UUID, then edit fstab:
sudo nano /etc/fstab
Add:
UUID=<UUID_from_blkid> /mnt/raid ext4 defaults 0 0
Step 9: Save RAID Configuration
This ensures RAID automatically assembles on boot:
sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf
Step 10: Verify RAID Array
Check detailed status:
sudo mdadm --detail /dev/md0
You should see RAID level, devices, and state (active/syncing).