Expanding LVM PVs and LVs
I’m writing this down because I keep having to expand disks in PVE, but can’t remember the commands for the guest and keep having to google it.
- Extend the disk in PVE by however much
- Use fdisk to expand (really, delete then recreate) the partition
# fdisk /dev/vda Command: p Disk /dev/vda: 192 GiB, 206158430208 bytes, 402653184 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 Disklabel type: gpt Disk identifier: 2283D992-048D-407F-A13C-63AFDA9CC224 Device Start End Sectors Size Type /dev/vda1 2048 1050623 1048576 512M EFI System /dev/vda2 1050624 2050047 999424 488M Linux filesystem /dev/vda3 2050048 201324543 199274496 95G Linux filesystem Command: d Partition number (1-3, default 3): Partition 3 has been deleted. Command: n Partition number (3-128, default 3): First sector (2050048-402653150, default 2050048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2050048-402653150, default 402651135): Created a new partition 3 of type 'Linux filesystem' and of size 191 GiB. Partition #3 contains a LVM2_member signature. Do you want to remove the signature? [Y]es/[N]o: n Command: w The partition table has been altered. Syncing disks.
- Extend the PV
# pvresize /dev/vda3 Physical volume "/dev/vda3" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
- Extend the LV
# lvresize -l +100%FREE /dev/mapper/vaermina--vg-root Size of logical volume vaermina-vg/root changed from <95.02 GiB (24325 extents) to <191.02 GiB (48901 extents). Logical volume vaermina-vg/root successfully resized.
- Extend the ext4 partition
# resize2fs /dev/mapper/vaermina--vg-root resize2fs 1.47.0 (5-Feb-2023) Filesystem at /dev/mapper/vaermina--vg-root is mounted on /; on-line resizing required old_desc_blocks = 12, new_desc_blocks = 24 The filesystem on /dev/mapper/vaermina--vg-root is now 50074624 (4k) blocks long.