When trying to connect a copied or moved disk image file (*.VHD/*.VDI) of an Oracle VirtualBox virtual machine, you will receive an error:
VirtualBox - Error
Failed to open the hard disk image file FilePath.vhd.
Cannot register the hard disk FilePath.vhd <GUID> because a hard disk DifferentFilePath.vhd with UUID <GUID> already exists.
Result Code: E_INVALIDARG (0x80070057)
Component: VirtualBoxWrap
Interface:IVirtualBox {GUID}
Callee RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)
The problem is the UUID of this virtual disk is not unique and was not changed when moving /copying the VHD/VDI file.
Virtualbox Hard Disk UUID Already Exists
You can change the UUID of a virtual disk using the vboxmanage
tool.
On Ubuntu Linux, you need to go to the directory with the virtual machine disk image file:
# cd /mnt/path/vms/
List all disk UUIDs available in VirtualBox:
# vboxmanage list hdds
Get information about the virtual disk (including the current UUID):
# vboxmanage showhdinfo yourfile.vdi
Generate a new UUID:
# VBoxManage internalcommands sethduuid yourfile.vdi
In Windows, you need to open a command prompt as an administrator and run the command:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands sethduuid "E:\VirtualBoxVMs\VMname\yourfile.vdi"
A message should appear:
UUID changed to: NewUUID
You can also unregister the old virtual disk using the Virtual Media Manager. Go to VirtualBox -> File -> Virtual Media Manager (or press CTRL+D
).
Select the virtual disk file and click Release. Now you can delete the old virtual disk entry from VirtualBox Manager. Click the Remove button.
# vboxmanage closemedium disk <uuid/full path to file>
After that, you can attach a disk to the virtual machine (open VM settings -> Storage -> Add Attachment Add Hard Disk -> Choose existing disk).
You can manually remove the old virtual disk from the VM configuration file. Check that VirtualBox Manager is not running and edit the files \.VirtualBox\VirtualBox.xml and \.VirtualBox\VirtualBox.xml-prev using your favorite text editor.
Remove the <HardDisks>...</HardDisks>
section for the disk you want to remove:
<HardDisks>
<HardDisk uuid="{xxxxxxxxxxxxxxxxxxxxxxxxxxxx}" location="~/VirtualBox VMs/VM1/box-disk001.vmdk" format="VMDK" type="Normal"/>
<HardDisk uuid="{yyyyyyyyyyyyyyyyyyyyyyyyyyy}" location="~/VirtualBox VMs/VM2/box-disk001.vmdk" format="VMDK" type="Normal"/>
Then run VirtualBox Manager.
How to Clone or Move Virtual Disk Images in Oracle VirtualBox?
The error VBoxManage.exe:: Cannot register the hard disk because a hard disk with UUID already exists
will appear if you manually moved the virtual disk file to another disk or folder.
Instead of manually copying/pasting VirtualBox virtual disk files (VDI, VHD) using the operating system tools, you must move/copy disks through Virtual Media Manager
- Run the Virtual Media Manager (
Ctrl+D
); - Select virtual disk;
- Click the Copy or Move button (depending on the operation you want to perform) and specify a new path to the virtual disk;
- If you have moved the disk, this will automatically change the path to it in the virtual machine settings;
- If you have created a copy of the disk, you can add it to the virtual machine. Select Add hard disk -> Choose existing disk -> Specify the path to the disk.
$ VBoxManage clonehd /home/user1/VMs/vm1/vm1.vdi /home/user1/VMs/vm1/vmnew.vdi --variant Standard
This will immediately assign a new UUID to the new disk image. Note that VBoxManage creates a complete clone of the original disk. This means it will take up as much disk space as the original file. If you want a disk file to take up as much space on the host as is actually filled in the virtual file system, use the Disk2vhd tool from Microsoft.
Thank you!