Resize an ext4 or LVM virtual disk
On this page
Context
Extending a partition of a VM on an ext4 / LVM file system. Start by extending the virtual disk on the hypervisor (Proxmox, for example). Then run the following commands on the VM.
For ext4
fdisk -u /dev/sdap: print the partition table (check start, end and partition number)d: delete the selected partitionn: create a new partitionN: /!\ answer no when asked to remove the ext4 signaturew: write the changesq: quit
partx /dev/sda: refresh the kernel partition layout (if it fails, a reboot is required)resize2fs /dev/sda1: resize the file system to fill the partitiondf -h: check the available space
For LVM
Start with steps 1 and 2 of the ext4 procedure, then:
pvresize /dev/sda3: extend the PV (physical volume)lvextend -l +100%FREE --fs resize_fsadm /dev/mapper/<lv-name>: extend the LV (logical volume)- If the LV was extended but the file system on it was not:
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv