Logical Volume manager (LVM)

Using the Logical Volume Manager or LVM we can create special kind of volumes to store datas which can be increased or decreased as per need. This resizing of the volumes are of minimal effort and so comes handy for managing the resources effectively. The following diagram will give you a better understanding of how the LVM works

Let us consider there are two HDD of 10 GB each ( /dev/sda and /dev/sdb). We can create physical partitions of 5 GB in both the disks( /dev/sda1 , /dev/sda2, /dev/sdb1, /dev/sdb2). Now picking three of these partitions we create one volume group ( we can later include new hdd or the remaining 5 Gb partition to the volume group ) of 15 GB. Now we can create smaller logical volumes as per need from this available 15GB space. Lets consider we have created one logical volume of 8 Gb. So there is still 7 Gb of space in hold. We can use this space to make more Logical volumes of use it when the already created LV needs resizing.

We will now discuss how to accomplish this thing.

First we need to create physical volumes out of the physical partitions available :

# pvcreate /dev/sd[ab][12]

 

** Use command like pvdisplay and pvscan to display and scan the available physical volumes. e.g. #pvscan

Now , create the Volume group (vgname) out of these PVs.

# vgcreate vgname /dev/sda1 /dev/sda2 /dev/sdb1

Use    #vgdisplay   to display the volume groups.

You can use the following command  to include the remaining physical volume to the VG anytime if you need.

# vgextend vg /dev/sbb2

We can now create our logical volumes from the available 15GB of space in the VG. Use the command

# lvcreate -n logicalvolname –L 8G vgname

 

** Use command like lvdisplay to display the available logical volumes. e.g. #lvscan

Now don’t forget to give it a filesystem and mount it in a directory to make it usable.

# mkfs.ext3 /dev/vgname/logicalvolname

# mkdir /project

# mount vgname/logicalvolname /project

Edit the file /etc/fstab accordingly if you want to make it permanent.

Use command like lvextend to extend the logical volumes. e.g

# lvextend -L +1G /dev/vgname/logicalvolname

** Donot forget to unmount the volume before resizing  it.

*** Note that if you use XFS or JFS filesystem, you cannot shrink it.

Note that though we have resized the volume, the ext3 filesystem on it has stayed unchanged. We need to resize the filesystem to actually fill the volume.

# e2fsck –f /dev/vgname/logicalvolname   

# resize2fs /dev/vgname/logicalvolname

And lastly, if you wish to remove the logical volumes.

# lvremove/dev/vgname/logicalvolname

That was simple LVM which maynot be of much use in coprotate sector where you will need Clustered LVM ( mirrored volumes).  Now that we know about the basic concept about LVM, we can proceed further to create the clustered LVM. We will consider three HDD ( /dev/sda /dev/sdb and /dev/sdc ) with 3 partitions in each , e.g. /dev/sda1 ,/dev/sda2 , /dev/sda3 , /dev/sdb1 , /dev/sdb2 , /dev/sdb3 and /dev/sdc1 , /dev/sdc2 /dev/sdc3

Lets create the physical volumes first

# pvcreate /dev/sd[abc][123]

Now, lets create the volumegroup and logical volume from it

# vgcreate vgname /dev/sd[abc][123]

# lvcreate -L 10G -n lvgroupname -m 1 vgname /dev/sda1 /dev/sdb1 /dev/sdc1

We can use the following command  to verify the mirrored layout.

# lvs -a -o +devices

** Use  –P with commands like lvs or vgs commands to check from the volumes that have failed.

** When any leg of the mirror fails, it gets converted in a singular linear volume. To rebuild it, recreate the physical volume ( pvcreateI) , check it (pvscan) , extend the original volume group with the new physical volume ( vgextend)

# vgextend vgname /dev/sda[123]

Now, convert the linear volume back to its original mirrored state

# lvconvert –m1 /dev/vgname/lvgroupname /dev/sda1 /dev/sdb1 /dev/sdc1

 

If you have a broken volume group, use the command vgcfgrestore to restore the volume group’s metadata

# vgcfgrestore vgname

 

** If you lose a physical volume, you can activate remaining PV in the VG with the - -partial  argument in the vgchange command

 

 

 

 

 

 

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.