Monday, 11 May 2015

RAID with LVM Configuration in RHEL7


In this tutorial, we will create RAID Level 5 device using 3 disks. On top of this RAID array, we will create a LVM partition. RAID with LVM configuration gives us several advantages over a traditional system:

1) RAID 5 gives fault tolerance. If one of our disks fails, our data remains intact.  
2) LVM gives us resizable volumes (partitions).
3) More disk space can be easily be added without the need to recreate any partition. Disks can be added to the RAID array and the LVM volume group can be extended. 

For basic RAID configuration, refer to this post . And for basic LVM configuration, refer to this post

Consider 3 disks,  /dev/sda, /dev/sdb, /dev/sdc each of size 1Gb. We will assemble these 3 disks into 1 logical RAID 5 device. We will add this RAID 5 device to a Volume Group. From the volume group, we will create a logical volume.

1) Create partitions /dev/sda1, /dev/sdb1, /dev/sdc1 on the devices  /dev/sda, /dev/sdb, /dev/sdc respectively.

2) Build a RAID 5 array '/dev/md0' with the above 3 partitions.
[root@server3 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.


View Status
[root@server3 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdc1[3] sdb1[1] sda1[0]
      2093056 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>

2) Initialize the RAID device as physical volume.
[root@server3 ~]# pvcreate /dev/md0
  Physical volume "/dev/md0" successfully created

3) Create a volume group consisting of the  physical volume initialized above.
[root@server3 ~]# vgcreate vg_linux /dev/md0
  Volume group "vg_linux" successfully created

The name of the volume group is 'vg_linux' and size is 2Gb as shown below.
[root@server3 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_linux
  Format                lvm2
  VG Access             read/write
  VG Status             resizable
  VG Size               1.99 GiB
  PE Size               4.00 MiB
  Total PE              510
  Alloc PE / Size       0 / 0  
  Free  PE / Size       510 / 1.99 GiB
  VG UUID               6tQeK2-NRmX-gaUb-jcfi-hlvR-2g6r-VxHk4P

4) Create a logical volume of size 1Gb, which you can mount and actually use.
[root@server3 ~]# lvcreate -L 1G -n lv_data vg_linux
  Logical volume "lv_data" created
 
The logical volume can now be accessed as '/dev/vg_linux/lv_data'.

5) Create filesystem on the logical volume 'lv_data'.
[root@server3 ~]# mkfs -t xfs /dev/vg_linux/lv_data

6) Create mount point
[root@server3 ~]# mkdir /var/data

7) Mount the logical volume 'lv_data' and create files in it.
[root@server3 ~]# mount -t xfs /dev/vg_linux/lv_data  /var/data
[root@server3 ~]# touch /var/data/foo{1,2,3}
[root@server3 ~]# ls /var/data/
foo1  foo2  foo3

8) Add the following entry in '/etc/fstab' (to automatically mount the logical volume at boot time).
          /dev/vg_linux/lv_data            /var/data         xfs           defaults        1  2

No comments:

Post a Comment