Extend an LVM logical volume into the free space of its VG
Read VFree from vgs, then grow the logical volume and its ext4 file system with one lvextend -r -l +100%FREE line. Covers XFS and the case where VFree is 0.
If df -h / shows far less than the disk you have, check whether the LVM volume group (VG) still has unused space. When the installer sized the root logical volume (LV) smaller than the VG, the rest sits idle. The output below comes from a VG built on two loop devices; only the names were changed to the Ubuntu defaults (ubuntu-vg, ubuntu-lv).
[1] Check how much space the VG has left. Anything other than 0 under VFree can be allocated.
# vgs ubuntu-vg VG #PV #LV #SN Attr VSize VFree ubuntu-vg 2 1 0 wz--n- 492.00m 240.00m[2] Check the LV size and the file system size. The LV path is /dev/<VG name>/<LV name>.
# lvs ubuntu-vg LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ubuntu-lv ubuntu-vg -wi-ao---- 252.00m # df -h /srv/dataFilesystem Size Used Avail Use% Mounted on/dev/mapper/ubuntu--vg-ubuntu--lv 220M 24K 203M 1% /srv/dataThe LV is 252M and the VG is 492M, so 240M is free. Find the file system type with findmnt -no FSTYPE /srv/data; ext4 or xfs decides step 6.
[3] Add all the free space to the LV and grow the file system in the same command. It works while mounted.
# lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv Size of logical volume ubuntu-vg/ubuntu-lv changed from 252.00 MiB (63 extents) to 492.00 MiB (123 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.resize2fs 1.47.0 (5-Feb-2023)Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /srv/data; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 1The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 125952 (4k) blocks long.-l +100%FREE adds all remaining free space in the VG. -r (--resizefs) resizes the file system on the LV with fsadm after the LV grows. Without -r only the LV grows and df stays the same; run resize2fs /dev/ubuntu-vg/ubuntu-lv yourself in that case.
[4] Check the result.
# vgs ubuntu-vg VG #PV #LV #SN Attr VSize VFree ubuntu-vg 2 1 0 wz--n- 492.00m 0 # df -h /srv/dataFilesystem Size Used Avail Use% Mounted on/dev/mapper/ubuntu--vg-ubuntu--lv 445M 24K 417M 1% /srv/dataVFree is now 0 and the Size in df went from 220M to 445M. Running the same command again prints Size of logical volume ... unchanged and Nothing to do! with exit status 0, so a repeat is harmless.
[5] If VFree is 0, the VG has no space to give, so grow the disk side first. On a virtual machine, enlarge the disk on the host. Then extend the partition that holds the PV to the end of the disk (growpart) and tell the PV (pvresize).
# growpart /dev/sda 3# pvresize /dev/sda3growpart takes the disk and the partition number as separate arguments. growpart -N /dev/sda 3 (--dry-run) only reports what it would do. Confirm the names with lsblk and pvs. This step was not run; it follows the usage in growpart --help and pvresize --help. Afterwards VFree in vgs has grown, so repeat step 3.
[6] On an XFS file system you can use xfs_growfs instead of lvextend -r. XFS grows while mounted and cannot be shrunk.
# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv# xfs_growfs /srv/dataxfs_growfs takes the mount point, not the device. Since there is no way back once XFS has grown, extend by only what you need (-L +10G) if you might want the space elsewhere later.
If the disk is full and you first need to know what is using the space, see Find what is eating the space when a disk is full.