Linux- How to‎ > ‎

Ch 11 LVM

Logical Volume Manager

Object of LVM

1) P.V   Physical Volume

2) V.G   Volume Group  (it could be from different HDD)

3) L.v   Logical Volume (it create in LVM)














III. All LVM become V.G   ( Volume Group)

     All LVM1,2 .... N become VG.




From V.G we needs to create L.M 

P.E  ( Physical Extend )

Physical Volume P.V we will get P.E.

1 PE = 4 M.B. (Mega byte)

LV ---> LE

LE ----> Logical Extend

How to create LVM.

#fdisk /dev/sda

Create two Partition and change system id to 8e (Hexadecimal for LVM)

-> n

-> E

-> u

-> +500M

-> t 8e (repeat all step for 2nd partition above command runs after

#fdisk /dev/sda 

# partprobe

# pvcreate /dev/sda? (? 1st partition NO) /dev/sda?(?2nd Partition)

# pvdisplay

# pvscan

( TO create physical Volume PV)

#vgcreate lvm0 /dev/sda? /dev/sda? (? 1st & 2nd Partition NO)


(TO create volume group)


#lvcreate –L +300M lvm0

(default name lvm0)

(to format the logical volume )

#mkfs.ext3  /dev/lvm0/lv010


#mkdir /lvm0

(Mount lvm0 in /lvm0 directory)

#mount /dev/lvm0/lv010 /lvm0

After reboot for auto mount add entry of this partition in /etc/fstab

Or add command with full path in /etc/rc.local.

To extend  LVM Partition

#lvextend –L +300M /dev/lvm0/lv010


To Reduce LVM Partition

Very Important small mistake lead you in big trouble so be very careful while reducing

The LVM Volume.

* It is mandatory to umount  your Volume before shirking/reducing the LVM Volume 

You have 5 GB Volume and you want to reduce it to 4 GB, There will be 4 GB Space reclaim from the Volume Group VG. and your final LV size will be 1 GB. 

# umount /oracle or # umount /dev/VolGroup00/lvol0 

# lvresize --resizefs --size -4G /dev/lvmtest/lvol0

fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/dev/mapper/lvmtest-lvol0: clean, 11/655360 files, 55936/1308672 blocks
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/lvmtest-lvol0 to 260096 (4k) blocks.
The filesystem on /dev/mapper/lvmtest-lvol0 is now 260096 blocks long.
Reducing logical volume lvol0 to 1016.00 MB
Logical volume lvol0 successfully resized

# Mount /dev/VolGroup00/lvol0 /oralce

New Resized volume size has 1 GB it was 5 GB before reduce. 

To Remove LVM

#umount /dev/lvm0/lv010

# vgchange –an lvm0

# vgremove lvm0

# Remove entry from /etc/fstab for any change in partition table partprobe is necessary)

How to use LVM with Private Cloud / Virtulization 

In the Cloud world Industry require cost effective solution with minimal downtime where Cloud and LVM technology is very use full.

I will cover How to add Storage on the fly to your VM and How to reduce it. without impacting Production environment.

Here is the scenario :

  • vmWare Esxi 5.0 Host 
  • SAN Storage 
  • Depending upon RAID Group LUNs are created
  • All LUNs are expose to available ESX Host.
  • Exposed LUN are formatted with VMFS.  

You have Linux VM1 Instance running on HOST1 which has 20 GB Disk allocated,and you want increase the disk to more 10 GB:

# Current Mount Point of VM and Disk Size.

# Adding VMware Disk of extra 10 GB to Same VM.

# Detecting New Added Hard disk to Kernel 

# creating New Partition with latest attached Disk.

# to Enter in Fdisk command console use  # fdisk /dev/sdb and once you complete the Partition creation press Command (m for help):w to save and exit.

# Resizing Online Volume.

# New Size of Volume is 27 GB in first Screen Shot it was 18 GB we have successfully extend the / Partition without any downtime.