mdadm

From CaveLab

mdadm is a Linux utility used to manage and monitor software RAID devices. (source: Wikipedia)

Status

cat /proc/mdstat
mdadm --detail /dev/md0

Create

RAID 0

sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sda /dev/sdb

RAID 6

sudo mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sda /dev/sdb /dev/sdc /dev/sdd

Persist

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u

echo '/dev/md0 /srv/md0 ext4 defaults,nofail,noatime 0 2' | sudo tee -a /etc/fstab

Modify

Add drive

mdadm --add /dev/md0 /dev/sda

Grow array

mdadm -v --grow --raid-devices=7 /dev/md0

Remove drive

mdadm --manage /dev/md0 --fail /dev/sde1
mdadm --manage /dev/md0 --remove /dev/sde1

Replace disk

mdadm /dev/md0 --add /dev/sdc1
mdadm /dev/md0 --replace /dev/sdd1 --with /dev/sdc1

Check and resize partition

fsck.ext4 -f /dev/md0 # must be done unmounted
resize2fs /dev/md0    # can be done mounted (on-line)

Performance

echo 8192 | sudo tee /sys/block/md0/md/stripe_cache_size

Stop and delete

mdadm --stop /dev/md0
mdadm --remove /dev/md0
mdadm --zero-superblock /dev/sda(1) # delete superblock

Problems

sdd1 does not have a valid v1.2 superblock
Add --update=devicesize when assembling.