When managing virtual machines (VMs) in Proxmox, you might find yourself running out of disk space. Fortunately, extending or resizing the disk size of an Ubuntu VM is straightforward, thanks to Logical Volume Management (LVM). In this blog post, I'll walk you through the process step-by-step, ensuring you can efficiently utilize all the available disk space.
Prerequisites
A Proxmox VE host with an Ubuntu VM running on it.
Basic knowledge of the Linux command line.
Sufficient space on your Proxmox storage pool to extend the VM's disk.
First, you'll need to increase the disk size for your Ubuntu VM within the Proxmox web interface.
Shut down the VM: Before making any changes, ensure the VM is powered off.
Edit the VM hardware: In the Proxmox web interface, navigate to the VM, click on "Hardware," and select the disk you want to resize.
Resize the disk: Increase the disk size by specifying the additional space you want to allocate (e.g., adding 10GB).
Start the VM: Once the disk has been resized, start the VM.
After resizing the disk in Proxmox and starting the VM, log into the Ubuntu system.
Use the lsblk command to verify the new disk size:
lsblk
You should see the resized disk, but the additional space will likely be unallocated and not yet available to your file system.
If you're using LVM (which is common in many Ubuntu setups), you'll need to extend the LVM partition to use the newly added space.
1. Scan for the Volume Group
First, verify that your volume group is detected correctly:
vgscan
If your volume group is inactive, activate it:
vgchange -ay ubuntu-vg
2. Check Free Space in the Volume Group
Next, check how much free space is available in the volume group:
vgdisplay ubuntu-vg
In the output, look for the "Free PE / Size" line to see how much space is available for allocation.
3. Extend the Logical Volume
Now, extend the logical volume to use all the available space:
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
This command tells LVM to allocate all free space in the volume group to the logical volume.
After extending the logical volume, the final step is to resize the filesystem to use the newly allocated space.
For ext4 filesystems (which is the default in most Ubuntu setups):
resize2fs /dev/ubuntu-vg/ubuntu-lv
This command resizes the filesystem to fill the logical volume. If the filesystem is mounted (e.g., it's your root filesystem /), resize2fs will perform an online resize.
Finally, confirm that the filesystem is now using the new space:
df -h
You should see that the size of the root (/) filesystem has increased, reflecting the additional space you've allocated.
Here’s a summary of the commands used in a real-world scenario:
Check current disk layout:
lsblk
Scan and activate the volume group:
vgscan
vgchange -ay ubuntu-vg
Verify free space in the volume group:
vgdisplay ubuntu-vg
Extend the logical volume:
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Resize the filesystem:
resize2fs /dev/ubuntu-vg/ubuntu-lv
Verify the filesystem size:
df -h
By following these steps, you can easily extend or resize the disk size of an Ubuntu VM running on Proxmox. This guide ensures that your VM can efficiently use all the allocated storage, avoiding any potential issues with disk space in the future.
Whether you're managing a single VM or multiple VMs on your Proxmox setup, knowing how to extend disk space is an essential skill that will help keep your virtual environment running smoothly.