23

I created a Ubuntu 20.04 LTS virtual machine (VM) on Hyper-V and now I am running out of disk space and I need to increase the filesystem space.

6 Answers 6

30

I tried existing solutions on 18.04 and found it doesn't work with a 'nothing to do' output. Some further searching had similar-but-slightly-different steps and needing to merge a few different bits-and-pieces from other solutions on the web to make work.

Setup: Hyper-V; VHDX file as hard disk; Ubuntu-18.04

Steps:

  1. Expand the VDHX file via Hyper-V as mentioned in existing solutions and then inside the VM:

  2. fdisk -l

    See which partition is the current Ubuntu setup - should be obvious based on size (in my case was sda3)

  3. growpart /dev/sda 3

    Note the space as mentioned.

  4. pvresize /dev/sda3

    This is the step which isn't mentioned in a lot of places; its the intemediate step that allows the logical volume extension step work.

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

    The /dev/ part can seen in the fdisk output from step 1.

  6. resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

    After the prep above, this step now works. Takes a couple of moments and afterwards can verify with df -h that the partition is expanded.

3
18

This is an issue I've run into so many times, I've decided to leave a public trace on how to do it quickly.

  1. In Hyper-V, edit the virtual machine and go under “Hard Drive”
  2. Click on “Edit”, select “Expand” and enter the desired size
  3. Reboot the virtual machine
  4. SSH into the virtual machine
  5. Run sudo lvdisplay to get the name of the logical volume
  6. Run sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv to extend the volume to the maximum size available
  7. Run df -h to see the status of the filesystem free space
  8. Grab the name of your target filesystem (typically /dev/mapper/ubuntu--vg-ubuntu--lv)
  9. Run sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv to resize the filesystem
  10. Run again df -h and you should now see that your volume has been extended

That’s it! Rebooting might not be a bad idea. 🙂

2
  • 3
    you can also use the gparted GUI tool to resize the ubunu partition
    – TmTron
    Jul 11, 2022 at 13:45
  • 2
    This answer is missing two critical steps: Before step 6, the partition holding the LVM physical volume needs to be expanded. Then, the physical volume needs to be expanded (pvresize). See Kelly Trinh’s answer for that.
    – Daniel B
    Oct 27, 2022 at 12:13
15

For me, sudo lvdisplay does not work and returns nothing, for some reason. GParted also refused to start.

So I had to find other ways. Here is what brought luck:

  • Start the VM again and install Guest Utils:
$ sudo apt install cloud-guest-utils
  • If not using English, override locale settings to avoid issues with non-English locales:
$ LC_ALL=C
  • Expand partition into the free space:
$ sudo growpart /dev/sda 5
# NB: space between `partition` and `id`!
  • Resize:
$ sudo resize2fs /dev/sda5
# NB: *no space* between partition and id!
2
  • 1
    This is the one that worked for me. sudo lbdisplay returned nothing and pvresize did not work either
    – Tikhon
    Jul 26, 2023 at 1:14
  • 1
    Best solution for me as well. This works because Ubuntu 22.04 as installed by (Windows 11) Hyper-v's "Quick create -> Ubuntu 22.04" does not use LVM. It's simply an ext4 partition so all you need are growpart and resize2fs. cat /etc/mtab will show what file system your / is mounted as.
    – lancepants
    Mar 23 at 8:48
1

Ubuntu: Extend your default LVM space

Resize partition: sudo cfdisk

Extend PV physical volume: pvresize /dev/sda3

Extend logical volume: lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Resize: resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

0

Setup:
Proxmox 7
Disk model: QEMU HARDDISK
Ubuntu 20.04.3 LTS

Expand the QEMU HARDDISK file via Proxmox as per Proxmox VM disk resize steps and then inside the VM:

$ sudo fdisk -l

See which partition is the current Ubuntu setup - should be obvious based on size (in my case was sda2)

$ sudo growpart /dev/sda 2
# NB: space between `partition` (/dev/sda) and `id` (2)!

Resize:

$ sudo resize2fs /dev/sda2
# NB: *no space* between partition and id!
-1

Expand the Hyper-v hardrive, Under the Edit in Versual hard disk section.

Make sure the checkpoints are merged and deleted while the Virtual

Machine is OFF.

Boot Ubuntu system.

Command line:

sudo su -
fdisk -l
growpart /dev/sda 3
pvresize /dev/sda3
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
resize2fs  /dev/mapper/ubuntu--vg-ubuntu--lv
df -h
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .