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 lvdisplay
to get the name of the logical volume - Run
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
to extend the volume to the maximum size available - Run
df -h
to 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--lv
to resize the filesystem - 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. 🙂
-
3
-
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 BOct 27, 2022 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 -l
See which partition is the current Ubuntu setup - should be obvious based on size (in my case was sda3)
growpart /dev/sda 3
Note the space as mentioned.
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.
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
The
/dev/
part can seen in the fdisk output from step 1.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.
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!
-
This is the one that worked for me. sudo lbdisplay returned nothing and pvresize did not work either– TikhonJul 26 at 1: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
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 superuser.com/a/1748427/705502, or am I missing something? Jan 13 at 15:06