"Linux Gazette...making Linux just a little more fun!"


Striping and Mirroring RAID under RedHat 6.0

By


Index:

  1. Resources
  2. Introduction to RAID
  3. Setting up a RAID Strip
  4. Setting up a RAID Mirror
  5. RAID 5 with a spare device
  6. Comments
Future updates for this article will be located at http://www.tcu-inc.com/mark/articles/Raid.html.

Resources

  1. http://ostenfeld.dk/~jakob/Software-RAID.HOWTO/
  2. /usr/doc/raidtools-0.90
These links are hardware specific which go beyond the scope of this article.
  1. Here is a DPT HOWTO, http://www.ram.org/computing/linux/dpt_raid.html

Introduction to RAID

It is assumed that you will read the The Software-RAID HOWTO by [email protected]. Apparently, he comes from Danmark (not Denmark), which is, of course, the best country in the world where a lot of smart people are located. Anyways, he does such a good job at his HOWTO, this article is probably not necessary. I only started this because the documentation used to suck really bad, which doesn't appear to be the case anymore. Also, this setup is specific for RedHat 6.0, but it should work with any distribution. When am I going to switch to Debian for good? Soon I hope.

What is RAID? Well, it basically gives you the power to do some funky stuff with multiple hard drives. It lets you combine hard drives, split data amongst several hard drives, and do other things. It can increase the speed to write and read your data to your hard drives and it can make backup copies of your hard drives so that if one hard drive crashes, you can most likely retrieve all your data. Read more about the RAID Levels from The Software-RAID HOWTO right now to get a better idea about the different types of Software RAID.

Also, you will need to setup several small partitions for this example. I suggest having 1 gig of diskspace free for an extended partition, and then to make 100 meg logical partitions out of the extended partition. Also, PLEASE PLEASE PLEASE only test raiding on a hard drive you don't care about. If you screw it up, it is your fault, even if my documentation is incorrect.


Strip RAID

I am ONLY going to show you how to setup a strip for DATA only. This means, I won't be striping the main operating system. There can be problems trying to strip an entire system, and so, I won't do it here.

There are basically 4 steps to setup a Strip RAID on your Linux system. striping puts data on two or more hard drives (actually partitions) where half the data is on one hard drive and the other half on the other. This increases your speed since you use BOTH the hard drives at the same time to get each half of the data. Again, please read more about this in the HOWTO.

First, we need to configure /dev/md0, then we need to initialize the partitions, and then we need to configure /etc/rc.d/rc.local to activate the raid, and then we need to configure /etc/rc.d/rc.local to mount the stripped device to a directory.

The Steps Well, I am going to do a trick. Instead of actually using two hard drives, I am going to assume that most of the low-end users don't have two hard drives. Hence, I will use two partitions on the same hard drive. Make an extended partition with two logical partitions, /dev/hda5 and /dev/hda6, which should be the same size. striping two partitions on the same hard drive is almost pointless, and even on the same IDE controller it is almost pointless. Still, this is just an EXERCISE.

  1. Configure /etc/raidtab with this text
    raiddev /dev/md0
              raid-level      0
              nr-raid-disks   2
              nr-spare-disks  0
              chunk-size     4
              persistent-superblock 1  
              device          /dev/hda5
              raid-disk       0
              device          /dev/hda6
              raid-disk       1
    
  2. Format the partitions with the command
    mkraid /dev/md0
    
    If you have problems with using the "mkraid" command, it will tell you how to get around any problems. Then issue this command
    mkfs -t ext2 /dev/md0
    
    Also, check out the status of your raid by looking at the "/proc/mdstat" file/.
    cat /proc/mdstat
    
  3. Execute this command which will add a line to /etc/rc.d/rc.local
    echo "raidstart /dev/md0" >> /etc/rc.d/rc.local
    
  4. Execute this command once. It will make you the directory for the RAID device and add a command to /etc/rc.d/rc.local.
    mkdir /RAID
    echo "mount /dev/md0 /RAID" >> /etc/rc.d/rc.local 
    
  5. If you don't want to reboot your computer, and you want to activate the raid now,
    raidstart /dev/md0
    mount /dev/md0 /RAID
    
    Also, check out the status of the mounted directory by issuing the single command
    df
    

