Useful Mdadm Commands
December 16th, 2007
Below is a collection of commands for mdadm that I have found useful. Use these at your own risk.
Create RAID
mdadm --create /dev/md0 --level=5 --raid-devices=4 /dev/sd[bcde]1 mkfs.ext3 /dev/md0
Remove disk from RAID
mdadm --fail /dev/md0 /dev/sda1 mdadm --remove /dev/md0 /dev/sda1
Copy the partition structure (when replacing a failed drive)
sfdisk -d /dev/sda | sfdisk /dev/sdb mdadm --zero-superblock /dev/sdb
Add a disk to a RAID array (to replace a removed failed drive)
mdadm --add /dev/md0 /dev/sdf1
Check RAID status
cat /proc/mdstat mdadm --detail /dev/md0
Reassemble a group of RAID disks
mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
Steps to emulate mdrun (which has been depreciated)
mdadm --examine --scan --config=partitions > /tmp/mdadm.conf mdadm --assemble --scan --config=/tmp/mdadm.conf
Convert a RAID 1 array to RAID 5 (follow the steps to add a disk after running this command)
mdadm --create /dev/md0 --level=5 -n 2 /dev/sda1 /dev/sdb1
Add a disk to an existing RAID and resize the filesystem
mdadm --add /dev/md0 /dev/sdg1 mdadm --grow /dev/md0 -n 5 fsck.ext3 -f /dev/md0 resize2fs /dev/md0
Stop and remove the RAID device
mdadm --stop /dev/md0 mdadm --remove /dev/md0