Resizing VirtualBox disk images

Recently I had the misfortune of having my windows virtual test machine fill up it’s hard drive. When I had created it, my host system had limited space and I only needed to test things in a windows environment inside a browser, so it got a small hard disk image. One day, while installing a new program, it simply ran out.

I could make a new virtual machine and re-install  but that requires configuration, whereas resizing only takes time.

In command line, navigate to the directory with the troubled system’s hard disk image. Since I had exported and imported this machine when I moved from a desktop to my nice new (to me) laptop my disk image was in vmdk format, but you need a vdi format to resize. So first we convert the disk:

Once cloned, you can resize the vdi you just made. Please note that the size is in MB.

The disk is now resized, but not attached to our virtual machine. I simply edited the virtual machine to point to the resized copy. Alternatively you can convert the image back into vmdk and copy it over the original.

(Don’t forget to delete extraneous copies, these files take up a lot of space)

The virtual machine should now have the new resized attached to it and it should be bootable, but the windows install can still only use the original size. We need to alter the partition to make it use the full disk. For this we need to boot into a live Linux disk with GParted. I used the Ubuntu 12.04 install CD, but GParted also have a live image available if you lack an already downloaded disk. Once you have saved the partition, you can shutdown the live disk and reboot into windows, which now has access to the entire resized hard disk image.

Software and versions used:
Ubuntu 12.04 LTS 64-bit (Xubuntu Desktop)
VirtualBox 4.1.12
Xubuntu Desktop 12.04 LTS Live CD
GParted