Mar 29, 2012

How to enlarge a VirtualBox disk with Windows XP guest in Kubuntu 12.04

After years of using my VirtualBox instance of Windows XP in my laptop I realized there is not enough space on the disk.

So I decided to enlarge it.

Create a new vdi in ~/.VirtualBox/VDI by running:

$ cd ~/.VirtualBox/VDI
$ VBoxManage createhd -filename new.vdi --size 15000 --remember

where size is in MB, in this example 15000MB ~= 15GB, and new.vdi is name of new hard drive to be created.

Next the old vdi needs to be cloned to the new vdi, this may take some time so wait while it occurs:
$ VBoxManage clonehd old.vdi new.vdi --existing

Detach old harddrive and attach new hard drive, replace VMName with whatever you called your VM:

$ VBoxManage modifyvm VMName --hda none
$ VBoxManage modifyvm VMName --hda new.vdi

Boot the VM, run Partition Wizard to resize the partition on the fly, and reboot.
Remove old vdi from VirtualBox and delete it:
$ VBoxManage closemedium disk old.vdi
$ rm old.vdi