Useful Mdadm Commands
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 |
Force the kernel to reread the partition table
partprobe |
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 |
Thanks for the info,
I’m re-setupping a failed array…
short story:
I had a Raid 5 with 4 disks,
I wanted to replace a failed drive, because I could not afford to lose another disk
and when I inserted a new drive, (freshly fdisk’ed)
and added it to the array,
mdadm somehow identified the disk as a disk that was used in the array a long time ago, and I went from a perfectly working degraded array, to a completely screwed up array…I lost everything
I thought to myself…how can mdadm be so stupid !!?
So..
Now I want to do a lot of adding/removing to make sure I have the proper set of commands