How to resize Ubuntu disk hosted on Proxmox
It turned out, that while creating a VM template in Proxmox 10G of storage is not enough if you want Ubuntu server and some apps running on Docker. I learned this the hard way 😄.
I found extending disk space in the VM quite challenging, here's how to do it.
#1 extend VM disk space in Proxmox
It can be easily done in Proxmox GUI. Go to your VM -> Options -> Hardware and click on Hard Disk. Now select Disk Action and choose Resize.
A modal will pop up. Here enter a value that you want your disk to be resized with. In my case I want to add 20G of space.
Once applied - we're not done yet. Start your VM and log in to terminal.
#2 extending root space
Log into your Ubuntu VM. When you enter df -h
you will notice that nothing really changed.
We need to run couple of commands. Follow along.
Firstly, we need to know which partition we need to extend.
Run lsblk
. You will see that ubuntu--vg-ubuntu--lv
is attached to sda3
, so that is the place that we should extend.
Next up, type in sudo cfdisk
. Navigate down to /dev/sda3/
and choose Resize
option. You will be asked to provide the new size. By default it will be set to max avaiable size. Then, choose Write
option, and Quit
.
Okay, change are still not visible. Let's continue with
sudo pvresize /dev/sda3
.
Now before we go to the next step, we need to find out what the Logical Volume Name is (LV name). To do that enter sudo lvdisplay
and copy the LV name parameter. In my case it is /dev/ubuntu-vg/ubuntu-lv
.
Next up enter the follwing command:
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
We are nearly there. When we check sudo lvdisplay
we can see that LV size is now what we expected. But still, we need to resize the root file system. To do that we need to know which filesystem to resize. Hit df -h
and find /dev/mapper/ubuntu--vg-ubuntu--lv
.
I promise it's the last step. To resize the filesystem, just run the command: resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
And that's it! Verify the changes with df -h
.
Conclusion
I've showed you how to extend disk space in your Ubuntu hosted on Proxmox with just a few Linux commands. Now when your VM approaches disk limit, you can easily extend the volume.
References:
https://pve.proxmox.com/wiki/Resize_disks
https://www.youtube.com/watch?v=58m0hnt0ij8