HOW TO CREATE RAID OVER LVM IN LINUX

In this post we will learn how to configure raid over lvm ( logical volume management ) in linux .

raid over lvm in linux

  • Create three partitions .
[root@3usageeks ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 68514.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-68514, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-68514, default 68514): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-68514, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-68514, default 68514): +800M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57589-68514, default 57589):
Using default value 57589
Last cylinder or +size or +sizeM or +sizeK (57589-68514, default 68514): +1300M

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Mandatory – run patprobe command to save all changes made .

[root@3usageeks ~]# partprobe /dev/sda
  • Convert these partitions into physical volumes .
[root@3usageeks ~]# pvcreate /dev/sda5 /dev/sda6 /dev/sda7
  Wiping software RAID md superblock on /dev/sda5
  Physical volume "/dev/sda5" successfully created
  Physical volume "/dev/sda6" successfully created
  Physical volume "/dev/sda7" successfully created
  • Create vg ( volume group ) over physical volume .
[root@3usageeks ~]# vgcreate vg22 /dev/sda5 /dev/sda6 /dev/sda7
  Volume group "vg22" successfully created
  • Now create lvm ( logical volume management )   . Make sure both are of equal size .
[root@3usageeks ~]# lvcreate -L +500M -n lv1 vg22
  Logical volume "lv1" created
[root@3usageeks ~]# lvcreate -L +500M -n lv2 vg22
  Logical volume "lv2" created
  • Then we will create raid 0 over these two lvm .
  • As you know raid 0 requires minimum two harddisks .
  • –level will be 0  ( raid 0)
  • If you want to create raid 1  – make level= 1  , create two lvm of equal size .
  • If you want to create raid 5 – make level = 5   , create three lvm of equal size .
  • If you want to create raid 6 – make level =6  , create four lvm of equal size .
[root@3usageeks ~]# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/vg22/lv1 /dev/vg22/lv2
mdadm: array /dev/md0 started.
  • Check raid  by  cat  /proc/mdstat command .
[root@3usageeks ~]# cat /proc/mdstat
Personalities :  [raid0]
md0 : active raid0 dm-1[1] dm-0[0]
      1023872 blocks 64k chunks
unused devices: <none>
  • We need to mount the raid to save all data . But before mounting we need to format .
[root@3usageeks ~]# mkfs.ext3 /dev/md0
  • To mount type –   mount   raidname   foldername
  • Check by df  -h command whether its been mounted or not .
[root@3usageeks ~]# mount /dev/md0 3usageeks
[root@3usageeks ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  7.4G  352G   3% /
tmpfs                 972M     0  972M   0% /dev/shm
/dev/md0              985M   18M  917M   2% /root/3usageeks
  • That was temporary mounting means mounting will be lost when system reboots .
  • For permanent mounting go to /etc/fstab file .
[root@3usageeks ~]# vim /etc/fstab
  • And make entry as shown below
/dev/md0                /root/3usageeks         ext3    defaults        0 0
  • Press ESC and type :wq ( to save and quit )
~
~
~
:wq

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s