Proxmox Resize LVM Disk

I find it convenient to start a VM from a cloud-init enabled template I've built which pre-configures the machine with my SSH credentials, networks and so on. At this point, everything is configurable again before I boot in terms of hardware, except for the Disk! We can increase Disk size, but the LVM doesn't automatically update. This information is available elsewhere but I find myself putting together 2-3 sources to get my result each time, so I'm documenting my process here. Hopefully it helps someone else as well!

Starting Point

Create a full clone of the template: 1 Enter the hardware section of the clone, and resize the disk: 2 Now, start the machine and get shell a shell on the system.

Evaluation

Check free space available with fdisk

$ sudo !!
sudo fdisk -l
GPT PMBR size mismatch (16777215 != 3145727999) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 1.48 TiB, 1610612736000 bytes, 3145728000 sectors
Disk model: QEMU HARDDISK
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: 9DAC2783-E920-45AB-9827-39DED54CE6A8
Device       Start      End  Sectors Size Type
/dev/sda1     2048     4095     2048   1M BIOS boot
/dev/sda2     4096  2101247  2097152   1G Linux filesystem
/dev/sda3  2101248 16775167 14673920   7G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 6.102 GiB, 7511998464 bytes, 14671872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

/dev/sda is 1.48Tb, but our lv is only 6.102 Gb

Extend Physical Drive Partition

$ growpart /dev/sda 3

Update PV

# View starting PV
$ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <7.00 GiB / not usable 0
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1791
  Free PE               0
  Allocated PE          1791
  PV UUID               cJxkPB-wQVI-cAMV-jkNc-CDz3-fQ2Y-y3emxI
# Instruct LVM that disk size has changed
$ sudo pvresize /dev/sda3
# Check new PV
$ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               1.46 TiB / not usable 16.50 KiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              383743
  Free PE               381952
  Allocated PE          1791
  PV UUID               cJxkPB-wQVI-cAMV-jkNc-CDz3-fQ2Y-y3emxI

Extend LV

# View starting LV
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                KfMCNz-e2DU-eUXJ-vXA8-Uk0q-DDTW-vnfE27
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-06-13 15:24:01 +0000
  LV Status              available
  # open                 1
  LV Size                <7.00 GiB
  Current LE             1791
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
# Resize LV
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <7.00 GiB (1791 extents) to 1.46 TiB (383743 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
# View changed LV
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                KfMCNz-e2DU-eUXJ-vXA8-Uk0q-DDTW-vnfE27
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-06-13 15:24:01 +0000
  LV Status              available
  # open                 1
  LV Size                1.46 TiB
  Current LE             383743
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Resize Filesystem

$ resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 188
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 392952832 (4k) blocks long.
# Confirm results
$ fdisk -l
...
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 1.47 TiB, 1609534799872 bytes, 3143622656 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes