Mdadm software raid – cheat sheet

Create a new RAID array (raid-1) #

To create a new raid array, please type (for sda1 and sdb1 for example):

$ mdadm –create –verbose /dev/md0 –level=1 /dev/sda1 /dev/sdb1

Where /dev/sda1 and /dev/sdb1 have the same size.

To remove failing drive (eg. sda1) from array, you need to mark it as fail first by typing:

$ mdadm –fail /dev/md0 /dev/sda1

And remove it from array by typing following command:

$ mdadm –remove /dev/md0 /dev/sda1

You can also mark disk as failed and remove it in one line command:

$ mdadm /dev/md0 –fail /dev/sda1 –remove /dev/sda1

Add a new disk to an existing array:

$ mdadm –add /dev/md0 /dev/sdc1

Check the array status:

$ mdadm –detail /dev/md0

You can also check the array status by checking /proc/mdstat:

$ cat /proc/mdstat

To stop and remove RAID array, please type:

$ mdadm –stop /dev/md0
$ mdadm –remove /dev/md0

Please remember also to remove RAID super block:

$ mdadm –zero-superblock /dev/sda1
$ mdadm –zero-superblock /dev/sdab