Errors when compacting VirtualBox VHD Image
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 technet.microsoft.com/en-us/library/gg252556.aspx.
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 vdi
See this example..., as well as this comprehensive example by Matt Wrock on how to optimise a VirtualBox VM, ready for packaging.
Related videos on Youtube
naivedeveloper
Updated on September 18, 2022Comments
-
naivedeveloper 3 monthsMy 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.
-
evilpenguin over 5 yearsI have noticed that when converting from VHD to VDI, the result is already optimized, so you don't have to run --compact on it again. -
Scott - Слава Україні almost 4 yearsI'm not sure that this is relevant to this question, since the image that the OP was trying to compact was already a clone/copy of an existing VM.