VirtualBox VM Disk Clone UUID problem

A VM disk image in Virtual Box (version 4.0.6) can be cloned using the command line “VBoxManage” tool with the “clonehd” command. Unfortunately, cloning a VM that already has a registered UUID in Virtual Box fails like that:

` #> ‘C:\Program Files\Oracle\VirtualBox\VBoxManage.exe’ clonehd .\MyVM.vdi .\NewVM.vdi

VBoxManage.exe: error: Cannot register the hard disk ‘C:\VMs\MyVM.vdi’ {601b44ed-a301-45a7-8b17-9b2185040a1e} because a hard disk ‘C:\VMs\MyVM1.vdi’ with UUID {601b44ed-a301-45a7-8b17-9b2185040a1e} already exists VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component VirtualBox, interface IVirtualBox, callee IUnknown Context: “OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, pMedium.asOutParam())” at line 209 of file VBoxManageDisk.cpp`

A quick way to clone the disk would just be to copy the file, don’t you think? Unfortunately the UUID still remains embedded in the copied VM image and does not allow you to load the new VM in the same machine!

One solution would be to copy the disk image and then change the UUID of the copied image to a new one. Such an option, however, does not show up on the VBoxManage printout!

Fortunately there’s an undocumented command of VBoxManage to do what we need, as I found in https://forums.virtualbox.org/viewtopic.php?p=33678

Unfortunately the command shown there was wrong, or it may have changed in recent versions of Virtual Box:

#> 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' internalcommands setvdiuuid .\MyVM.vdi Syntax error: Invalid command 'setvdiuuid'

The correct command is ‘sethduuid’ (showing up on the internalcommands usage printout) and using that we can finally change the UUID and use the copied VM image as a new VM:

#> 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' internalcommands sethduuid .\MyVM.vdi UUID changed to: 0156199f-6e83-4cd6-97b7-c9e24d9cd26d

All done! You can now create a new VM on the same computer using the copied disk image without any problems.