Skip to content

Ubuntu LVM Expansion

On the cluster nodes, if there is additional disk space you can use this with the following commands to expand the LV to match the maximum available disk size.

Note, the main partition during installation was only 100GB out of 500GB…

ubuntu@k8s-control-plane-node:/$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.6G  3.0M  1.6G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   98G   47G   46G  51% /
tmpfs                              7.7G     0  7.7G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
...

Using fdisk shows the raw disk space available is ~500GB…

ubuntu@k8s-control-plane-node:/$ sudo fdisk -l
Disk /dev/sda: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: 512GB SSD       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AC52E26C-6583-4398-8856-D1793E22BC27

Device       Start        End   Sectors   Size Type
/dev/sda1     2048    2203647   2201600     1G EFI System
/dev/sda2  2203648    6397951   4194304     2G Linux filesystem
/dev/sda3  6397952 1000212479 993814528 473.9G Linux filesystem
# Increase the Physical Volume (pv) to max size
pvresize /dev/sda3

# Expand the Logical Volume (LV) to max size to match
lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

# Expand the filesystem itself
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
ubuntu@k8s-control-plane-node:/$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.6G  3.1M  1.6G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  466G   49G  398G  11% /
tmpfs                              7.7G     0  7.7G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
...