Problems cloning VirtualBox disk images.
Antarctica Starts Here. » Antarctica Starts Here. 2014-02-04
Summary:
VirtualBox is a (mostly) open source virtualization stack designed to run on desktop machines. While you can run it in a "serious" fashion (such as using VMs to implement your network infrastructure) it really shines if you use it as part of your development effort.
If you want to get under the hood the VBoxManage utility is the first place to start. It lets you do things like convert and manipulate disk images, something that I do from time to time at work these days. Until I ran into the following problem when trying to convert a VMDK virtual disk into a VDI so a cow-orker could run a VM inside of Parallels:
[drwho@orobouros output-virtualbox-iso]$ VBoxManage clonehd virtual-machine-disk1.vmdk virtual-machine-disk1.vdi
VBoxManage: error: UUID {5de67552-5ce0-40b5-9ae3-2c22e1e43f74} of the medium '/home/drwho/appliance/output-virtualbox-iso/virtual-machine-disk1.vmdk' does not match the value {f12334aa-250b-421f-a118-9e98138a7d48} stored in the media registry ('/home/drwho/.config/VirtualBox/VirtualBox.xml')
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Medium, interface IMedium, callee nsISupports
VBoxManage: error: Context: "CloneTo(dstDisk, ComSafeArrayAsInParam(l_variants), NULL, progress.asOutParam())" at line 740 of file VBoxManageDisk.cpp
The first thing I did was probe the virtual disk to determine its status:
[drwho@orobouros output-virtualbox-iso]$ VBoxManage showhdinfo virtual-machine-disk1.vmdk
UUID: f12334aa-250b-421f-a118-9e98138a7d48
Parent UUID: base
State: inaccessible
Access Error: UUID {5de67552-5ce0-40b5-9ae3-2c22e1e43f74} of the medium '/home/drwho/appliance/output-virtualbox-iso/virtual-machine-disk1.vmdk' does not match the value {f12334aa-250b-421f-a118-9e98138a7d48} stored in the media registry ('/home/drwho/.config/VirtualBox/VirtualBox.xml')
Type: normal (base)
Location: /home/drwho/appliance/output-virtualbox-iso/virtual-machine-disk1.vmdk
Storage format: VMDK
Format variant: dynamic streamOptimized
Capacity: 16384 MBytes
Size on disk: 1106 MBytes
After some head scratching and playing around at the command line, I figured out the fix - the virtual disk had to be closed (insofar as VirtualBox is concerned) before it could be manipulated (including converting it into a different format):
[drwho@orobouros output-virtualbox-iso]$ VBoxManage closemedium disk virtual-machine-disk1.vmdk
The output of the VBoxManage command was thus:
[drwho@orobouros output-virtualbox-iso]$ VBoxManage showhdinfo virtual-machine-disk1.vmdk
UUID: 5de67552-5ce0-40b5-9ae3-2c22e1e43f74
Parent UUID: base
State: created
Type: normal (base)
Location: /home/drwho/appliance/output-virtualbox-iso/virtual-machine-disk1.vmdk
Storage format: VMDK
Format variant: dynamic streamOptimized
Capacity: 16384 MBytes
Size on disk: 1161 MBytes
Please note the value of "State:" and the lack of an "Access Error:" line in the output. I was then able to convert the disk image into the VDI format:
[drwho@orobouros output-virtualbox-iso]$ VBoxManage clonehd --format VDI virtual-machine-disk1.vmdk virtual-machine-disk.vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: fe587770-4096-415f-8e4f-73c7f1837745
Success!