Ok so im playing with raids and what not.. and i thought id quickly document the commands so that when i forget them i can find then easily.

You need the package mdadm

Obviously substituing mdX for the raid number ur setting up.. ie md0 and /dev/hdx? with /dev/hdd1 /dev/hdc2 etc

Basic Commands
Checking status of drive/arrays, displaying all raids and basic information
cat /proc/mdstat

Detailed status of array
mdadm --detail /dev/mdX

Creating raid device
mdadm --create --verbose /dev/mdX --level=5 --raid-devices=2 /dev/hdx? /dev/hdx?

Stoping raid device
mdadm --stop /dev/mdX

Adding a drive:
mdadm /dev/mdX -a /dev/hdx?

Marking a drive as failed (This will break things if your not careful)
mdadm --manage --set-faulty /dev/mdX /dev/hdx?

Removing a drive:
mdadm /dev/mdX -r /dev/hdx?

Forcing a full check of the raid:
echo check >> /sys/block/mdX/md/sync_action

Growing array to include new drive (Y is new number of devices)
mdadm --grow --raid-devices=Y /dev/mdX

Creating Array and File system
Create the initall array with the number of devices you want
mdadm --create --verbose /dev/mdX --level=RAID5--raid-devices=3 /dev/hdx? /dev/hdx? /dev/hdx?

Then format the device to include the file system you want (EXT3 in this case:
mkfs.ext3 /dev/mdX

Then mount your /dev/mdX device and your done.

Expanding your array
To expand your array, to have another drive in it.. you first should force a complete check of the drive so that it doesnt fail while rebuilding.
echo check >> /sys/block/mdX/md/sync_action
That will take a while. Then you add your new device.
mdadm /dev/mdX -a /dev/hdx?
If you do a detailed listing of your raid, you will see it list that you now have a spare. To make the raid grow to include this spare.(Y is the number of devices you will have in the array now)
mdadm --grow --raid-devices=Y /dev/mdX
This will take a while again as it rebuilds the array to include the new drive.

Once this has finished you will want to resize the filesystem to have the new space. Make sure you unmount the drive first.
resize2fs /dev/mdX

Chances are resize2fs will ask you to run a fsck on the drive first. It wont work until its satisifed the drive is stable.

Also after having issues where i accidently forgot to plug a drive back in when i rebuilt the case, i went hunting for a way to not have the raid start and then go into degraded mode if a hdd is not present.

modify the file /etc/init.d/mdadm-raid and change the line that looks like
for line in $($MDADM --assemble --scan --auto=yes --symlink=no 2>&1); do
to
for line in $($MDADM --assemble --scan --no-degraded --auto=yes --symlink=no 2>&1); do
This makes the loading system not assemble any raid that is degraded that isnt started via initrd.

You also have to run dpkg-reconfigure mdadm and make sure that its not loading all devices when it starts, otherwise it will start and load your array which will then be bad.

Update:

Some additional things that i forogt to add.
Sometimes if its really fubar, and it doesnt want to bring it up, or if its in a new host and really being special. You have to create the array again. This sounds counter intuative, but mdadm is smart and as long as its in the same order it can figure it out

mdadm --create --verbose /dev/mdX --level=5 --raid-devices=4 /dev/hda /dev/hdb /dev/hdc /dev/hdd

If a drive is missing, you can force it to create it without it, but make sure you put the word missing in place of the dead disk so it knows the physical order of the array to know where it is.

mdadm --create --verbose /dev/mdX --level=5 --raid-devices=4 /dev/hda missing /dev/hdc /dev/hdd

Also you can examine the contents of a disk itself to know what it thinks the raid table should look like (including the order if you dont remember it)

This will show you the array and what order the disks should be in, and some other useful stuff like what that disk’s blocks think the status of the array is. This information is great if you suffer a major failure on potentially two drives. You can use this information to try and force one of the dead drives back into service, once you know the order…
mdadm --examine /dev/sdb1

Also, to just get some primiative information such as the MD number, and the UUID this will help
mdadm --examine --scan /dev/sdb1