boup.
FR EN

Resize an ext4 or LVM virtual disk

CheatsheetHomelabLinuxCheatsheet
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

  1. fdisk -u /dev/sda
    • p: print the partition table (check start, end and partition number)
    • d: delete the selected partition
    • n: create a new partition
    • N: /!\ answer no when asked to remove the ext4 signature
    • w: write the changes
    • q: quit
  2. partx /dev/sda: refresh the kernel partition layout (if it fails, a reboot is required)
  3. resize2fs /dev/sda1: resize the file system to fill the partition
  4. df -h: check the available space

For LVM

Start with steps 1 and 2 of the ext4 procedure, then:

  1. pvresize /dev/sda3: extend the PV (physical volume)
  2. lvextend -l +100%FREE --fs resize_fsadm /dev/mapper/<lv-name>: extend the LV (logical volume)
  3. If the LV was extended but the file system on it was not: resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Source

https://unix.stackexchange.com/questions/67095/how-to-expand-ext4-partition-size-using-command-line#67107