mdadm RAID using an existing drive

Friday 12th September 2008 01:48 PM

TAGS: mdadm, raid, linux

Western Digital DriveLast 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

Comments on this article:


#1 Cyborg28 says:

Monday 2nd February 2009 03:33 PM

Hi, great how to guide. Two things, doing the above when starting with an ext3 file system causes mdadm to let you know it has autodetected an ext2fs disk. This does not seem to be a problem. The other thing is that under Ubuntu (in an X term session) the final instruction to create the mdadm config file wont run regardless of whether you point it to /etc/mdadm/mdadm.conf or just /etc/mdadm.conf. Can you help with this? Thanks!

#2 Cyborg28 says:

Friday 10th April 2009 03:52 AM

Hi,

I used your method and it worked great. The only problem is I get an fsck error on bootup. If I bypass the error the raid array works fine. I have posted all the info I have in the link above. If you know anything about this sort of issue could you please give me some pointers?

Thanks,

Cyborg


Add Comment:


Make a Comment

*Nb, all comments are moderated to prevent spam or inappropriate content.








netforge logo
netforge provides high quality and friendly website design services to business. We're Australian based and reliable... (find out more).