Increase the size of Oracle Virtualbox VDI Image

Oracle Virtualbox dynamic disks can be incredibly painful at times when you are trying to build or dynamically manage /tmp directories.

If you are having issues with disk space warnings and associated issues when trying to build apps from source using /tmp or other similar issues you can force resize the virtualbox .vdi disk

The overall process involves the following:

  1. Stop your virtualbox instance

  2. Download the gparted image / .iso

  3. Add the iso as a boot disk in Virtualbox

  4. Make sure under System > Boot Order the CD is at the top

  5. Save and start your VM - it should boot from the CD and launch Gparted GUI

  6. Hit enter when you get this screen

  7. Hit enter again

  8. Select the language you want to use

  9. Hit enter again when it asks you which mode you prefer

  10. Once gparted launches make sure you have selected the disk you want to resize. By default, it usually selects the CD you just booted from, change it to your VDI disk

  11. If you are working with Ubuntu then the one you are going to want to resize is the lvm2 pv ubuntu-vg

  12. Click on that partition > Resize

  13. Resize the partition to whatever takes your fancy (I'd recommend 25GB)

  14. Click Resize

  15. Click Apply All Operations (the green tick)

  16. You can now shutdown the VM

  17. Remove the CD Disk image you added so it doesn't boot from the CD again when you startup (virtualbox may automatically do this for you if you shutdown the VM properly)

  18. Restart the VM

  19. You will now need to do some tweaking in ubuntu

  20. Run lsblk

  21. You can see the /dev/sda3 has the new disk space allocated; however, the below lv is not so you need to expand it

  22. Run df -h to list the paths

  23. /dev/mapper/ubuntu--vg-ubuntu--lv is the path you are after

  24. Run sudo lvm lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv to expand it to 100% available space

  25. Run lsblk again

  26. You should now have the extra space you allocated and are good to go

Last updated