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 Answers
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.
- 476
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!
- 321
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.
- 581
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
stop VM, delete all snapshot, then open settings... of target VM, find the disk setting and change its size.
SSH to VM, run cmd below
sudo -i
growpart /dev/sda 1
resize2fs /dev/sda1
done. run df -h to check the result
- 21
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
- 11
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!
or you can just login via GUI, start GParted and easily expand the drive via drag and drop. That's what I have done
- 1,027
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