Mdadm
From Bashlinux
How to create a RAID
mdadm --create /dev/md0 --level=raid10 --raid-devices=4 /dev/sd[abcd]1
How to replace a failed drive on a RAID
- Stop the RAID
# swapoff -a # mdadm -S $RAID
- Mark drive as failed
# mdadm --manage /dev/md0 --fail /dev/sda1 # mdadm --manage /dev/md1 --fail /dev/sda2
- Prepare drive to be removed
# mdadm --manage /dev/md0 --remove /dev/sda1 # mdadm --manage /dev/md1 --remove /dev/sda2
- Take off the failed drive and put the new one. Note that new drive must match the old one in size, cache and speed.
- Clean up the new drive before to add it into a RAID
# mdadm --zero-superblock /dev/sda1
- Clone the partition table and MBR from the next drive
# dd if=/dev/sdb of=/dev/sda bs=512 count=1
- or
# sfdisk -d /dev/sda | sfdisk --force /dev/sdb
- Reload the partition table
# partprobe /dev/sda
- Re-attach the drive to the RAID
# mdadm --manage /dev/md0 --add /dev/sda1 # mdadm --manage /dev/md1 --add /dev/sda2
- Restore mdadm.conf
# mdadm --examine --scan >> /etc/mdadm.conf
- Add the proper entries on /etc/fstab
- In order to match the UUID for each disk
blkid
will get you the UUIDs for each md device
- In order to match the UUID for each disk
How to resize a partition
- Grow up the partition
# mdadm --grow /dev/md2 --size=max
- Check the file system
# e2fsck -f /dev/md2
- Resize the filesystem
# resize2fs /dev/md2
- Re-chek the filesystem after re-size
# e2fsck -f /dev/md2
How to activate an spare drive
Make sue the RAID has enough room for the current amount of RAID devices plus the spare device(s)
# mdadm --grow /dev/md2 --raid-devices=3
- Remove the failed drive
# mdadm --manage /dev/md2 --fail /dev/sdb3 # mdadm --manage /dev/md2 --remove /dev/sdb3
- Clean the status of the raid by restoring the amount of raid devices
# mdadm --grow /dev/md2 --raid-devices=2