Last week, I decided it was time to put in place a basic mirrored RAID setup on my linux server, as it has quite a few irreplaceable files and documents on it, not to mention client info that needs to be kept safe.
RAID 1 is a mirrored drive setup, I have 2x 1tb drives in my server, which both contain the exact same data, and act as a single 1tb drive. In the event of one drive failing, I can simply put a new one in, let the background process rebuild the new drive, and there should be zero downtime.
There are several methods to go down to get your RAID setup. The first is by using on-board RAID found on many motherboards, however this relies on a driver to get things up and running, and if your motherboard was to be replaced or break, you would have to find another with the same chipset to get things running again, I didn't like this idea.
A dedicated RAID card is the other option, although you have to be very careful, as many of these cards simply are a virtual interface for a drive built into your operating system, that covers any card you see advertised for $80-$200.
The full hardware solution cards are the best of the best, but they do come at a price, $400-$500+. Simply put, the full hardware cards have a dedicated processor on-board which manages everything, all the operating system sees is a regular drive. The benefit of this is that you get the fastest speed possible, and more advanced setups like RAID 5 work far better.
To throw a spanner in the works however, linux has an inbuilt software RAID which works on pretty much any *nix distro. It's called mdadm, and has the advantage of being able to manage a RAID setup without having to use BIOS drivers or proprietary bits sitting in between.
Because i was after data reliability over speed, I chose to use this method, as it is quite portable between systems, doesn't require custom formats and is so, so easy to setup.
Make sure you have all of your data backed up before attempting this, it worked fine for me, but it's always better to be safe. I'll make the point at this stage, RAID is not a replacement for good backups, so don't get lazy. ;)
From Sébastien Wains, the easiest way to setup a system is to use the "missing" method. I was dealing with a SATA drive that already had data on it (/dev/sda1), and my new, blank drive (/dev/sda2). Use fdisk -l to list all of the drives in your system if you're not sure.
First step, is to set both drive types to "fd" using fdisk:
fdisk /dev/sda1
Command (m for help): t
Partition number (1-5): 1
Hex code (type L to list codes): fd
Once this is complete, we can get straight into setting things up! Make sure all your target drives are unmounted, and run the following command on the drive that has data already on it.
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 missing
That's it, mdadm has now created a new RAID array for you which is accessible via /dev/md0 if you are wanting to mount it straight away. We just have to add the other drive now, and let them sync up.
mdadm --add /dev/md0 /dev/sda2
To see the status of your RAID array at anytime, simply use:
cat /proc/mdstat
Last step is to create the mdadm configuration file (automatically), run this command, and we're all set, and you can use /dev/md0 just the same as you would a regular drive in your system!
mdadm --detail --scan --verbose > /etc/mdadm.conf




