How to Extend the size of Volume Group and Logical volumes(LVM)

Volume Group/Logical Volume Extending(LVM)

In our previous article we have seen the basics of LVM, how to configure PV, VG, LV, Here we are going to see how to increase the size of the existing volume group and logical volume size.As I have stated earlier the biggest advantage of Logical volume manager is, it allows us to increase the size of the logical volumes at any time when you are running out of space.

If you missed my previous  Basic LVM article you can visit here  Understanding LVM

Now in our case we have three PV, one VG and four LV, Check the details by using the following command

#pvs
#vgs
#lvs

As you can see from the above output, we don’t have enough space available in physical volumes and volume group, For example, if there is a requirement of additional 10 GB to one of the  logical volume, will it be possible to add 10 GB extra to the logical volume???no…we couldn’t extend that as we don’t have enough space in VG,

for extending what we have to do is, we need to add one physical volume(PV) and then we have to extend the volume group(VG) by extending the VG then we will get enough space to increase the logical volume size, so first will add one physical volume

For adding the PV we need to create one LVM partition with “fdisk” command

NOTE: YOU CAN ASLO ADD A NEW PHYSICAL HARDDISK TO EXTEND THE SIZE OF VG AND LV

1.To create a new partition, Press n

2.Choose the primary partition, press p

3.Choose which number of partition to be selected to create the primary partition

4.Press 3 (coz already I have created two partitions )

5.change the type using t

6.Type 8e to change the partition type to Linux LVM

7.Press w to write the changes

Now reboot the system once completed

Now check the partition we have created with fdisk

#fdisk   -l   /dev/sda

Now create a PV(Physical volume) using the following command

#pvcreate  /dev/sda3

Check the PV details

#pvs or pvdisplay

Extending the size of the Volume Group(VG)

Now you have to add this newly created PV to the volume group VG1 to grow the size of the volume group  to get more space for expanding Logical volume (LV)

Syntax:

#vgextend   <Volume group name>    <Physical volume name>
#vgextend   VG1   /dev/sda3

Now let us check the size of the volume group by using the following command

#vgs

As you can see from the above output, now the volume group  VG1 space extended from 3.99 GB to 19.09 GB

If you want to check which PV is used to create particular volume group run the following command

#pvscan

As you can see from the above screenshot each PV and its associated VG names are listed, we have just added one PV  and it’s totally free.

Extending size of the Logical volume(LV)

Before we expanding the size let us check the size of the  each Logical volumes

#lvdisplay or lvs

For better view Output has been truncated

In this example am going to expand the size of the logical volume lv1 (current lv1 size is 2 GB)

I will add additional 10 GB to the logical volume lv1

syntax:

#lvextend  -L <+size>   <Logical volume name path>
#lvextend -L +10 GB  /dev/VG1/lv1

As you can see from the above screenshot, now the  filesystem size is extended 10 12 GB  from  3.99 GB

After extending we need to resize the filesystem by using the following command

Before you run the resize2fs command you must have to run the e2fsck command to check the

#e2fsck -f  /dev/VG1/lv1

e2fsck is used to check the integrity of ext2/ext3/ext4 filesystem types.

Note:resize2fs will not run unless you execute e2fsck . 

#resize2fs  /dev/VG1/lv1

Now let us see the size of the re-sized logical volumes by using lvdisplay

#lvdisplay

As you can see from the above output after extending there is 12.00 GB from 3.99 GB

Now if we check the VG size available

#vgs

The above output says the current available VGfree size is changed from 19.9 GB to  9.09 GB

I hope now you have got some ideas on LVM concepts, resizing the LV, VG volumes.

Never miss any articles from Vasanth blog follow my facebook page for updates Learn Linux in an easier way
If you found this article useful, Kindly Subscribe here 👉👉🏿Click this link to Subscribe

 

 

About Author:

Hello readers! Let me introduce my self first. My name is Vasanth Nirmal Singh J S having 9+ years of experience in IT on all flavours of Unix operating systems ,Storage's and many more .. I would like to share my technical experience i have come across - can be help to other people. So in this blog, I'll post my thoughts related to ITIS. I'll share experiences that I've had while working in different environments. You can expect content related to Unix,Solaris,Linux,EMC Storeages,HP-UX and many others. I hope this blog can be useful for you! Your comments will be appreciated!

Leave a Reply

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