Mdadm
mdadm is a tool to manage software RAID on linux. It allows you to
- create a (new) software raid array. Think of two USB hard drives that you just bought and that you want to use in a RAID 1 configuration.
- assemble an (existing) array. Think of two USB hard drives that you have in your shelve and that you have already made to a RAID array using the create command. When you re-attach them to your computer, you need to tell the computer how the disks belong together (RAID 0 or RAID 1 for example). That is what the assemble command is for.
Examine Existing Arrays
List the "/proc/mdstat" file to see the capabilities of the kernel, and the existing arrays. If the file does not exist, your kernel does not have md support, and RAID cannot be used. The Personalities it lists are the kinds of RAID that are supported. The rest of the output is RAID devices and RAID arrays that are present.
# cat /proc/mdstat
Create an array
To create a RAID-0 array at /dev/md0 consisting of /dev/sda1 and /dev/sdb1:
# mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sda1 /dev/sdb1 mdadm: chunk size defaults to 64K mdadm: array /dev/md0 started.
The /etc/mdadm.conf file will be maintained by the the kernel's autodetecting facility.
It is possible to combine software raid and Logical Volume Manager for maximum flexibility and reliability.
Assemble an array
Here we have a RAID array out of one disk. The configuration is stored in
/tmp/mdadm.conf:
DEVICE /dev/disk/by-id/scsi-360a98000486e5337524a4f6a4e43542d-part2 ARRAY /dev/md0 level=raid0 num-devices=1 UUID=357d721b:86058e8c:8d746cf9:a620ae3c
Use this config file in conjunction with mdadm's assemble command:
mdadm --assemble --config /tmp/mdadm.conf /dev/md0
Delete an array
To delete an array, stop it using the -S command like this:
mdadm -S /dev/md0
Then remove all disks from the array like this
mdadm -r /dev/sda mdadm -r /dev/sdb
Edit /etc/mdadm/mdadm.conf if it exists.
That's all, now you can re-partition or re-format your disks.