
mdadm: Practical RAID management for Linux
mdadm: Practical RAID management for Linux
mdadm is the go-to command-line tool for managing Linux software RAID arrays. This guide focuses on common tasks, with concrete examples and quick tips for beginners and intermediate users.
Quick start: what you can do
- Create an array
- Stop or fail a disk
- Remove or add disks
- Inspect array details
- Clear RAID metadata on a disk
Below are representative commands. Adapt the device paths to your system. Run as root or with sudo where indicated.
Create an array
Create a new RAID array with a specific level and number of disks. Replace the placeholders with your actual devices.
sudo mdadm --create /dev/md/MyRAID --level raid_level --raid-devices number_of_disks /dev/sdXN
Notes:
- Replace /dev/md/MyRAID with your desired array device (often /dev/md0).
- Replace raid_level with values like 0, 1, 5, 6, 10, etc.
- Replace number_of_disks with the number of disks in the array.
- Replace /dev/sdXN with the actual disk partitions to include (e.g., /dev/sdb1 /dev/sdc1).
- The system may complain if devices have existing partitions or metadata.
Common pitfall:
- Don’t mix disks with existing data unless you mean to overwrite. mdadm —create initializes new metadata; data on disks will be lost.
Stop an array
If you need to safely stop an array (for maintenance or replacement):
sudo mdadm --stop /dev/md0
Notes:
- Stopping does not power down disks; it just stops the kernel from using the array.
- You may also need to remove the array from the mdadm config after stopping.
Mark a disk as failed
When a disk is suspected to be failing, mark it as failed to prevent syncing on it.
sudo mdadm --fail /dev/md0 /dev/sdXN
Notes:
- Use with caution; failing a disk will typically trigger a rebuild if redundancy allows.
- Ensure you have hot-spare disks configured if you rely on automatic rebuilding.
Remove a disk from an array
If a disk is failed or you need to remove it from the array:
sudo mdadm --remove /dev/md0 /dev/sdXN
Notes:
- The disk must be removed from the array before you can repurpose it.
- After removal, you might want to zero the superblock on the disk.
Add a disk to an array
To re-add or assemble a disk into an existing array:
sudo mdadm --assemble /dev/md0 /dev/sdXN
Notes:
- This is commonly used to re-add a hot spare or a rebuilt disk.
- The disk must have compatible metadata or be prepared for assembly.
Show RAID info
Get a detailed snapshot of an array’s status and configuration:
sudo mdadm --detail /dev/md0
What you’ll see:
- Array state, raid level, number of devices, and which disks are active/failed.
Reset disk by deleting RAID metadata
If a disk has old or conflicting RAID metadata, you can wipe it:
sudo mdadm --zero-superblock /dev/sdXN
Notes:
- This does not touch partitions outside the RAID metadata. Use with care if the disk holds other data.
Common pitfalls to avoid
- Mixing different RAID levels or devices not intended for the same array can corrupt data.
- Running mdadm commands on the wrong device path (e.g., mistaking /dev/sdX for a partition) can cause data loss.
- Not updating the kernel initramfs or mdadm config may cause the array not to assemble after reboot. Run update commands as needed for your distro.
Quick maintenance tips
- Regularly check array health:
sudo mdadm --detail /dev/md0
to verify status.
- Keep a spare drive on hand for hot-replcements if your setup supports it.
- Keep a backup of critical data; RAID is not a substitute for backups.
Where to learn more
- Man page: man mdadm
- Overview: https://manned.org/mdadm
End-to-end example (typical workflow)
- Create a 2-disk RAID 1 array:
sudo mdadm --create /dev/md0 --level 1 --raid-devices 2 /dev/sdb1 /dev/sdc1
- Check status:
sudo mdadm --detail /dev/md0
- Simulate a failure for testing:
sudo mdadm --fail /dev/md0 /dev/sdb1
- Remove failed disk:
sudo mdadm --remove /dev/md0 /dev/sdb1
This guide should give you a solid starting point for typical mdadm tasks without diving into advanced features. As you gain confidence, you can explore more options and automations for your specific hardware and redundancy requirements.