Introduction
I'm writing this article mostly for my future self since I already did this kind of expansion twice before. Most online tutorials focus on Ubuntu VMs with graphical interfaces, but I prefer headless Ubuntu Server installations for better performance — no GUI overhead.
Setup:
- Host OS: Windows 10 Pro
- Virtualization: VirtualBox
- Guest OS: Ubuntu Server 20.04 LTS
- Standard installation without drive encryption
Prerequisites
- Access to your virtualization software
- Sudo privileges on the guest VM
- Cfdisk utility (typically pre-installed on Ubuntu LTS)
Quick Reference (TL;DR)
Sequentially increase the following components:
- VDI size via Virtual Media Manager
- Physical Volume using
cfdiskandpvresize - Volume Group (optional) using
vgextend - Logical Volume using
lvresize - Filesystem using
resize2fs
Step 1: Increase VDI Size
In VirtualBox, open File → Virtual Media Manager. Select your VM's virtual disk image and use the slider or input field to expand it to the desired size.
Step 2: Increase Physical Volume
Using cfdisk
Launch cfdisk which will automatically detect the expanded VDI:
sudo cfdisk
The utility presents straightforward operations: select the partition you want to resize, choose Resize, confirm the new size, then select Write to save changes to disk.
Using pvresize
After exiting cfdisk, expand the physical volume:
sudo pvresize /dev/sda3
Replace /dev/sda3 with your corresponding physical volume.
Step 3: Increase Volume Group (Optional)
This step is only needed when adding a new physical volume rather than resizing an existing one. If you're resizing an existing partition, you can skip this step.
Step 4: Increase Logical Volume
First, verify the physical and logical volume sizes:
sudo fdisk -l
Then allocate all available free space to your logical volume:
sudo lvresize -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Replace the path with your actual logical volume path.
Step 5: Increase Filesystem
Finally, make the space available to the operating system:
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
You can verify the expansion was successful with:
df -h