geoffwilliams@home:~$

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:

  1. Download the .iso
  2. In VirtualBox, choose VM Settings -> Storage, then insert the .iso into virtual CD drive (add one if missing). Don’t check the Live CD box as this will prevent ejecting the CD at the end of the process
  3. Boot order in same settings dialog should boot the CD first by default. If not, fix this now
  4. 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
  5. Click Next to select Language, Keyboard, Network (wired since it’s a VM), etc until you get to What do you want to do with Ubuntu?. Change the selection to Try Ubuntu and click Close
  6. 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 gparted click the app icon and then authorize running as root by clicking Authenticate on the next dialogue
  7. Good old gparted should 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 a swap partition, you may need to right click -> swapoff it, to avoid the live CD sneakily using it and stopping you resizing things.
  8. Finish up in gparted, then shutdown the system with the menu in top right corner. The CD will automatically be ejected when you hit enter as prompted
  9. Power-on the VM, login and check you have some free space with the df command.

Final word of warning: If gparted offers to fix the GPT layout, say yes.

And now back to our AI enhanced sandbox.

Post comment

Markdown is allowed, HTML is not. All comments are moderated.