Easiest Way to Increase Linux LVM by Expanding Virtual Disk

Today, I come across a situation where I had to increase the size of lvm partition without adding a new virtual disk. Here, are the easy steps to increase an lvm partition by expanding virtual disk or vdisk.

Here, Current size of LVM: 110GB New Size should be: 150GB Disk to Expand: /dev/sdb

$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
vg00 1 2 0 wz--n- 76.51g 40.00m
vg01 1 1 0 wz--n- 110.00g 0
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg00 lvm2 a-- 76.51g 40.00m
/dev/sdb vg01 lvm2 a-- 110.00g 0
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 118.1 GB, 118111600640 bytes, 230686720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

I assume that you have expanded the virtual disk from vmware from size 110GB to 150GB.

Step 1: Rescan the disk at OS level so that kernel can be aware of the increased disk size:

# echo 1 > /sys/class/block/sdb/device/rescan

Here, sdb: The disk which was increased.

Step 2: Resize the physical volume:

# pvresize /dev/sdb

Now, check the size of associated PV and VG

# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg00 lvm2 a-- 76.51g 40.00m
/dev/sdb vg01 lvm2 a-- 150.00g 40.00g
# vgs
VG #PV #LV #SN Attr VSize VFree
vg00 1 2 0 wz--n- 76.51g 40.00m
vg01 1 1 0 wz--n- 150.00g 40.00g

Step 3: Increase the size of LV from 110GB to 150GB:

# lvextend -l+100%FREE /dev/mapper/vg01-lvol0 -r
Size of logical volume vg01/lvol0 changed from 110.00 GiB (28159 extents) to 150.00 GiB (38399 extents).
Logical volume lvol0 successfully resized.
meta-data=/dev/mapper/vg01-lvol0 isize=256 agcount=28, agsize=1048320 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=28834816, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 28834816 to 39320576