Expanding VirtualBox Partition

Trying to update to Ubuntu 11.04 on my trusty virtual machine today, I got a message saying that the disk was full.

Since the VM is just a file on my windows hard drive on which I have plenty of space, I thought it would be fairly easy to just increase the size of the file and thus give me enough space. Turns out there are a few more steps than that.

The first thing to do is to increase the size of the VirtualBox file. This can be done with the VBoxManage command from the windows command line.

VBoxManage modifyhd d:\ubuntu.vdi --resize 12200

Replace the filename with your own vdi file and the number with the desired size in megabytes.

This only adds unallocated space to the virtual computer. The next problem is to add this to the root partition. This can only be done when the partition is not mounted and thus requires booting from a live CD. I don’t have live CDs around but I do have a USB thumbdrive with a copy of Ubuntu on it. However, it’s not that easy to boot to a USB drive from VirtualBox. It involves fooling the system into thinking that the USB drive is actually an IDE drive.

Follow the instructions at agnipulse.com to see how to accomplish this. When running the command line command and when adding the vmdk file, run the command line and VirtualBox in Administrator mode, or it’ll fail with funny errors. This was mentioned in some VirtualBox forum threads.

VBoxManage internalcommands createrawvmdk -filename d:\usb.vmdk -rawdisk \\.\PhysicalDrive1

Which PhysicalDrive number the USB drive is actually at should be checked from Disk Management.

After booting up to the USB image, run GParted. Delete the extended partition containing the swap partition. Extend the primary partition then add the swap partition back at the end of it.

That’s it! Enjoy the glorious extra space now available on the root partition.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s