Resizing vmdk harddisks for VirtualBox

VirtualBox is a free tool, which allows you to run virtual machines on a host computer. Using VirtualBox you can install Linux, Windows and other operating systems to play and experiment with.

Start the process by closing virtualbox (I usually also dettach the virtual harddisk due to be resized).
Go on to a shell and find the directory where the virual machines are located.

If your initial harddisk was cloened from another virtualbox, you may get an error like this:

VBoxManage: error: Cannot register the hard disk 'disk01.vmdk' {eaed1256-a34f-4c2f-873b-62cc78c4be80} because a hard disk 'disk01.vmdk' with UUID {eeed1256-a32f-4c1f-813a-62dd78c4be80} already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp

To fix this issue pop into a terminal and enter this command:

vboxmanage internalcommands sethduuid ./disk01.vmdk

This command changes the HD uuid from the disk and ought to fix the issue.

Ready to resize

Next challenge is that the disk is in vmdk format, so to resize we need to convert the disk to VDI format, resize and convert back to vmdk format:

vboxmanage clonehd ./disk01.vmdk clone.vdi --format vdi
VBoxManage modifyhd ./clone.vdi --resize 30720
vboxmanage clonehd ./clone.vdi ./disk01.vmdk --format vmdk

The “virtual physical drive” is now resized, but the partion on the harddisk also need to be resized.

Boot up the virutal box (and make sure the disk is attached if you’ve dettached it during the conversion and resizing).

  • In Linux you can do this through using Gparted.
  • In Windows go to Computer Management (by right clicking “My Computer” and find “Storeage” -> “Disk Manangement”.

Change the partition on the drive need to be expaned and save the changes. The drive should now be resized and ready to be used.