Extend virtual drive HyperV Ubuntu

Turn off the VM.

Use Manager (Hyper-V Manager or Esxi) to select the Settings of the Virtual Machine, select the Hard Drive option and Edit under Virtual hard disk. Use the GUI to expand the drive, start the VM again.

Install Guest Utils (as root)

apt install cloud-guest-utils

You can check the size of your disks (here 95% of use, the free space is 5%)

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 124G 113G 6.3G 95% /

Use PVS to see the physical partition

pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <125.50g 0

Resize the physical volume

pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

Expend the logical volume (name from df -h)

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

Check the size again

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 156G 113G 38G 76% /

If you’re not using LVM, you can replace the pvresize/lvextend steps with resize2fs instead. A simple resize2fs /dev/sda3 will be the job.