Wednesday, 11 August 2021

Extend Logical volume using LVM

 Extend Logical volume using LVM


I am going to extend already created xfs file system using LVM by 1GB.
Currently i have no free space in pv / vg / lv to extend it to the File system.
So i will be adding a new 1 GB disk to the VM first and then extend vg / lv.
Adding disk and making partition is explained here.

Let's continue with our work to extend pv first. 
Current pv vg and lv output as below. and you can see i have no space for now. 

1.1 Current Physical volume

1.2 Current Physical volume free space detail

1.3 Current VG details

1.4 Current LV details

I have completed adding disk and got it on the server by scanning the scsi hosts.
Lets proceed creating a new pv using the newly added disk. 
Command to create pv - pvcreate 
Syntax : pvcreate disk_name
disk_name = /dev/sdc1

1.5 pv create

Now we can extend our vg vgdata with the newly created pv as shown below,
Syntax: vgextend vgname pvname
vgname = vgdata
pvname = /dev/sdc1

1.6 vg extend



1.7 new vg details


1.7 current lv details

Now we have free space in vg, we can extend the lv,
Syntax : lvextend -L +size lvname
size = 1020MiB 
lvname = /dev/vgdata/lvdata

1.8 extend lv

You can see the newly extended size in lvs and lvdisplay command as below

1.9 new lv

LV size is extended, however this will not be visible to file system yet. we have to resize / grow the file system. I have a xfs file system so i will use xfs_growfs, if you have a older fs like ext4/3/2 you may use resize2fs.

command: xfs_growfs
Syntax : xfs_grow lvname/devicename
lvname = /dev/mapper/vgdata-lvdata

1.10 xfs grow

Once you have executed xfs_growfs for the file system you can now see the increased size in the df -h output and you can start utilizing the newly available fs. 

1.11 Extended xfs filesystem


This is the best advantage of a LVM, you can grow/extend/increase your file system space online without any need for downtime. 
LVM has many more uses like cluster support, raid features, backup/recovery.

No comments:

Post a Comment