Growing VirtualBox disks (Linux)
VirtualBox makes the perfect AI playground, but sooner or later you will likely hit the dreaded No space left on device error.
Here’s how to fix it:
Step 1 - shutdown VM
Needs to be powered off, not suspended
Step 2 - Grow the disk with VBoxManage
Find the VDI, then use VBoxManage to resize it (Example: grow to 50GB):
# megabytes
VBoxManage modifymedium disk debian\ 13.vdi --resize 51200
Output:
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
This of course assumes you are using dynamically allocated disk images. If you opted for fixed image sizes, you will need to clone the whole drive to a new, growable image first as the command above would just error out in this case.
Step 3 - Grow the disk in Linux
Warning on snapshots
Resizing a disk that has snapshots can behave unexpectedly (the resize applies to the base image, not the current state). Delete/merge your snapshots first - you have been warned.
LVM
If you used LVM when setting up your VM, you can follow my notes to grow the LV holding your root filesystem. Job Done.
growpart
If you’re not using LVM and are also “lucky”, you can use growpart to expand a single EXT2/3/4 partition, like this (see also xfs_growfs for XFS):
sudo apt install cloud-guest-utils
sudo growpart /dev/sda 2
sudo resize2fs /dev/sda2
However, this relies on contiguous free space. If you have other partitions “in the way”, you will need to move them to the start/end of the drive with gparted first. Read on.
gparted
You can’t move the partitions you need to with gparted from the running system - you will need to boot into live OS and run gparted against the unmounted drive instead.
The easiest live environment I have found is Ubuntu Desktop. Boot into the live environment and gparted will be right there as an app.
To boot Ubuntu Live DVD instead of your normal Linux:
- Download the
.iso - In VirtualBox, choose
VM Settings->Storage, then insert the.isointo virtual CD drive (add one if missing). Don’t check theLive CDbox as this will prevent ejecting the CD at the end of the process - Boot order in same settings dialog should boot the CD first by default. If not, fix this now
- Boot the VM,
Try or Install Ubuntu, wait a few mins for the OS to load, errors about unsupported graphics can probably (but not necessarily) be ignored, as long as things are still moving on the boot screen - Click
Nextto select Language, Keyboard, Network (wired since it’s a VM), etc until you get toWhat do you want to do with Ubuntu?. Change the selection toTry Ubuntuand clickClose - Now you should be dropped to the desktop. Click the funny 3 dot circle (app grid) in the bottom left of the screen to bring up the apps menu, start typing
gpartedclick the app icon and then authorize running as root by clickingAuthenticateon the next dialogue - Good old
gpartedshould now be running. Make sure to select the correct device, then move and adjust your filesystems as required to use the new space. If you have aswappartition, you may need to right click ->swapoffit, to avoid the live CD sneakily using it and stopping you resizing things. - Finish up in
gparted, then shutdown the system with the menu in top right corner. The CD will automatically be ejected when you hitenteras prompted - Power-on the VM, login and check you have some free space with the
dfcommand.
Final word of warning: If gparted offers to fix the GPT layout, say yes.
And now back to our AI enhanced sandbox.