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
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.
- In Hyper-V, edit the virtual machine and go under “Hard Drive”
- Click on “Edit”, select “Expand” and enter the desired size
- Reboot the virtual machine
- SSH into the virtual machine
- Run
sudo lvdisplayto get the name of the logical volume - Run
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lvto extend the volume to the maximum size available - Run
df -hto see the status of the filesystem free space - Grab the name of your target filesystem (typically
/dev/mapper/ubuntu--vg-ubuntu--lv) - Run
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lvto resize the filesystem - Run again
df -hand you should now see that your volume has been extended
That’s it! Rebooting might not be a bad idea.
- 441
- 1
- 2
- 6
-
3you can also use the gparted GUI tool to resize the ubunu partition – TmTron Jul 11 '22 at 13:45
-
1This 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 '22 at 12:13
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:
Expand the VDHX file via Hyper-V as mentioned in existing solutions and then inside the VM:
fdisk -lSee which partition is the current Ubuntu setup - should be obvious based on size (in my case was sda3)
growpart /dev/sda 3Note the space as mentioned.
pvresize /dev/sda3This is the step which isn't mentioned in a lot of places; its the intemediate step that allows the logical volume extension step work.
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lvThe
/dev/part can seen in the fdisk output from step 1.resize2fs /dev/mapper/ubuntu--vg-ubuntu--lvAfter the prep above, this step now works. Takes a couple of moments and afterwards can verify with
df -hthat the partition is expanded.
- 296
- 2
- 5
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!
- 201
- 2
- 4
-
This is the one that worked for me. sudo lbdisplay returned nothing and pvresize did not work either – Tikhon Jul 26 '23 at 01:14
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
- 2,473
- 10
- 29
- 45
- 11
- 1
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!
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
-
How isn't this an exact duplicate of https://superuser.com/a/1748427/705502, or am I missing something? – Joep van Steen Jan 13 '23 at 15:06