mdadm — quick reference
Create arrays
Requires partitioned or whole-disk members with matching role for the chosen level. Use spare loop files under /tmp for practice — never experiment on production RAID volumes.
| When to use | Command |
|---|---|
| Create RAID 0 (stripe) with N devices | sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1 |
| Create RAID 1 (mirror) | sudo mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1 |
| Create RAID 5 (minimum three devices) | sudo mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 |
| Create RAID 10 | sudo mdadm --create /dev/md10 --level=10 --raid-devices=4 /dev/sd{b,c,d,e}1 |
| Skip creation prompts in scripts | sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1 --run |
| Name the array (metadata tag) | sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 --name=backup /dev/sdb1 /dev/sdc1 |
Inspect arrays and members
| When to use | Command |
|---|---|
| Short summary of an MD device | sudo mdadm --query /dev/md0 |
| Full array detail | sudo mdadm --detail /dev/md0 |
| Examine superblock on a component | sudo mdadm --examine /dev/sdb1 |
| Kernel view of active arrays | cat /proc/mdstat |
| Emit ARRAY lines for mdadm.conf | sudo mdadm --detail --scan |
Stop, zero, and assemble
| When to use | Command |
|---|---|
| Stop an array (unmount first) | sudo mdadm --stop /dev/md0 |
| Stop every array listed in mdstat | sudo mdadm --stop --scan |
| Erase MD superblock so disk can be reused | sudo mdadm --zero-superblock /dev/sdb1 |
| Assemble arrays from mdadm.conf | sudo mdadm --assemble --scan |
| Assemble one known array | sudo mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1 |
Manage members
| When to use | Command |
|---|---|
| Mark a device failed | sudo mdadm /dev/md0 --fail /dev/sdb1 |
| Remove a failed device | sudo mdadm /dev/md0 --remove /dev/sdb1 |
| Add a device to an array | sudo mdadm /dev/md0 --add /dev/sdd1 |
| Add a hot spare | sudo mdadm /dev/md0 --add /dev/sdd1 |
Help and version
| When to use | Command |
|---|---|
| Top-level usage | mdadm --help |
| Mode-specific options | mdadm --create --help |
| Package version | mdadm --version |
mdadm — command syntax
Synopsis from mdadm --help on Ubuntu 25.04 (mdadm 4.4):
mdadm --create device options...
mdadm --assemble device options...
mdadm --build device options...
mdadm --manage device options...
mdadm --misc options... devices
mdadm --grow options device
mdadm --incremental device
mdadm --monitor options...
mdadm device options... # shorthand for --managemdadm writes RAID superblocks to member devices and registers arrays with the md kernel driver. Creating or zeroing superblocks destroys data on those members.
mdadm — command examples
Essential Create RAID 0 on loop-backed files (lab)
File-backed arrays are safe for learning — use real partitions (/dev/sdb1) in production with the same flags.
dd if=/dev/zero of=/tmp/md1.img bs=1M count=32 status=none
dd if=/dev/zero of=/tmp/md2.img bs=1M count=32 status=none
L1=$(sudo losetup -f --show /tmp/md1.img)
L2=$(sudo losetup -f --show /tmp/md2.img)
sudo mdadm --create /dev/md127 --level=0 --raid-devices=2 $L1 $L2 --runSample output:
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md127 started.Verify:
cat /proc/mdstatSample output:
md127 : active raid0 loop28[1] loop27[0]
61440 blocks super 1.2 512k chunksStop and clean up:
sudo mdadm --stop /dev/md127
sudo mdadm --zero-superblock $L1 $L2
sudo losetup -d $L1 $L2
rm -f /tmp/md1.img /tmp/md2.imgEssential Query and detail an active array
sudo mdadm --query /dev/md127
sudo mdadm --detail /dev/md127Sample --query line:
/dev/md127: 60.00MiB raid0 2 devices, 0 spares. Use mdadm --detail for more detail.Sample --detail excerpt:
Raid Level : raid0
Array Size : 61440 (60.00 MiB 62.91 MB)
Raid Devices : 2
State : clean
Active Devices : 2Run these read-only commands on existing production arrays when auditing health — they do not modify metadata.
Common Examine superblock on a member disk
--examine reads metadata on a component even when the array is stopped — useful before reusing a disk.
sudo mdadm --examine /dev/sdb1Sample fields from a lab member:
Magic : a92b4efc
Version : 1.2
Raid Level : raid0
Raid Devices : 2
State : cleanOn Ubuntu, full walkthroughs for RAID 1 and RAID 5 with real disks are in the RAID 1 and RAID 5 guides.
Common Generate mdadm.conf ARRAY lines
Ubuntu stores the config at /etc/mdadm/mdadm.conf. --detail --scan prints ARRAY lines you can merge into that file for boot-time assembly.
sudo mdadm --detail --scanSample line:
ARRAY /dev/md127 metadata=1.2 UUID=4cf28406:d4c8c78d:33a8821b:c62fbec5Append only after reviewing — do not overwrite production config in a lab test.
Common Stop an array and clear superblocks
Unmount filesystems before --stop. --zero-superblock lets you repartition members for a new array.
sudo umount /dev/md0
sudo mdadm --stop /dev/md0
sudo mdadm --zero-superblock /dev/sdb1 /dev/sdc1Sample stop message:
mdadm: stopped /dev/md0Skipping umount leaves the array busy and --stop fails.
Common Watch resync progress in /proc/mdstat
During RAID 1 and RAID 5 rebuilds, /proc/mdstat shows resync progress:
md1 : active raid1 sdc1[1] sdb1[0]
10475520 blocks super 1.2 [2/2] [UU]
[=====>...............] resync = 28.4%When [UU] appears and resync reaches 100%, format the array with mke2fs or mkfs.ext4.
Advanced Assemble arrays at boot
After importing ARRAY lines into /etc/mdadm/mdadm.conf and running update-initramfs -u on Debian/Ubuntu:
sudo mdadm --assemble --scanSample success line:
mdadm: /dev/md/0 has been started with 2 drives.On a fresh lab VM with no arrays defined, this command may print nothing — that is normal.
Advanced Creation prompts on mismatched devices
If a member still contains a filesystem signature, mdadm asks for confirmation unless --run or --force is supplied. Always double-check device names — mdadm --create is destructive.
mdadm: /dev/sdb1 appears to contain an ext4 filesystem.
Continue creating array? (y/n)Answer n unless you intend to wipe the underlying data.
mdadm — when to use / when not
| Use mdadm when | Use something else when |
|---|---|
|
|
mdadm vs hardware RAID
| mdadm (software) | Hardware RAID | |
|---|---|---|
| Layer | Linux kernel MD driver | RAID controller firmware |
| Cost | No controller required | Requires RAID HBA |
| Portability | Arrays tied to Linux MD metadata | Vendor-specific |
| Tooling | mdadm, /proc/mdstat |
storcli, ssacli, etc. |
Related commands
| Command | One line |
|---|---|
| mdadm | Software RAID management (this page) |
| losetup | Loop files for safe RAID practice |
| cat /proc/mdstat | Kernel RAID status |
Browse the full index in our Linux commands reference.
mdadm — interview corner
What does mdadm manage?
mdadm controls Linux MD (multiple device) RAID — kernel md devices such as /dev/md0 built from partitions or disks. It creates metadata superblocks, starts and stops arrays, and reports failed members.
A strong answer is:
"mdadm is the userspace tool for Linux software RAID — create, assemble, monitor, and stop md arrays."
How many disks for RAID 0, 1, and 5?
RAID 0 stripes across two or more devices (no redundancy). RAID 1 mirrors two or more copies. RAID 5 needs at least three devices for distributed parity.
A strong answer is:
"RAID 0 minimum two disks, no redundancy; RAID 1 two for mirror; RAID 5 three for parity."
Where do you check RAID sync status?
/proc/mdstat shows active personalities, member states ([UU] = both mirrors up), and resync percentages. mdadm --detail adds UUID, chunk size, and event counters.
A strong answer is:
"I watch /proc/mdstat for resync progress and mdadm --detail for metadata and failed devices."
Why run --zero-superblock?
It removes MD metadata from a disk so you can repartition or join a different array without stale RAID signatures confusing mdadm or blkid.
A strong answer is:
"--zero-superblock wipes RAID metadata so the disk can be reused cleanly — only after stopping the array and backing up data."
What does mdadm --detail --scan output?
ARRAY lines with device path, metadata version, and UUID for /etc/mdadm/mdadm.conf (Ubuntu) so initramfs can assemble arrays at boot.
A strong answer is:
"It prints ARRAY lines for mdadm.conf — device, metadata version, and UUID for boot-time assembly."
Troubleshooting
| Symptom | Likely cause | What to try |
|---|---|---|
mdadm: cannot open /dev/md0: No such file |
Array not started | mdadm --assemble or check /proc/mdstat |
mdadm: error opening /dev/sdb1: Device or resource busy |
Filesystem mounted | umount, then --stop or --zero-superblock |
Found some drive for an array that is already active |
Member still in another array | mdadm --detail each disk; stop duplicate arrays |
| Resync stuck | Failed member or slow disk | mdadm --detail, replace failed drive, check dmesg |
Continue creating array? prompt |
Filesystem signature on member | Confirm correct disk; backup before answering y |
