Skip to main content

mdadm - Linux Software RAID

The mdadm utility in Linux is used for creating, managing and monitoring software RAID setups.

RAID is a method for combining multiple disk drives into a single unit to improve performance, redundancy, or both.

Checking Existing Array

You can check if there are any existing RAID array by running the following:

cat /proc/mdstat

Screenshot_2024-07-22_212702.png

You can check the details of the RAID array by running the following: 

#Syntax
mdadm --detail /dev/<md RAID name>

#Wxample
mdadm --detail /dev/md127

Screenshot_2024-07-05_221838.png

Creating RAID 1 Array

First, check existing drives on the system with lsblk, and note down the device name that you want to use in the array.

lsblk

For RAID 1, you will need a minimum of 2 drives. 

Run the following to setup your RAID 1 array:

#Syntax
sudo mdadm --create --verbose /dev/md{number_not_already_used} --level=1 --raid-devices=2 /dev/{device_1} /dev/{device_2}

#Example
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdc

Screenshot_2024-07-22_214004.png

Rebuild Array

To rebuild a member in an array, first remove the old array member and replace it with a new drive device. 

Then run the following to tell mdadm to add a new disk to the array:

#Syntax
mdadm --manage /dev/<md RAID name> -a /dev/<replacement drive name>

#Example
mdadm --manage /dev/md127 -a /dev/nvme0n1

Screenshot_2024-07-05_221839.png

If you run mdadm --detail , you will see that the RAID is rebuilding. 

Screenshot_2024-07-05_222018.png