Saturday, December 3, 2011

Different RAID levels for Linux / UNIX / Configure RAID Level 5

Redundant Array of Independent Drives (or Disks), also known as Redundant Array of Inexpensive Drives (or Disks) (RAID) is an term for data storage schemes that divide and/or replicate data among multiple hard drives. RAID can be designed to provide increased data reliability or increased I/O performance, though one goal may compromise the other.
There are total 10 types of RAID levels:
  • RAID level 0
  • RAID level RAID level 1
  • RAID level 2
  • RAID level 3
  • RAID level 4
  • RAID level 5
  • RAID level 6
  • RAID level 10
  • RAID level 50
  • RAID level 0+1
Following are commonly used RAID levels :

RAID levelMinimum hard disksSuggested applicationNotes
RAID 0 - Striped Set without parity2 Hard disks1. Video Production and Editing
2. Image Editing
3. Any application requiring high bandwidth
Provides improved performance and additional storage but no fault tolerance from disk errors or disk failure. Any disk failure destroys the array, which becomes more likely with more disks in the array.
RAID 1 - Mirrored Set (2 disks minimum) without parity.2 Hard disks1. Office application
2. Financial application
3. Payroll application etc
Provides fault tolerance from disk errors and single disk failure. Increased read performance occurs when using a multi-threaded operating system that supports split seeks, very small performance reduction when writing. Array continues to operate so long as at least one drive is functioning
RAID 5 Distributed Parity3 Hard disks1. File and Application servers
2. Internet Web, E-mail servers
3. Intranet servers
Highest Read data transaction rate, Medium Write data transaction rate, Overall good (aggregate) transfer rate. drive failure requires replacement, but the array is not destroyed by a single drive failure. Upon drive failure, any subsequent reads can be calculated from the distributed parity such that the drive failure is masked from the end user. The array will have data loss in the event of a second drive failure and is vulnerable until the data that was on the failed drive is rebuilt onto a replacement drive
RAID 10 (nested RAID 1+0)4 Hard disks1. Database server (such as Oracle / MySQL / MS-SQL) which requiring high performance and fault toleranceProvides fault tolerance and improved performance but increases complexity.


In all the diagrams mentioned below:
  • A, B, C, D, E and F – represents blocks
  • p1, p2, and p3 – represents parity

RAID LEVEL 0


Following are the key points to remember for RAID level 0.
  • Minimum 2 disks.
  • Excellent performance ( as blocks are striped ).
  • No redundancy ( no mirror, no parity ).
  • Don’t use this for any critical system.

RAID LEVEL 1


Following are the key points to remember for RAID level 1.
  • Minimum 2 disks.
  • Good performance ( no striping. no parity ).
  • Excellent redundancy ( as blocks are mirrored ).

RAID LEVEL 5


Following are the key points to remember for RAID level 5.
  • Minimum 3 disks.
  • Good performance ( as blocks are striped ).
  • Good redundancy ( distributed parity ).
  • Best cost effective option providing both performance and redundancy. Use this for DB that is heavily read oriented. Write operations will be slow.

RAID LEVEL 10



Following are the key points to remember for RAID level 10.
  • Minimum 4 disks.
  • This is also called as “stripe of mirrors”
  • Excellent redundancy ( as blocks are mirrored )
  • Excellent performance ( as blocks are striped )
  • If you can afford , this is the BEST option for any mission critical applications (especially databases).
Configure RAID Level 5

Here we'll show how to create a Level 5 raid device. Here we use three partitions /dev/sdb /dev/sdc /dev/sdd. Keep in mind that, in real industry it'll be three different hard disks.

This following command will create a raid device /dev/md0 with level 5
#mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd{b,c,d}
mdadm: array /dev/md0 started.


If we run the command "watch cat /proc/mdstat" while executing the above command, we can see the status of the process of creating md raid device. Output will be as given below

tanishka-Studio-1558 tanishka # watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat Sat Mar 3 19:21:31 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[3] sdc[1] sdb[0]
10485632 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
[======>..............] recovery = 33.5% (1759128/5242816) finish=1.4min speed=39024K/sec
unused devices: <none>


Status when finished.
tanishka-Studio-1558 tanishka # watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat Sat Mar 3 19:23:27 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[2] sdc[1] sdb[0]
10485632 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>


To see the details of the created raid device.
tanishka-Studio-1558 tanishka # mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar 3 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar 3 19:23:18 2012
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.2
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd

 
You have to create one configuration file for the raid device created by mdadm. Else it wont be able to survive a reboot.
tanishka-Studio-1558 tanishka # mdadm --detail --verbose --scan >> /etc/mdadm.conf
tanishka-Studio-1558 tanishka # cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=4e4f2828:3bbe8227:61435180:8ac962cf
devices=/dev/sdb,/dev/sdc,/dev/sdd

 
Formatting the raid device
tanishka-Studio-1558 tanishka # mkfs.ext3 /dev/md0

Creating mount point
#mkdir /data

Mounting the raid device to the created mount point
#mount /dev/md0 /data

Making the mount permanent by adding it in fstab
#vi /etc/fstab
/dev/md0 /data ext3 defaults 0 0
:wq
#mount -a


Now we will create a file of size 100mb in /data
tanishka-Studio-1558 tanishka # dd if=/dev/zero of=bf bs=1024 count=100000
100000+0 records in
100000+0 records out
102400000 bytes (102 MB) copied, 1.85005 seconds, 55.3 MB/s

 
Now we will check the raid by failing one partition/disk.
tanishka-Studio-1558 tanishka # mdadm /dev/md0 --fail /dev/sdc
mdadm: set /dev/sdc faulty in /dev/md0
tanishka-Studio-1558 tanishka #


Now the status is
tanishka-Studio-1558 tanishka # mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar 3 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar 3 19:56:08 2012
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.6
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 0 0 1 removed
2 8 48 2 active sync /dev/sdd
3 8 32 - faulty spare /dev/sdc
tanishka-Studio-1558 tanishka #

Now we can remove the faulty one by
tanishka-Studio-1558 tanishka # mdadm /dev/md0 --remove /dev/sdc
mdadm: hot removed /dev/sdc
tanishka-Studio-1558 tanishka #

Now the status is
tanishka-Studio-1558 tanishka # mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
 Creation Time : Sun May 20 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar 3 20:04:16 2012
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.8
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 0 0 1 removed
2 8 48 2 active sync /dev/sdd
tanishka-Studio-1558 tanishka #
Now we add a new disk replacement for the one we removed.

tanishka-Studio-1558 tanishka # mdadm /dev/md0 --add /dev/sde
mdadm: added /dev/sde

tanishka-Studio-1558 tanishka #

See the data is rebuilding using the data and parity information from the other two disk.
tanishka-Studio-1558 tanishka # watch cat /proc/mdstat
 Every 2.0s: cat /proc/mdstat Sun May 20 20:08:19 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde[3] sdd[2] sdb[0]
10485632 blocks level 5, 64k chunk, algorithm 2 [3/2] [U_U]
[===>.................] recovery = 18.9% (994220/5242816) finish=1.8min speed=38239K/sec
unused devices: <none>


Also check
tanishka-Studio-1558 tanishka # mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
 Creation Time : Sun May 2019:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
 Update Time : Sun May 20 20:04:16 2012
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 77% complete
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.8
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
3 8 64 1 spare rebuilding /dev/sde
2 8 48 2 active sync /dev/sdd

tanishka-Studio-1558 tanishka #
This is how we can create a Raid device with level 1
#mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda{5,6}

This is how we can create a Raid device with level 0
#mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda{5,6}

Stopping mdadm
*Unmount the md0 before stopping mdadm
tanishka-Studio-1558 tanishka # umount /data/
tanishka-Studio-1558 tanishka # mdadm --stop /dev/md0
mdadm: stopped /dev/md0
tanishka-Studio-1558 tanishka #
If you want to create additional devices[ie there exists a /dev/md0] you may need to add an "-a yes" option to the mdadm command.

For example,
#mdadm --create /dev/md1 -a yes --level=0 --raid-devices=2 /dev/sda{5,6}
Adding Spare disk
We can also specify the spare device at the time of creating the raid array.

tanishka-Studio-1558 tanishka # mdadm --create /dev/md0 --level=1 --raid-devices=2 --spare-devices=1 /dev/sd{b,c,d}

See
tanishka-Studio-1558 tanishka # mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
 Creation Time : Sun May 20 20:36:58 2012
Raid Level : raid1
Array Size : 5242816 (5.00 GiB 5.37 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar 3 20:37:25 2012
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
UUID : 17b820a4:61fc941e:267bf6c8:8adff61a
Events : 0.2
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 - spare /dev/sdd
tanishka-Studio-1558 tanishka #



Note that this document comes without warranty of any kind. But every effort has been made to provide the information as accurate as possible. I welcome emails from any readers with comments, suggestions, and corrections at webmaster_at admin@linuxhowto.in

Copyright © 2012 LINUXHOWTO.IN

1 comment: