Sunday, January 20, 2008

new 500GB SATA RAID1 mirror

For fault tolerance, I finally got around to upgrading my drives to a RAID1 mirror this weekend. I bought a pair of Seagate ST3500641AS-RK Barracuda from Outpost.com for $99 each. Sale is over now, of course.

Here's what I had to do:
  1. partition the drives using fdisk
  2. create the mirror
  3. wait for the mirror to sync
  4. format the mirror
  5. test a mount
  6. add to /etc/fstab
  7. reboot to make sure everything comes up

Partition the drives with good ol' fdisk
I had to partition each drive and give each drive a partition type of "Linux raid autodetect". This is type "fd". Here is a snip of my fdisk session for one of the drives:

[mule@ogre ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdf: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-60801, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801):
Using default value 60801

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd

Command (m for help): p

Disk /dev/sdf: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdf1 1 60801 488384001 fd Linux raid autodetect

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create the mirror
I created the mirror using mdadm. Note the "--level=1" for the RAID1 mirror:
[mule@ogre ~]# mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sde1 /dev/sdf1

Let's check out the details:
[mule@ogre ~]# mdadm --detail /dev/md2
/dev/md2:
Version : 00.90.03
Creation Time : Thu Jan 17 19:58:30 2008
Raid Level : raid1
Array Size : 488383936 (465.76 GiB 500.11 GB)
Used Dev Size : 488383936 (465.76 GiB 500.11 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Sun Jan 20 16:19:10 2008
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 1705b387:1c71d83e:364b60b4:fb0cce92
Events : 0.6

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sde1
1 8 49 1 active sync /dev/sdf1


Wait for the mirror to build
You can also look in /proc/mdstat for status information:
[mule@ogre ~]# cat /proc/mdstat
Personalities : [raid0] [raid6] [raid5] [raid4] [raid1]
md2 : active raid1 sdb1[0] sdd1[1]
488383936 blocks [2/2] [UU]

md0 : active raid0 sda3[0] sdc2[1]
483411456 blocks 256k chunks


unused devices:


Format the partition
The -j parameter to mke2fs creates the filesystem with an ext3 journal, for another level of safety. File access on an ext3 filesystem is a bit slower than on an ext2 filesystem. However, the benefit is that you have a journaling filesystem that recovers from errors quickly and safely. Here's some documentation on the ext3 filesystem:
http://www.ibm.com/developerworks/linux/library/l-fs7.html

Here is the command I ran to create the ext3 filesystem:
[mule@ogre ~]# mke2fs -j /dev/md2

Test the mount
You should always test mounting the new filesystem. Since this filesystem is going to store all my videos, I am going to create my mount point and mount the new RAID mirror to /mnt/videos:
[mule@ogre ~]# mkdir /mnt/videos
[mule@ogre ~]# mount -t ext3 /dev/md2 /mnt/videos
[mule@ogre ~]#

You see no errors after the mount command. This means that the mount was successful. Yes!

Add to /etc/fstab
Of course, we want the new filesystem to be mounted when we reboot, so I add the following line to my /etc/fstab:
/dev/md2 /mnt/videos ext3 defaults 1 1

Reboot!
The final test is to reboot. The following lines in dmesg output make me happy:
md: md2 stopped.
md: bind
md: bind
md: raid1 personality registered for level 1
raid1: raid set md2 active with 2 out of 2 mirrors


Rock and roll! We're good with the new RAID mirror and safe from drive failures!
The Mule

No comments:

Post a Comment