Mirror RAID

Like the example for striping, I will use two partitions on the same hard drive and I will only mirror partitions that are used for data.

First, we need to configure /dev/md0, then we need to initialize the partitions, and then we need to configure /etc/rc.d/rc.local to activate the raid, and then we need to configure /etc/rc.d/rc.local to mount the mirrored device to a directory.

  1. Configure /etc/raidtab with this text
    raiddev /dev/md0
              raid-level      1
              nr-raid-disks   2
              nr-spare-disks  0
              chunk-size     4
              persistent-superblock 1
              device          /dev/hda5
              raid-disk       0
              device          /dev/hda6
              raid-disk       1
    
  2. Format the partitions with the command
    mkraid /dev/md0
    
    If you have problems with using the "mkraid" command, it will tell you how to get around any problems. Then issue this command
    mkfs -t ext2 /dev/md0
    
    Also, check out the status of your raid by looking at the "/proc/mdstat" file/.
     
    cat /proc/mdstat
    
  3. Execute this command which will add a line to /etc/rc.d/rc.local
    echo "raidstart /dev/md0" >> /etc/rc.d/rc.local
    
  4. Execute this command once. It will make you the directory for the RAID device and add a command to /etc/rc.d/rc.local.
    mkdir /RAID
    echo "mount /dev/md0 /RAID" >> /etc/rc.d/rc.local
    
  5. If you don't want to reboot your computer, and you want to activate the raid now,
    raidstart /dev/md0
    mount /dev/md0 /RAID
    
    Also, check out the status of the mounted directory by issuing the single command
    df
    

RAID 5 with a spare partition

Okay, RAID 5 with a spare device is a VERY cool thing to do. Again, we will just be using one hard drive. Generally, for experimenting, I would just use 100 meg logical partitions. If you have a 1 gig extended partition, you can have 10 logical partitions for goofing around with.

Use the same steps for the Mirror or Strip, just change the config file to this.

raiddev /dev/md0
        raid-level      5
        nr-raid-disks   7
        nr-spare-disks  1
        persistent-superblock 1
        parity-algorithm        left-symmetric
        chunk-size      32
        device          /dev/hda5
        raid-disk       0
        device          /dev/hda6
        raid-disk       1
        device          /dev/hda7
        raid-disk       2
        device          /dev/hda8
        raid-disk       3
        device          /dev/hda9
        raid-disk       4
        device          /dev/hda10
        raid-disk       5
        device          /dev/hda11
        raid-disk       6
   ### Also, let us have a spare device  
        device         /dev/hda12
        spare-disk     0

Comments

Mount the raid device in /etc/rc.d/rc.local and don't bother putting it into /etc/fstab. If you want to put it into /etc/fstab, go ahead and try. It probably won't work, but sometimes people just like to see it for themselves (like I do). I like the power to shoot myself in the foot. It makes the surgery interesting.

Well, it is pretty freaking cool. The documentation used to really suck rocks, but that howto has been updated, the tools seem easier to use, and with these few examples, and amateur who knows how to use Linux can probably setup a raid device. Hopefully this will reduce the overall cost of RAID servers.

If you really want to do Software raiding correctly, get an U2W SCSI controller, like an Adaptec controller or other good brands, DPT, Mylex, etc. For cheap raids where you are just mirroring and don't care about speed, IDE hard drives are okay. If you want to go one step beyond software raid and to get into hardware raid, then several companies support hardware raid for Linux.


works as a receptionist (shorts and tee-shirt) at The Computer Underground and as a professional (suit and tie) consultant at 800linux.com. In his spare time, he does volunteer stuff, like writing these documents to help stop entities which thrive on the ignorant. I wonder which company is like that? Edited using emacs and ispell.


Copyright © 1999, Mark Nielsen
Published in Issue 45 of Linux Gazette, September 1999


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next