Saturday, November 25, 2006

Software RAID

The primary purpose of my server is a file server. While it has other purposes, that is what it was originally built for. Earlier this year we bought a 250 GB HD from Woot. After filling it more than half way, I got to thinking about backups. With Black Friday just passing, the wife took a trip to Best Buy, where there was a 250 GB HD for $60. A good deal. And at first I was going to to just use rsync to keep the files mirrored, I looked into RAID 1, which accomplishes the same task, but in real time.
Here is my setup:

  • 30GB HD with OS installed on IDE 0, set as Master. (/dev/hda)
  • (2) 250GB HD for file storage, one on IDE 0 as slave, the other on IDE 1 as Master (dev/hdb & c)
  • CD-ROM on IDE 1 as slave. (/dev/hdd)
Here is how I set it up:
  1. Install raidtools:
    1. urpmi raidtools
  2. Backup drive data. I was lucky and my wife had just enough space on her HD to be a temporary storage. It took close to 4 hours to transfer the data over a samba connection on a 100MB connection. Backing up the data is a MUST since you will be changing partition tables and re-formating the drives.
  3. Install second hard drive, and make sure BIOS recognizes it. I made sure the two 250 GB drives were on separate IDE channels.
  4. After the backup was verified, I changed the file system type on both drives. Type these commands:
    1. fdisk /dev/hdb
    2. t (to change file system type)
    3. fd (which is Linux Raid Auto)
    4. w (to write the new partition table)
  5. Repeat the same for /dev/hdc
  6. Copy the template raid config files:
    1. cp /usr/share/doc/raidtools/raid1.conf.sample /etc/raidtab
  7. Edit the new raidtab with vi. Make it look like this:
    # My raid-1 configuration
    raiddev /dev/md0
    raid-level 1
    nr-raid-disks 2
    nr-spare-disks 0
    chunk-size 32

    device /dev/hdb1
    raid-disk 0

    device /dev/hdc1
    raid-disk 1
  8. Initialize the RAID:
    1. mkraid /dev/md0
  9. Check to make sure it's working:
    1. cat /proc/mdstat
    2. Should see no error messages
  10. Format new RAID partition
    1. mkfs -t ext3 -b 4096 /dev/md0
  11. Now everything should be set, last step is change fstab to mount the new RAID array:
    1. /dev/md0 /server ext3 defaults 1 2
  12. Type mount -a and you now have access to the RAID array.
Note: /proc/mdstat is your key to the status of your RAID array. Check it if you suspect any problems later on.

No comments: