How to expand Ubuntu disk inside Virtual Machines
For two times in my life I struggled to find a way to increase Ubuntu LVM disk size inside virtual machines (Hyper-V and WSL2). Maybe these solution works for you.

df -h
command is resulting a 100% use like this picture, you should try this article.TL;DR
$ sudo lvmdiskscan
$ sudo growpart /dev/sda 3
$ sudo pvresize /dev/sda3
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
$ df -h
1. If you have a Hyper-V virtual machine (maybe also applicable to VirtualBox or VMware)
Increase the physical disk file (VHDX or VDI)
In Hyper-V, follow these steps:
- Shutdown the virtual machine
- In Hyper-V Manager go to
Settings
→ select the hard drive →Edit
. If this option is disabled, delete any checkpoints for the VM. - Select the
Expand
operation and increase to a desirable size. - Turn on the VM again and follow the next step
Find your /sda/dev
device
- Inside VM’s terminal, find the right
/sda/dev
device with command:
$ sudo lvmdiskscan
The result is something like this:

You are looking to device at the first column where the third column is named “LVM physical volume”. Note down the number after “/dev/sda” (in this example is “3”.
2. Run the following commands replacing the device number you found above:
$ sudo growpart /dev/sda 3
$ sudo pvresize /dev/sda3
I think growpart
is a CLI from cloud-guest-utils
. So, maybe you need sudo apt install cloud-guest-utils
first.
Now follow the steps below.
2. If you already had increased physical disk space OR you have a WSL2 subsystem
Run the commands:
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Now list storage devices again and be happy 😛
$ df -h
