Skip to content

Instantly share code, notes, and snippets.

@adrian-pino
Last active March 13, 2025 14:39
Show Gist options
  • Select an option

  • Save adrian-pino/254168c85475409f484c63d94431cd2e to your computer and use it in GitHub Desktop.

Select an option

Save adrian-pino/254168c85475409f484c63d94431cd2e to your computer and use it in GitHub Desktop.
Resize an Ubuntu VM disk with LVM

Disk Resizing on Ubuntu VM with LVM

0. Resize the disk from the hypervisor (e.g.: Proxmox)

1. Rescan the Disk & Check the current partitions

Before starting, ensure the kernel recognizes the new size of the disk:

sudo partprobe
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 209715200 blocks) or continue with the current setting? 

If you get a warning about unused space in the GPT, you can fix it using the steps in the next section.

Now, let's list the current partition:

lsblk

2. Resize the Partition

Use parted to resize the partition

  1. Open parted:

    sudo parted /dev/sda
  2. Inside parted, print the current partition layout:

    print
  3. Resize the last partition (sda3) to use all available space:

    resizepart 3 100%
  4. Exit parted:

    quit

3. Resize the Physical Volume (PV)

Once the partition is resized, expand the Physical Volume (PV):

sudo pvresize /dev/sda3

4. Extend the Logical Volume (LV)

Extend the Logical Volume (LV) to use the newly available space:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

5. Resize the Filesystem

Resize the filesystem to utilize the expanded logical volume.

For ext4 filesystem:

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

For XFS filesystem:

sudo xfs_growfs /dev/ubuntu-vg/ubuntu-lv

6. Verify the Changes

Check the new disk size using:

df -h

This should show the updated disk space on your root partition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment