LVM is a method of allocating harddrive space into logical volumes that can be easily resized instead of partitions.
With LVM the harddrive (or) set of harddrives are allocated to one or more physical volumes.

The physical volumes are combined into volume groups
Each volume group is divided into logical volumes which are assigned mountpoints such as /home and filesystem types such as ext3

To configure LVM
1)Create three LVM partitions
2)Convert them as physical volumes
3)Create volume groups from physical volumes
4)Create logical volumes from volume groups and assign mountpoints

#fdisk /dev/sda

:8e    (Linux LVM)
:w   (save & exit)
#partx -a /dev/sda (update kernel)

To convert LVM partitions as physical volumes
#pvcreate /dev/sda
ex: pvcreate /dev/sda{9,10,11}

To view physical volumes

To create volume group
ex: vgcreate bsrtech /dev/sda{9,10,11}

To view volume groups

To create a logical volume
#lvcreate -L -n
ex: lvcreate -L +300M /dev/bsrtech -n lv1

To view logical volumes

To format logical volumes
#mkfs.ext4 /dev/bsrtech/lv1

Create a mountpoint and mount logical volume on it
#mkdir /mysql
#mount  /dev/bsrtech/lv1   /mysql
#cd /mysql

To extend size of logical volume
#lvresize -L +
ex:lvresize -L +200M  /dev/bsrtech/lv1
To make filesystem for extended size
ex: resize2fs  /dev/bsrtech/lv1
#mount /dev/bsrtech/lv1  /mysql

To reduce a logical volume
note: whenever we are reducing an LVM we have to take backup (More Details #man lvreduce)
#mkdir  /lvm-bkp
#cp -rf /mysql/*  /lvm-bkp

#lvreduce -L
ex: lvreduce -L -100M  /dev/bsrtech/lv1
To format LVM
ex:mkfs.ext4 /dev/bsrtech/lv1

#mount /dev/bsrtech/lv1  /mysql
#cp -rf /lvm-bkp/* /mysql

To remove an LVM
ex:lvremove /dev/bsrtech/lv1

To extend volume group
1)create another LVM partition
2)convert into physical volume

ex:vgextend /dev/bsrtech  /dev/sda12

To reduce volume group
ex:vgreduce /dev/bsrtech  /dev/sda12

To remove volume group
ex:vgremove /dev/bsrtech

To delete physical volumes
ex:pvremove /dev/sda{9,10,11,12}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.