Aller au contenu
Ubuntu / Linux

Extend an LVM Logical Volume on Ubuntu Server (Use All Your Disk)

sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv grows the logical volume and its filesystem in one step, without a reboot.

Testé sur Ubuntu Server 24.04 LTS, 22.04 LTS

A common surprise after installing Ubuntu Server: a 100 GB disk, but df -h shows a root filesystem of about half that. The installer created an LVM volume group across the whole disk but only allocated part of it to the root logical volume. The rest is free – you just need to assign it.

Step 1 – See the real free space

df only shows what is allocated to filesystems. To see the whole volume group, use vgdisplay:

Terminal
sudo vgdisplay
  • VG Size – total space in the volume group.
  • Alloc PE / Size – space already given to logical volumes.
  • Free PE / Size – unallocated space you can use.
vgdisplay output showing free space in the volume group
df -h output showing the smaller root filesystem

Step 2 – Find the logical volume path

Terminal
sudo lvdisplay

On a default install the root volume is /dev/ubuntu-vg/ubuntu-lv.

lvdisplay output showing /dev/ubuntu-vg/ubuntu-lv

Step 3 – Extend the volume and filesystem

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

-l +100%FREE uses all remaining space (use +50%FREE to keep some in reserve). -r resizes the filesystem in the same step. Both work online – no reboot or unmount.

lvextend output

Already ran lvextend without -r? Grow the ext4 filesystem separately:

Terminal
sudo resize2fs /dev/mapper/ubuntuu002du002dvg-ubuntuu002du002dlv
resize2fs output

Step 4 – Confirm

Terminal
df -h /

Added a new virtual disk instead?

If you enlarged the virtual disk in VMware or Hyper-V, first grow the partition (sudo growpart /dev/sda 3) and the physical volume (sudo pvresize /dev/sda3), then run the lvextend command above.

Back up first

Resizing is routine, but take a snapshot or backup before changing storage on a production server. XFS filesystems can only grow (use xfs_growfs); none of these commands shrink a volume.

Inder Kochar

Écrit par

Inder Kochar

Ingénieur systèmes et réseaux – Je rédige les solutions que j’applique chez mes clients, testées sur de vrais systèmes. Bloqué sur un problème similaire ?

Continuer la lecture

Posez une question ou partagez votre solution

Votre e-mail n’est pas publié. Les commentaires sont modérés – merci de rester dans le sujet.