Here is a quick command reference for mdadm utility.

Creating an Array

Linear mode

Append two partitions/block devices to each other, not necessary same size.

#mdadm --create --verbose /dev/md1 --level=linear --raid-devices=2 /dev/sda3 /dev/sdb4


The following command create md0, raid0(stripe), two disk partitions(same size), chunk size 128k(default 64k), verbose output, two partitions get access in parallel.

# mdadm -Cv /dev/md0 -l0 -n2 -c128 /dev/sdd1 /dev/sdc1

Raid1 with spare

Two disk partitions, mirror to each other, the third one is the spare disk(sdd1) which can take over the failed partition.

# mdadm -Cv /dev/md0 -l1 -n2 -c128 /dev/sdd1 /dev/sdc1 --spare-devices=1 /dev/sdd1


Mdadm doesn't support raid3, Raid4 is rarely used, it support block level stripping with a dedicated spare disk.

 #mdadm --create --verbose /dev/md0 --level=4 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 --spare-devices=1 /dev/sde1


The following commad creates a raid5 array, chunk size 128k, using device /dev/sda1,/dev/sdb1,/dev/sdc1,/dev/sdd1,/dev/sde1

#mdadm -Cv /dev/md0 -l5 -n5 -c128 /dev/sd{a,b,c,d,e}1
mdadm: layout defaults to left-symmetric
mdadm: array /dev/md0 started.


Like RAID5, but with two parity segment in each block stripe.

#mdadm -Cv /dev/md1 -l6  /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 


Take number of mirrorsets, and stripe across them as RAID0

# mdadm -Cv /dev/md0 -l10 -n2 -c128 /dev/sdd1 /dev/sdc1 --spare-devices=1 /dev/sdd1

Note: RAID10 is different with raid 1+0

Save the configuration

Use the command to save/update mdadm.conf

mdadm --detail --scan >> /etc/mdadm.conf

Check currenty array status

The output of /proc/mdstat below shows the array is at good condition

 #cat /proc/mdstat 
Personalities : [raid10]
md1 : active raid10 sdc1[0] sdd1[1]
      244195904 blocks 2 near-copies [2/2] [UU]
unused devices: <none>

Misc mode, Get, Exam array info from device

Query Array             

#mdadm --query /dev/md1

Examine array

The examine options (-E or --examine) allows you to print the md superblock (if present) from a block device that could be an array component.

#mdadm -E /dev/sdc1

Array detail info

Check an array's detail info

#mdadm --detail /dev/md

Assemble mode, Start, Stop, rename, and check an Array

Assemble mode is used to start an array that already exists

Stop an array

#mdadm -S /dev/md1

Start an array

If you created the array like below

#mdadm -Cv /dev/md0 -l5 -n5 -c128 /dev/sd{a,b,c,d,e}1

then, run

#mdadm --assemble /dev/md0 /dev/sd{a,b,c,d,e}1

Or, run

# mdadm -As /dev/md0
-A stands for Assemble
-s stands for scan

Or for simple md device case

#mdadm --assemble --scan

In more complex situation, if you only want to specify an arry to start, run

#mdadm --scan --assemble --uuid=a26bf396:31389f83:0df1722d:f404fe4c

Note: mdadm --run /dev/md0 doesn't work

Rename an Array

Option 1, on the fly

#mdadm --detail /dev/md1 ## get detail physical drive info
#mdadm -S /dev/md1
#mdadm --assemble /dev/md2 --super-minor=0 --update=super-minor /dev/sdc1 /dev/sdd1

Option 2, reboot machine

Change the array name in /etc/mdadm.conf, then reboot the machine, the array will come up as new name.(Remember change fstab entry if device name is used)

Managing Arrays

Fail a disk in an array

#mdadm /dev/md1 --fail /dev/sdc1

Remove a disk from an array

#mdadm /dev/md1 --remove /dev/sdc1

Add a disk to an array

 #mdadm /dev/md1 --fail /dev/sdc1

Follow, or Monitor, mode

Monitor a md device

The following command will monitor /dev/md0 (polling every 300 seconds) for critical events. When a fatal error occurs, mdadm will send an email to sysadmin. You can tailor the polling interval and email address to meet your needs. 

#mdadm --monitor --mail=root --delay=300 /dev/md0  

You can also specify -y option to let mdadm write log into syslog.

#mdadm --monitor --mail=root --delay=300 -y /dev/md0 

Set monitor to permenant.

On linux, commonly people just enable mdmonitor, which is a put mdadm to backgroup  daemon mode, it uses the following options.

          chkconfig mdmonitor on
          chkconfig --list mdmonitor
          mdmonitor          0:off    1:off    2:on    3:on    4:on    5:on    6:off   
By default, it uses the following options
          OPTIONS="--monitor --scan -f --pid-file=$PIDFILE"

To test monitoring function, try

          mdadm --monitor  -t /dev/md1