28

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.

8 Answers8

35

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.

22

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!
20

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

I use Hyper-v Quick Create to create a ubuntu VM. the default disk is /dev/sda1, which is 12GB. it will run out of space quite soon.

I use steps below to expend the disk

  1. stop VM, delete all snapshot, then open settings... of target VM, find the disk setting and change its size.

  2. SSH to VM, run cmd below

sudo -i
growpart /dev/sda 1
resize2fs /dev/sda1

done. run df -h to check the result

maud L
  • 21
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

mr apes
  • 11
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!
Mureinik
  • 4,152
0

or you can just login via GUI, start GParted and easily expand the drive via drag and drop. That's what I have done

Vitas
  • 1,027
-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
Mureinik
  • 4,152