How to create a Raid Device using Madadm
Trang 1How to create a Raid Device using madadm in
linux rhel5 with level 5, 0 and 1
The following article explains what is Raid, what are important levels and how
to install and configure a raid device in a linux system using the software
mdadm This is tested in Redhat rhel5 and also works with other distributions
as fedora, centos etc
What is RAID?
RAID is redundant array of independent or inexpensive disks It is mainly used for data protection It protects our data storage from failures and data loss All storage units now use raid technology
It has following uses
1 Data protection
2 Increasing performance
Types of RAIDs:
There are alot of levels of RAIDs But the main levels are
1 Level 0 or Striping
2 Level 1 or Mirroring
3 Level 5 or Striping + Parity
Level 0:
It is also known as striping You know hard disk is a block device Datas are read and written from/to it by blocks
Suppose we have data block as below
1 0 1 1
Suppose each bit takes one cpu clock cycles for writing into a disk Total, it will take 4 cpu clock cycles
With stripping:
Trang 2In striping we use "N" number of hard disks RAID devides the data block by
"N" and writes each part to each disk in parallel
If we have 4 hard disks, It'll take only one cpu clock cycle if we use Level 0 RAID
Raid 0 is best for where more writing take place than reading But is insecure
as there is no recovery mechanisms
Level 1:
Also known as Mirroring One is the exact replica of other Whatever writing to master disk will be written in to mirror disk also Reading can be performed fro each disk simultaneously, thus increasing the read performance
But can be utilize only 50% of the total size
Level 5:
It is a combination of striping and parity Need at least three hard disks Both parity and data are distributed in all If one hard disk fails, data on that can be regenerated by the data and parity information in the other two hard disks
###RAID###
Raid 5 :need 3 disks
Raid 0 :need 2 disks
Raid 1 :need 2 disks
first partition disks
***RAID 5***
Here we'll show how to create a Level 5 raid device Here we use three
partitions /dev/sda5 /dev/sda6 /dev/sda7 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/sda{5,6,7}
Formatting the raid device
#mke2fs -j /dev/md0
Trang 3Creating mount point
#mkdir /raid5
Mounting the raid device to the created mount point
#mount /dev/md0 /raid5
Making the mount permanent by adding it in fstab
#vi /etc/fstab
/dev/md0 /raid5 ext3 defaults 0 0
:wq
#mount -a
Test read and write permissions And if you want you can check whether the raid is working by failing or deleting any partition it consists of
touch something in /raid5 and delete one of partitions of sda5,sda6,sda7
This is how we can create a Raid device with level 1
***RAID 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
***RAID 0***
#mdadm create /dev/md0 level=0 raid-devices=2 /dev/sda{5,6}
Stopping mdadm
*Unmount the md0 before stopping mdadm
#mdadm stop /dev/md0
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}