Thursday, August 12, 2021

How to resize an LVM partition

My Linux VM is Ubuntu20 with a primary partition of 32GB root volume in an LVM configuration. I need to increase the partition size. We can do this without a service interruption using standard Linux tools.


The overall procedure is as follows:

1. Increase the virtual disk size from the hypervisor
2. Check the partitions to identify which partition you need to expand - sfdisk -l /dev/sda
3. If a partition size mismatch occurs correct it automatically using parted -l /dev/sda
4. Increase the partition size to match the new disk layout - use growpart or parted ex. growpart /dev/sda 3
5. Increase the physical volume size to match the new partition size - pvresize
6. Increase the logical volume size to the new physical volume size - lvextend
7. Finally update the filesystem to match the logical volume layout - resize2fs