Extend Ubuntu Server LVM

August 05, 2019

Ubuntu Server has been not utilizing an entire drive when installing a new server utilizing the automatic formatting. This has bit me a few times so I figured I’d dump this information here to reference later.

Let’s check and see what the Logical Volume Name is:

sudo lvdisplay

--- Logical volume ---
LV Path                /dev/ubuntu-vg/ubuntu-lv
LV Name                ubuntu-lv
VG Name                ubuntu-vg
LV UUID                rtf55z-SdW8-DVy1-GSAj-Df3L-72I2-C4srii
LV Write Access        read/write
LV Creation host, time ubuntu-server, 2019-08-05 17:57:56 +0000
LV Status              available
# open                 1
LV Size                4.00 GiB
Current LE             1024
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

Okay, now let’s see the specifics around the ubuntu-vg mentioned in the lvdisplay output.

sudo vgdisplay

--- Volume group ---
VG Name               ubuntu-vg
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               475.43 GiB
PE Size               4.00 MiB
Total PE              121711
Alloc PE / Size       1024 / 4.00 GiB
Free  PE / Size       120687 / 471.43 GiB
VG UUID               7BFwXK-sXAe-EyJE-4kGp-cwFF-Qwj0-dNkhw1

In the output, one of the important things to note is the “Free PE / Size”. In my case, I intend to use the entire disk.

sudo lvextend -l +120687 /dev/ubuntu-vg/ubuntu-lv

Size of logical volume ubuntu-vg/ubuntu-lv changed from 4.00 GiB (1024 extents) to 475.43 GiB (121711 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

As you can see, I was able to fill my entire 500GB NVMe on this box with the logical volume. Now, we need to expand the file-system.

sudo resize2fs /dev/ubuntu-vg/ubuntu-lg

resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 60
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 124632064 (4k) blocks long.

Now let’s double-check to make sure everything is available to us:

df -h

Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv  468G  2.8G  447G   1% /