System and processes

The mdadm command

Creates, reassembles and inspects Linux software RAID (md) arrays.

Syntax

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdcTry it in the terminal →

Most useful options

-C, --createCreates a new array on the given md device, for example /dev/md0.
-l, --level=RAID level, such as raid1 or raid5. Numeric aliases such as 1 or 5 are accepted.
-n, --raid-devices=Number of active devices. With 1 it requires --force; RAID 4, 5 and 6 do not allow it.
-D, --detailShows the detailed status of an active md array.
--zero-superblockOverwrites the md superblock of a device with zeros. It is destructive.

Copy-ready examples

$ sudo mdadm --detail /dev/md0shows the status of array md0: level, devices and whether it is healthy.
$ cat /proc/mdstatlists every array on the system and the progress of a rebuild. It does not need sudo.
$ sudo mdadm --add /dev/md0 /dev/sddwarning: adds /dev/sdd to md0 to replace a failed disk. It changes the composition of the array.
$ sudo mdadm --stop /dev/md0warning: stops md0. Unmount its filesystem with umount first.
$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdcwarning: writes RAID metadata to both disks. Any data they held must be considered lost: make a backup first.

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • With --raid-devices=1, mdadm requires --force, and RAID 4, 5 and 6 do not allow a single active device, according to the manual.
  • A new array does not simply keep what was on its disks: treat it as a destructive operation and make a backup first.
  • --zero-superblock has no undo. With --force it writes zeros even where the superblock does not look valid.
  • Live status is in /proc/mdstat, and --detail gives the array detail. It is worth checking both after a failure.

Differences from similar commands

  • parted: creates and edits partitions on a disk. mdadm builds an array on disks or partitions that already exist.
  • lsblk: shows the hierarchy of disks, partitions and md arrays. mdadm is what creates and manages them.
  • mkfs.ext4: creates a filesystem. mdadm only creates the md device; formatting comes afterwards, inside the array.

FAQ

How do I see whether the array is rebuilding?

Check /proc/mdstat, where the progress appears. With mdadm --detail /dev/md0 you see the array status.

What is the md superblock?

Metadata a disk stores to recognise itself as an array member. mdadm -E shows it.

What should I do before stopping an array?

Unmount its filesystems with umount. If they stay mounted, the system may fail when the device disappears.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course