This guide shows how to increase the size of a VirtualBox VDI disk and then extend an LVM partition and ext4 filesystem inside the Linux virtual machine.
Resize the VirtualBox Disk
Power off the virtual machine before resizing the virtual disk. On the VirtualBox hypervisor, resize the VDI disk using VBoxManage:
VBoxManage modifyhd "/mnt/data/vbox/VirtualBox VMs/vbox-guest/Snapshots/{19de0931-a68b-4b2d-bd11-4569a5b03eaa}.vdi" --resize 30480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
The --resize value is specified in megabytes. After the virtual disk has been resized, start the virtual machine.
Extend the LVM Partition
Inside the virtual machine, extend partition 3 to use the additional disk space:
root@vbox-guest:~# growpart /dev/sda 3
CHANGED: partition=3 start=3674112 old: size=29878272 end=33552384 new: size=58748895 end=62423007
Check the LVM Physical Volume
Verify that LVM sees the increased physical volume size:
root@vbox-guest:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- 28.01g 18.01g
If pvs still shows the old physical volume size after running growpart, resize the LVM physical volume manually:
Extend the LVM Logical Volume
Add 18 GB to the root logical volume:
root@vbox-guest:~# lvextend -L+18G /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 10.00 GiB (2560 extents) to 28.00 GiB (7168 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
Extend the ext4 Filesystem
Resize the ext4 filesystem so it can use the newly allocated LVM space:
root@vbox-guest:~# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 7340032 (4k) blocks long.
Check the New Disk Size
Finally, verify that the root filesystem has been successfully increased:
root@vbox-guest:~# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 795M 1.1M 793M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 28G 7.6G 19G 29% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 1.7G 251M 1.4G 16% /boot
tmpfs 795M 4.0K 795M 1% /run/user/0
Resize Sequence
The complete process is:
VBoxManage modifyhd "/path/to/disk.vdi" --resize 30480
growpart /dev/sda 3
pvs
pvresize /dev/sda3
lvextend -L+18G /dev/ubuntu-vg/ubuntu-lv
resize2fs /dev/ubuntu-vg/ubuntu-lv
df -h