Mdadm Cheat Sheet

Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays.
Some common usages of mdadm to manage software raid arrays

 

Verifying the status of the RAID arrays

Checking the status/health of an RAID (also useful for checking a RAID is rebluilding):
cat /proc/mdstat
or
mdadm --detail /dev/md0

Create a new RAID array

Create (mdadm –create) is used to create a new array:
mdadm --create --verbose /dev/md0 --level=1 /dev/sda1 /dev/sdb2

If you get “mdadm: no raid-devices specified” try adding the raid-devices option
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb2

Remove a disk from an array

We can’t remove a disk directly from the array, unless it is failed, so we first have to fail it (unless it already is):
Fail sda1
mdadm --fail /dev/md0 /dev/sda1
Remove sda1 from array
mdadm --remove /dev/md0 /dev/sda1

Add a disk to an existing array

Normally done when replacing a failed disk:
mdadm --add /dev/md0 /dev/sdb1

Stop and delete a RAID array

If we want to completely remove a raid array we have to stop if first and then remove it:
mdadm --stop /dev/md0
mdadm --remove /dev/md0

Remove Superblock
mdadm --zero-superblock /dev/sda

Leave a Reply