mdadm

Use mdadm to create RAID levels.

Modes (from the man page):

Options:

mdadm --assemble md-device ...

For create, build, or grow:

mdadm --build md-device ...
mdadm --create md-device ...

For assemble:

mdadm --assemble md-device ...

For manage mode:

mdadm --md-device ...

For misc. mode:

mdadm md-device options... devices...

For monitor mode:

Setup RAID

RAID1

RAID1 is for mirroring data across disks. If one drive fails, the data is still preserved.

Create the RAID1 array using the two harddrives:

mdadm --create /dev/md0 -l raid1 -n 2 /dev/sdb1 /dev/sdc1

Monitor the creation of the RAID1 drive:

mdadm --monitor

Create a filesystem:

mkfs.ext3 /dev/md0

Stop the array:

mdadm --stop /dev/md0

Start the array:

mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1

RAID5

RAID5 is for mirroring and striping. It will combine two disks and use the third for parity checks. If two drives fail, all the data is lost. At least three devices are needed.

Create a RAID5 array
mdadm --create /dev/md0 --level=5 -n 3 /dev/sda1 /dev/sdb1 /dev/sdc1

Howto

Add a drive to an existing RAID setup

In this scenario, /dev/sda1 and /dev/sdb1 already exist as block devices, and we are adding /dev/sdc1 to the array.

mdadm --add /dev/md0 /dev/sdc1
mdadm --grow --raid-devices=3 /dev/md0

See here for more instructions before doing this.

Gotchas

removed block devices

When mdadm is started building / rebuilding an array, it will create /dev/mdX entries, and remove the block devices that are part of the RAID (/dev/sda1, /dev/sdb1, fex). After stopping mdadm, run partprobe to load the device nodes. It will restart mdadm, but stopping it the second time will leave the device blocks there.

Examples

From the man page.

Query the device to see if it's a RAID array, or part of one, etc.:

mdadm --query device

Scan the config file and assemble and start all arrays:

mdadm --assemble --scan

Shut down all arrays that can be shut down; not currently in use:

mdadm --stop --scan

Check devices that have RAID superblocks and print out results:

mdadm --examine --brief --scan --config=partitions