Friday, July 10, 2009

Creating a RAID 5 Array in software on CentOS 5.3

In order to create a RAID 5 array entirely in software on Linux you need to do a few things.

First I used three Identical drives, same speed, size, make, and model. This may not be a requirement, but
it will defiantly help the process. For RAID 5 you will need at least three partitions of the same size.

I picked up a four disk internal hot-swap enclosure from Addonics (http://www.addonics.com/products/raid_system/ae4rcs35nsa.asp) and
a hot-swap capable raid card. Once I got everything physically installed in the server case I booted into CentOS 5.3
and got on the command line. The first thing you need to do is create partitions on the blank drives and set them to be
Linux raid autodetect (Hex value of fd). To do this run fdisk /dev/sdX where X is the drive(s) that you want to partition for the RAID array.
For me this was SDC, SDD, SDE but you results will vary.

fdisk /dev/sdc
n [ENTER]
e [ENTER]
4 [ENTER]
[ENTER]
[ENTER]
n [ENTER]
l [ENTER]
t [ENTER]
5 [ENTER]
fd [ENTER]
w [ENTER]

You will want to create an Extended partition so choose n for New partition. If you get stuck you can hit m to get the help menu.
After you hit n type e for Extended. Then you will have to enter a partition number, I choose 4 for all of my drives.
After that you n again and then choose l for logical partition type. Again it will ask for a partition number 1-4 are for primary and thus not an option,
so I choose 5 for all of my drives.

Once the logical partitions are created hit t to change the partition type. If you are unsure what to use hit l, but in this case we already know that we want to
use type fd for the Linux RAID auto.

Once the type has been changed you can type w to write this info to the drive and start on the next one.
fdisk /dev/sdd
n [ENTER]
e [ENTER]
4 [ENTER]
[ENTER]
[ENTER]
n [ENTER]
l [ENTER]
t [ENTER]
5 [ENTER]
fd [ENTER]
w [ENTER]
fdisk /dev/sde
n [ENTER]
e [ENTER]
4 [ENTER]
[ENTER]
[ENTER]
n [ENTER]
l [ENTER]
t [ENTER]
5 [ENTER]
fd [ENTER]
w [ENTER]

Now that we have three (the minimum) partitions for our RAID device we have to create it in CentOS. Here we will use a tool called mdadm to create the
actual RAID device in Linux.
/sbin/mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdc5 /dev/sdd5 /dev/sde5 [ENTER]
Once this returns back, and it should be pretty quick, you will have a RAID 5 device. To check the status of it run:
/sbin/mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Wed Jul 8 09:14:19 2009
Raid Level : raid5
Array Size : 2930271744 (2794.52 GiB 3000.60 GB)
Used Dev Size : 1465135872 (1397.26 GiB 1500.30 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Fri Jul 10 11:20:02 2009
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 64K

UUID : 53f6f95a:9e33f5ba:7ac8ef3e:0a40921a
Events : 0.2

Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdc5
1 8 37 1 active sync /dev/sdd5
2 8 53 2 active sync /dev/sde5
Now for me after I first created the RAID device the state was listed as clean, degraded, rebuilding. There was a place for the percentage rebuilt and
/dev/sde5 was listed as spare. It took the better part of a day for the rebuild to finish, given that it was a three terabyte device I am not surprised by that.

Once the rebuild was done I had to create a Physical volume for LVM to be able to manage the RAID device.
pvcreate /dev/md0

After that I was able to use system-config-lvm to create the storage volume and format the drive.

No comments: