Saturday, December 3, 2022

Extending XFS Partition Based LVM by Increasing the Disk Size

This is the original disk layout before the disk extension

We can see that the LVM is built on /dev/sda2, which is a partition, and not a disk. The disk, /dev/sda is now extended by 100G on the VM manager level. After a reboot, we can now see that the disk size is now 130G. 


To include this new space into existing LVM, create a new partition on the new disk space using a tool called cfdisk. Please refer to this post on how to use cfdisk to create a new partition.

The first step is to become root. If you prefer using sudo, please append sudo on each of these commands.

Once we can see that the partition is available, create a new physical volume (PV) using the new partition. 
# pvcreate /dev/sda3 

We should see the message as per below

Then, check what is the name of our volume group (VG)
# vgs 

Extend our VG by including the new PV
# vgextend centos /dev/sda3 

Check what is our logical volume (LV) path
# lvdisplay | grep Path 

Extend our LV to use the whole free space available on the VG
# lvextend -l +100%FREE /dev/centos/root

Check that our LV's size is now expanded 
# lvs 

Determine what is our filesystem type, at the same time we can see that our filesystem is not aware of the new size 
# df -Th / 

Grow xfs filesystem to suit the new partition size
# xfs_growfs /  

We can see that the filesystem is now grown to the full size as per our LV
# df -Th / 


No comments: