Sunday, February 26, 2012

Logical Volume Manager (LVM)

Logical Volume Manager also known as LVM, Its provide facility to create partitions flexibly. LVM gives System Administrator, power to extend or reduce the partitions online, means we can extend a logical volume while the data on it is being accessed by the users, without corruption of data.
It is important to understand the basic concept of LVM. There are mainly three steps(points) to create LVM:  

1) Physical Volume:- Actual hard-disk or a partition of disk. 
2) Volume Group :- Group of one or more than one physical Partition(s)
3) .Logical Volume :- Partition created from Volume Group.
To Create a lvm partition below r the following steps:-

Firstly create a normal partition of 2GB & change its partition id of lvm i.e. 8e  like this
#fdisk /dev/sda
     Press p   (Than Enter)-----To Show Partition
     Press n   (Than Enter)-----To create Partition
    Than Enter in  First Cylinder
    Than type +2G in Last Cylinder
    Then type t and Enter--------To give partition id of lvm
    Then type partition No. 6 and Enter(we assume that it is 6 partition)
    Then type lvm id 8e and Enter
    Then type w and Enter (To save the partition)

Then reboot the system
#reboot
After reboot the system

#fdisk –l ----- To check the  Partition
#pvcreate /dev/sda6 ----To create physical volume
#pvdisplay----To check the physical volume
 
#vgcreate vol0 /dev/sda6------To create volume group & name vol0
#vgdisplay------To check volume group

To create 1GB logical volume and name vol1
#lvcreate –L 1024M –n vol1 /dev/vol0
-L is used to define size of Lvm, -n is used to name Logical volume
#lvdisplay-----To check logical volume

To Format Logical Volume
#mkfs.ext4 /dev/vol0/vol1 
To create a lvm directory
#mkdir /lvm
To permanently mount it
#vim /etc/fstab 
------Type below line at last in this File
 /dev/vol0/vol1               /lvm      ext4      defaults 0 0
------& save it with :wq

#mount –a------To mounted partition
To check actual size of lvm partition mounted in /lvm directory
#df –h

 To Extend lvm partition vol1 upto 1300MB

#umount /lvm
#lvextend –L +300M /dev/vol0/vol1
#e2fsck –f /dev/vol0/vol1
#resize2fs /dev/vol0/vol1 1300M
#mount –a
#df –h
#lvdisplay

To reduce lvm partition vol1 of 1GB to 700MB

#umount /lvm
#e2fsck –f /dev/vol0/vol1
#resize2fs /dev/vol0/vol1 700M
#lvreduce –L -300M /dev/vol0/vol1
#mount –a
#df –h
#lvdisplay