All notes

Ubuntu Server only uses half the disk: grow the root volume with lvextend

UbuntuLVMLinuxSelf-hosting

Run sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv. It gives the root logical volume every free extent in its volume group and grows the ext4 filesystem on it in the same step, while it’s mounted, with no reboot. On the VM that runs Rubric’s pipeline, it took / from 19 GB at 84% to 38 GB at 42%.

Find the free space

lsblk          # the disk, the partition LVM uses, and the volume on it
sudo vgs       # VFree: space in the volume group that no volume uses yet
df -h /        # what the filesystem has

The VM runs Ubuntu 24.04.5 LTS on a 40 GB disk. lsblk showed the partition LVM uses, sda3, at 38 GB and the root volume on it at 19 GB, and vgs had the other half under VFree. When VFree holds what you’re missing, the one command is all it takes.

If VFree is zero but lsblk shows the disk bigger than the partition, which is what you see after enlarging a VM’s virtual disk, the space is outside LVM. Grow the partition and the physical volume first (growpart comes with the cloud-guest-utils package), then run the same lvextend:

sudo growpart /dev/sda 3
sudo pvresize /dev/sda3

Grow it

sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

-l +100%FREE adds all the free extents in the volume group, so you don’t have to work out a size. -r resizes the filesystem along with the volume, so there’s no separate resize2fs. ext4 can grow while it’s mounted, and / stayed in use the whole time. Afterwards:

$ df -h /
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv   38G   15G   21G  42% /

Growing is the easy direction. Shrinking ext4 needs it unmounted, so give the root volume what it needs rather than more than you’ll use, if you plan to keep free space for another volume or for snapshots.

Why the installer left half

Ubuntu Server’s guided install with LVM sizes the root volume from the volume group: all of it under 10 GiB, 10 GiB up to 20, half of it up to 200 GiB, and 100 GiB above that. The rule is scaled_rootfs_size in the installer’s source, and the space it leaves is meant for snapshots and for growing volumes later. A 38 GB volume group gets 19. In an autoinstall file, sizing-policy: all gives the root volume everything from the start.

Nothing tells you at boot. I found out when the disk filled: on 31 October an image build took / to 100%, the second time in three days. With 21 GB free, the same build now fits.