Technology

Expand CentOS LVM disk and filesystem

There are two ways of expanding your root filesystem space. It’s either by adding additional volumes or by resizing PV. Let’s try the latter. We have CentOS 7 wth XFS running on Proxmox. First expand drive size with admin UI. Next:

yum install cloud-utils-growpart
growpart /dev/sdX 2
pvresize /dev/sdX2
lvextend -l +100%FREE /dev/mapper/centos-root
# and...
xfs_growfs / # for XFS 
# or
resize2fs /dev/mapper/centos-root

At first after resizing drive you will see in lsblk that the drive should have additional space. At growpart you will see your partition expands. At pvresize there is no change. Change happens on lvextend, so you will see you LVM increases in space. To see filesystem change in df you need to run either xfs_growfs or resize2fs depending on your filesystem you’re running on.