Sunday, June 3, 2007

Raid 1 Setup

I've always hated backing up data. YOu make a DVD backup and two days later you have another 2 Gig that you want to backup.. Its impossible to keep upto date with backups if you dont have a sophisticated system.

After my OS course 2 semesters ago I finally decided that RAID could be my solution. Implement RAID 1 which basically mirrors the drives and voilia Backup!

So after my machine died on me I decided to go shopping. Alomg with a snazzy 22" LCD monitor I decided to put in some dollars for 2 320 GB SATA HDDS.

The idea was to keep my old IDE 40GB drive as root (/) and have my /home and other partitions on the SATA RAID drives. This works great coz I hear that setting a RAID drive as the boot drive causes problems with GRUB since it doesnt know how to read RAID since the module isn't loaded at that point.

So heres the map of things:

* hda1 = 40 GB IDE Drive
* sda and sdb = 320 GB (detects 299 GB) SATA Drives

/ - 40GB /dev/hda1
/home - RAID ARRAY 1 [ 60GB /dev/sda1 & 60GB /dev/sdb1 ]
/audio - RAID ARRAY 2 [ 60GB /dev/sda5 & 60GB /dev/sdb5 ]
/neuro - RAID ARRAY 3 [ 60GB /dev/sda6 & 60GB /dev/sdb6 ]
/virtuo - RAID ARRAY 4 [ 60GB /dev/sda7 & 60GB /dev/sdb7 ]
/video - RAID ARRAY 5 [ 59GB /dev/sda8 & 60GB /dev/sdb8 ]


While I went though a slightly messy setup since I didn't really know what I was doing at the time, in retrospect things are a lot clearer now. So here's instruction for setting up RAID POST installation...

IMHO I think a PRE install setup shouldn't be too different. Setup the mdadm arrays and then run the install and ubuntu will detect the partitions or you can modify the fstab to mount the partitions manually. But don't take my word for it, check out the links at the bottom of this post.

---- BOOT FROM LIVE CD ----
We need mdadm to enable RAID. (mdadm -manage MD devices aka Linux Software Raid.) The standard LIVE CD doesnt have mdadm available, so lets install it:

sudo apt-get update
sudo apt-get install mdadm

During the installation I answered:
mdadm md arrays needed for the root filesystem: none
start MD arrays automatically: yes

NOTE: If you are going to boot from a RAID partition your answers will be different.


---- SETUP PARTITIONS ----
Create identical partitions (ext3) on the individual drives. In my scenario I had 5 partitions of ~60GB on each drive. You can use the GParted GUI tool under System > Administration.

Now to make these partitions RAID. Ensure you know the names of each partition, you can check them in GParted.

What happens now is that we create RAID arrays and tell mdadm which partitions are going to be in each array. Since I planned for 5 partitions I have 5 RAID Arrays which all are RAID-1.

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sd[ab]1
sudo mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sd[ab]5
sudo mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sd[ab]6
sudo mdadm --create /dev/md3 --level=1 --raid-devices=2 /dev/sd[ab]7
sudo mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sd[ab]8

A quick explination of the above command: Create /dev/md0 as a RAID1 array consisting of /dev/hda1 and /dev/hdb1.

Now although mdadm will start automatically on boot and detect these arrays we still need to tell fstab to mount these partitions. Since we've booted from a live cd our drives are not mounted.
Mount your / (root) partition with:
sudo mount /dev/hda /somefolderthatexists

Now navigate to and modify your fstab (/somefolderthatexists/etc/fstab) to mount each array. Here's my fstab
# /etc/fstab: static file system information.
proc /proc proc defaults 0 0
# /dev/hda1
UUID=f3bbc342-67c3-43f1-adbf-8051783b5972 none swap sw 0 0
# /dev/hda2
UUID=0f193453-21ce-430a-a31e-774750e9043f / ext3 defaults,errors=remount-ro 0 1
/dev/md0 /home ext3 defaults 0 0
/dev/md1 /audio ext3 defaults 0 0
/dev/md2 /neuro ext3 defaults 0 0
/dev/md3 /video ext3 defaults 0 0
/dev/md3 /virtuo ext3 defaults 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0

And we're done!

You can reboot or mount the drives now with: sudo mount -a which mounts all filesystems listed in /etc/fstab.

Also, mdadm is (re)syncing the partitions in the background. You can check the status/progress with: cat /proc/mdstat

You dont have to wait to use your drives, you can use them immediately and mdadm will sync them in the background..

Hope this helps, if not here's what helped me:
http://man-wiki.net/index.php/8:mdadm
http://ubuntuforums.org/showthread.php?t=408461
http://advosys.ca/viewpoints/2007/04/setting-up-software-raid-in-ubuntu-server/

No comments: