MDADM Cheat Sheet (2)


create a new array

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


mdadm -C /dev/md0 -l1 -n2 /dev/sd[ab]1

add array to the configuration file:

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

or on debian (sigh)…

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

can only remove failed disks from an array, so fail a disk:

mdadm --fail /dev/md0 /dev/sda1

remove the failed disk from the array:

mdadm --remove /dev/md0 /dev/sda1

fail and remove in a single step:

mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

add a new disk to an existing array (or replace a failed disk):

mdadm --add /dev/md0 /dev/sda1

verify an array

mdadm --detail /dev/md0

or, for all arrays…

cat /proc/mdstat

  • output should contain U for each member of the array
  • a failed disk status code is F
  • degraded arrays will be missing disks

remove an arry (first, must be stopped)

mdadm --stop /dev/md0 ; mdadm --remove /dev/md0

better: test for successful stop

mdadm --stop /dev/md0 && mdadm --remove /dev/md0

remove the superblock from the array members’ partitions

mdadm --zero-superblock /dev/sda

copy a partition table from one disk to another

sfdisk -d /dev/sda | sfdisk /dev/sdb

this is not strictly a raid command, but often handy since raid arrays are usually composed of multiple, identical disks.


Please enter your comment!
Please enter your name here