HOWTO+-+Software+RAID+in+Linux+with+mdadm

To get the running md devices code format="bash" cat /proc/mdstat code

To create a raid5 with 3 active hard disks and 1 hot spare code format="bash" mdadm --create /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sd[bcde]1 code

To add a disk to an active array (as a hotspare) code format="bash" mdadm /dev/md0 --add /dev/sdf1 code

To enlarge a RAID5 array (unmount it first, run the command following and change accordingly the mdadm.conf file) code format="bash" mdadm --grow /dev/md0 --raid-devices=4 code

To extend a RAID partition (useful if you have progressively changed the drives of the array to larger hard drives: []) code format="bash" mdadm --grow /dev/md0 --size=max code

To remove a hot spare disk code format="bash" mdadm /dev/md0 --remove /dev/sdf code

To remove an active disk (we have to mark it as "fail" first) code format="bash" mdadm /dev/md0 --fail /dev/sdb1 --remove /dev/sdb1 code

Make sure that the raid will work after a reboot by putting the output of the command "mdadm --detail --scan" into /etc/mdadm/mdadm.conf code format="bash" mdadm --detail --scan code using mkconf will create a new mdadm.conf code format="bash" /usr/share/mdadm/mkconf code

To stop one raid device code format="bash" mdadm --stop /dev/md0 code

To start the raid again code format="bash" mdadm -As /dev/md0 code

To remove the RAID Superblock from the hard disks code format="bash" mdadm --zero-superblock --force /dev/sd[bcde]1 code

In case of any failure or if you forgotten to add the array into mdadm.conf try the assemble option code format="bash" mdadm --assemble --scan code

Make sure if you want to totally remove a raid, to remove it also from mdadm.conf