Setting up Linux RAID 1
Configuring LINUX RAID 1 is very essential as its provides redundancy.
RAID partitions allows advanced features such as redundancy and better performance. So lets describe how to implement RAID, let’s look at the different types of RAID:
■ RAID 0 (Striping) disks are grouped together to form one large drive. This offers better performance at the cost of availability. Should any single disk in the RAID fail, the entire set of disks becomes unusable. Two disk minimum.
■ RAID 1 (Mirroring) disks are copied from one to another, allowing for redundancy. Should one disk fail, the other disk takes over, having an exact copy of data from the original disk. The downside here is slow write times. Two disk minimum.
■ RAID 5 (Striping with parity) disks are similar to RAID 0 and are join together to form one large drive. The difference here is that 25% of the disk is used for a parity bit, which allows the disks to be recovered should a single disk fail. Three disk minimum.
Let’s move on to hands on for Linux RAID 1 configuration.
Prerequisites for Linux RAID 1:
- mdam should be installed on system, Please confirm using below command.
[root@rhel1 ~]# rpm -qa|grep -i mdadm mdadm-3.2.2-9.el6.x86_64 [root@rhel1 ~]#
2. System should have 2 HDD attached with the system.
For This Create two partitions, one on each disk (sdc, sdd), allowing each partition to consume the whole disk
Disk /dev/sdc: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x67cc8cfb Device Boot Start End Blocks Id System /dev/sdc1 1 130 1044193+ 83 Linux Disk /dev/sdd: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0294382b Device Boot Start End Blocks Id System /dev/sdd1 1 130 1044193+ 83 Linux
Now you can begin to set up the RAID 1 array with the two partitions in hand. You can use the mdadm command to create any RAID array.
Syntax: mdadm [options] Options: -a, xx Adds a disk into a current array -C, —create Creates a new RAID array -D, —detail Prints the details of an array -G, —grow Changes the size or shape of an active array -f, xx Fails a disk in the array -l, —level Specifies level (type) of RAID array to create -n, —raid-devices Specifies the devices in the RAID array -q, —quiet Species not to show output -S, —stop Stops an array -v, —verbose Provides verbose output
Now Let’s create Linux RAID 1 device.
[root@rhel1 ~]# mdadm -Cv /dev/md0 --level=1 -n2 /dev/sdc1 /dev/sdd1 mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 mdadm: size set to 1044181K Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@rhel1 ~]#
View the status of newly created Linux RAID 1 using below command.
[root@rhel1 ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdd1[1] sdc1[0] 1044181 blocks super 1.2 [2/2] [UU] unused devices: <none> [root@rhel1 ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdd1[1] sdc1[0] 1044181 blocks super 1.2 [2/2] [UU] unused devices: <none>
Use the mdadm command again to verify that ,LINUX RAID 1 array has been created successfully:
[root@rhel1 ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Wed Dec 7 15:50:06 2016 Raid Level : raid1 Array Size : 1044181 (1019.88 MiB 1069.24 MB) Used Dev Size : 1044181 (1019.88 MiB 1069.24 MB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Wed Dec 7 15:50:12 2016 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Name : rhel1.lab.com:0 (local to host rhel1.lab.com) UUID : d5c0f82e:4e0753e6:0b28c178:e6f75af4 Events : 17 Number Major Minor RaidDevice State 0 8 33 0 active sync /dev/sdc1 1 8 49 1 active sync /dev/sdd1 [root@rhel1 ~]#
Now Format the Newly created LINUX RAID 1 device using below command:
[root@rhel1 ~]# mkfs.ext4 /dev/md0 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65280 inodes, 261045 blocks 13052 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Mount Linux RAID 1 device;
[root@rhel1 ~]# mkdir /RAID1 [root@rhel1 ~]# mount /dev/md0 /RAID1 [root@rhel1 ~]# df -h /RAID1 Filesystem Size Used Avail Use% Mounted on /dev/md0 1004M 18M 936M 2% /RAID1 [root@rhel1 ~]#