VirtualBox: Cannot Register the Hard Disk Already Exists

PowerADM.com / Virtualization / VirtualBox / VirtualBox: Cannot Register the Hard Disk Already Exists

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)

VirtualBox - Cannot register the hard disk because a hard disk already exists

The problem is the UUID of this virtual disk is not unique and was not changed when moving /copying the VHD/VDI file.

In order to identify virtual disks in VirtualBox, each disk is assigned a unique UUID. This identifier and the full path to the file are saved in the VM configuration file and registered in the Virtual Media Manager. If you change the file path, VirtualBox will refuse to register a new virtual disk with a non-unique UUID.

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

VBoxManage.exe internalcommands sethduuid - reset disk UUID

You can also unregister the old virtual disk using the Virtual Media Manager. Go to VirtualBox -> File -> Virtual Media Manager (or press CTRL+D).

VirtuaBox -> Virtual Media Manager

Select the virtual disk file and click Release. Now you can delete the old virtual disk entry from VirtualBox Manager. Click the Remove button.

You can remove a drive from the Virtual Media Manager configuration by its UUID or full file path from the command line:

# vboxmanage closemedium disk <uuid/full path to file>

release virtual disk image in oracle virtualbox

This will only remove the virtual disk from the VirtualBox configuration, and will not delete the vhd/vdi file from the storage.

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

  1. Run the Virtual Media Manager (Ctrl+D);
  2. Select virtual disk;
  3. Click the Copy or Move button (depending on the operation you want to perform) and specify a new path to the virtual disk;virtualbox: move or clone virtual disk image file
  4. If you have moved the disk, this will automatically change the path to it in the virtual machine settings;
  5. 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.
You can use the command to copy the virtual disk file:

$ 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.

One thought on “VirtualBox: Cannot Register the Hard Disk Already Exists”
Leave a Reply

Your email address will not be published. Required fields are marked *