HOWTO: Setup and Configure Linux Software RAID (CentOS/Fedora/RedHat)

| 1 TrackBack
You may have just purchased a new "RAID" card and found out it's not what you were expectingOr, you don't have a RAID card (just a plain storage controller) but want to take advantage of RAID anyways.  You have two options for setting up a RAID volume in Linux using a "fakeraid" card, or a regular storage controller:

  1. Assuming you have a fakeraid card, you could install some proprietary Linux RAID driver from the controller vendor.  This is not always possible given that most vendors only provide software RAID drivers for Windows.  My controller, a SATA 4-Channel RAID card (SC-SA4R12-S2) by SIIG does not have any Linux drivers, so this option isn't even possible.  Even if your vendor did provide the Linux drivers for your controller, I would suggest you ignore them and consider Option #2.  Fake RAID cards traditionally "emulate the missing hardware RAID functionality inside idiosyncratic, undocumented, and proprietary software drivers, to hit low price points."  Using a fakeraid driver from a specific vendor usually backs you, and your data, into a corner.

  2. The second option is to setup and use Linux Software RAID.  I know, it's not hardware RAID like you probably wanted, but unless you're willing to go out and spend some serious cash on a really good hardware RAID controller, this is your only option so suck it up.  For what it's worth, the Linux Software RAID solution is actually quite good, assuming you don't have any strict fault tolerance requirements like data caching, etc.  You can also use any combination of disks across any type of storage controller to create a software RAID volume.
Continue reading to find out how to setup a Linux software RAID volume.
This is a quick-and-dirty HOWTO for setting up and configuring a Linux Software RAID volume on CentOS, which should also work on Fedora, Red Hat Linux, and other distros.  If you want a more detailed HOWTO, then see http://tldp.org/HOWTO/Software-RAID-HOWTO.html.

I have an HP xw8200 Workstation running x86_64 CentOS 5.2 Final (current kernel is 2.6.18-92.1.18.el5).  The HP xw8200 Workstation has an onboard Intel fakeraid controller that I've disabled.  If you're not familiar with CentOS 5.2, it's the free version of Red Hat Enterprise Linux 5.  I've added my SATA 4-Channel RAID card (SC-SA4R12-S2) by SIIG to one of the open PCI slots.  The card is visible using the lspci command:

(root@bermuda)~> /sbin/lspci -v | grep -i sata
03:02.0 RAID bus controller: Silicon Image, Inc. SiI 3114 [SATALink/SATARaid] Serial ATA Controller (rev 02)
        Subsystem: Silicon Image, Inc. SiI 3114 SATARaid Controller


If you have an SIIG SC-SA4R12-S2 SATA "RAID" card, you should know it's not a real hardware RAID card; this controller relies on the OS driver to do the real RAID work.  Given that there are no Linux drivers for the SIIG SC-SA4R12-S2, your only option (on Linux) is to use Linux software RAID.

Connected to my SIIG SC-SA4R12-S2, I have two 250.0 GB Seagate SATA disks.  Both are visible under /dev:

(root@bermuda)~> ll /dev/sd*
brw-r----- 1 root disk 8,  0 Nov 14 22:37 /dev/sda
   <<-- my root disk, SCSI
brw-r----- 1 root disk 8,  1 Nov 14 22:37 /dev/sda1
brw-r----- 1 root disk 8,  2 Nov 14 22:37 /dev/sda2
brw-r----- 1 root disk 8,  3 Nov 14 22:37 /dev/sda3
brw-r----- 1 root disk 8, 16 Nov 14 22:37 /dev/sdb
  <<-- an extra 146 GB SCSI disk
brw-r----- 1 root disk 8, 32 Nov 14 22:37 /dev/sdc
  <<-- SATA disk #1
brw-r----- 1 root disk 8, 48 Nov 14 22:37 /dev/sdd
  <<-- SATA disk #2
brw-r----- 1 root disk 8, 64 Nov 14 22:37 /dev/sde   <<-- USB flash key

My SATA disks are /dev/sdc and /dev/sdd.  Note the "8" in the output above, followed by another number.  The "8" is the device major number, which indicates which driver owns the disk.  The following number is a minor number, which is unique and specific to the device driver.  To find which driver owns the disk device, you should look at the output of /proc/devices:

(root@bermuda)~> cat /proc/devices | grep 8
128 ptm
180 usb
189 usb_device
  8 sd
 68 sd
