My host OS is OS X Lion running a Windows XP client with VirtualBox 4.2.0. I'm wanting to make a copy of the image and compact it to share with a colleague. First, I used the VirtualBox command line to clone the image via clonehd.
VBoxManage clonevdi /path/to/image.vhd /new/path/to/image.vhdNext, I tried compacting the image with the following command:
VBoxManage modifyhd /new/path/to/image.vhd --compactIn which I'm presented with the following error:
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to compact hard disk
VBoxManage: error: Could not compact medium '/new/path/to/image.vhd' (VERR_INVALID_STATE)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Medium, interface IMedium
VBoxManage: error: Context: "int handleModifyHardDisk(HandlerArg*)" at line 577 of file VBoxManageDisk.cppI've tried my hand at resolving the issue by searching, but I've came up empty handed up to this point. Any help will be greatly appreciated.
2 Answers
You can only compact VDI images using the VirtualBox commandline as far as I know. You can use 3rd party tools to compact a VHD - Google is your friend.
If your host is Windows 7 or Windows Server 2008 R2, you should be able to use compact vdisk according to the page at .
In the VirtualBox world, here's how...
VBoxManage modifyhd path\to\disk.VDI --compact...if you've created a disk in a different format - e.g. VHD, exec the following command first...
VBoxManage clonehd "path\to\vhdformat.vhd" "path\to\vdiformat.vdi" --format vdiSee this example..., as well as this comprehensive example by Matt Wrock on how to optimise a VirtualBox VM, ready for packaging.
1Same happened to me just now but I quickly fixed it by just shutting down the virtual machine.
-Looks like you can't shrink virtualbox storage while it's in use.
1