My Ubuntu VM was running out of space. The good thing about VMs is that the hard disk storage file can just be expanded. I followed the steps from this blog post.
First, expand the size of the disk. My host OS is Windows, so the following command is for the Windows version of VirtualBox. If the VirtualBox folder isn’t in the PATH variable, you will have to use the full path to VBoxManage.exe. For the command below to work, your working directory should be where the vdi file is. The final parameter is the new desired size of the partition.
VBoxManage.exe modifyhd mydisk.vdi --resize 20000
The partition must now be resized to make use of the expanded disk. Boot to a liveCD of Ubuntu to use the GParted partition editor. If you have an ISO file, it’s a pretty simple matter of assigning it to the virtual CD drive. Boot from the liveCD, select “Try Ubuntu” and start GParted.
If the Swap partition is in the way, right click on it, select Swapoff so that the partition can be moved. This is also necessary to do other stuff to the swap partition, like deleting it.
The swap partition was in the way, preventing me from expanding the primary partition, so I first had to move the extended partition all the way over. To do so first required deleting the swap partition. Right click on the swap partition to open the context menu and select delete.
Now click on the cyan border of the extended partition to select it, then right click and select Resize/Move. Adjust the sliders to move it to the end. This post here had the solution to the problem of moving the extended partition.
Recreate the swap partition in the extended partition. linux-swap is one of the options for the filesystem type.
Finally, extend the primary partition to take up the space. Remember to click on the green tick to apply the changes.
Shutdown the VM and remove the liveCD from the virtual CD drive. Reboot, and the available disk space has been increased!