128 sd


The driver we care about has a major number of 8.  No surprise, it's the "sd" driver (the Linux disk driver).  Now we're going to use the Linux md Driver to setup a software RAID volume.  You'll need the mdadm.x86_64 or the mdadm.i386 package installed, depending on your architecture.  Use "rpm -qa" to check the installed packages on your system:

(root@bermuda)~> rpm -qa | grep -i mdadm
mdadm-2.6.4-1.el5


If this is not installed, you can run "yum install mdadm".  If you want to read more on "md - Multiple Device driver aka Linux Software RAID", check the "man 4 md" man-page.  I'm now going to use the mdadm command to create a RAID-1 volume (mirror) using the two SATA disks /dev/sd[c,d]:

(root@bermuda)~> mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sd[c,d]
...


This may take a while, so be patient.  Setting up a mirror of two 250.0 GB SATA disks took just over an hour.  You can run dmesg to check the output of the system log to monitor the progress of your array creation.  Now that we've created the array, we're going to assemble the disks together:

(root@bermuda)~> /sbin/mdadm --assemble /dev/md0 /dev/sd[c,d]
mdadm: /dev/md0 has been started with 2 drives.


Once the assembly is complete, you now have a valid /dev/md0 device file which can be mounted just like any other disk.  I'm going to mount /dev/md0 on /core:

(root@bermuda)~> mount /dev/md0 /core

I'm going to copy some sample data to /core and then run "df -h" to see how much disk space is left on my RAID volume:

(root@bermuda)~> cp -r ~/data /core

(root@bermuda)~> df -h /dev/md0
Filesystem            Size  Used Avail Use% Mounted on
/dev/md0              230G  103G  115G  48% /core


You can also use the mdadm command to view additional state details about your RAID volume:

(root@bermuda)~> mdadm -D /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Thu Nov 13 22:49:51 2008
     Raid Level : raid1
     Array Size : 244198464 (232.89 GiB 250.06 GB)
  Used Dev Size : 244198464 (232.89 GiB 250.06 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sat Nov 15 10:57:16 2008
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : f6b21240:5386aa5d:582df766:e7d842d7
         Events : 0.2

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd


If you want this volume to be mounted automatically at boot time, add an entry in /etc/fstab and add /etc/mdadm.conf to define the prebuilt array:

(root@bermuda)~> cat /etc/fstab | grep -i md0
/dev/md0                /core                   ext3    defaults        0 0


(root@bermuda)~> cat /etc/mdadm.conf
ARRAY /dev/md0 devices=/dev/sdc,/dev/sdd


Now, if you're like me, you'll want to prove to yourself that your data is actually mirrored on both disks /dev/sd[c,d].  So, let's stop the RAID volume, umount it, and then mount each disk separately to verify:

(root@bermuda)~> umount /core

Stop the RAID volume:

(root@bermuda)~> mdadm -S /dev/md0
mdadm: stopped /dev/md0


Mount /dev/sdc to /core:

(root@bermuda)~> mount /dev/sdc /core

(root@bermuda)~> df -h /dev/sdc
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdc              230G  103G  115G  48% /core


Well, what do you know!  103 GB used on this single disk, same as my mirrored RAID volume on /dev/md0 above!  So, I guess the mirror really is working like I thought it was.  Now, let's reassemble the volume:

(root@bermuda)~> umount /core

(root@bermuda)~> mdadm -A /dev/md0 /dev/sdc /dev/sdd
mdadm: /dev/md0 has been started with 2 drives.

(root@bermuda)~> mount /dev/md0 /core


That's it!  Hopefully this gave you a quick-and-dirty start to using Linux Software RAID.  For a more official Linux Software RAID HOWTO, see http://tldp.org/HOWTO/Software-RAID-HOWTO.html.

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

1 TrackBack

About This Site from Mark S. Kolich on March 18, 2010 11:57 PM

I'm Mark Kolich, and this is my personal weblog.  I usually write about my technical interests, which mostly relate to client and server-side web technologies on various platforms and in numerous programming languages.  I enjoy solving tough ... Read More

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on November 15, 2008 11:03 AM.

SATA RAID Cards (Linux/Windows), What you Should Know About Fake RAID Cards was the previous entry in this blog.

HOWTO: Check if Your System Will Support a 64-bit OS (x86_64 Linux) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.