Sunday, 17 May 2020

How to Fix VirtualBox UUID already exists Errors


Kitten and partial reflection in mirror, Paul Reynolds / CC BY (https://creativecommons.org/licenses/by/2.0)
Retrieving an old VirtualBox VM earlier, I had to copy the virtual hard drive from one partition to another. I released the copy of the disk from the Virtual Media Manager, tried to add the new copy in the new location to the machine's storage tree and Virtual Box stopped dead because... the disk's unique identifier was already registered by VirtualBox itself. I had to relearn how to fix VirtualBox 'UUID already exists Errors' all over again.


Adding the new copy of the disk in its' newlocation produced the error message:

   Failed to open the hard disk /vm_data/machines/Windws10tp/Windows10_32gb.vdi.

    Cannot register the hard disk '/vm_data/machines/Windws10tp/Windows10_32gb.vdi' {2b9d4351-6574-484b-b0cd-425794af928b} because a hard disk '/medio/medio/VDI/Windows10tp/Windows10_32gb.vdi' with UUID {2b9d4351-6574-484b-b0cd-425794af928b} already exists.

    Result Code:
    E_INVALIDARG (0x80070057)

    Component:
    VirtualBox

    Interface:
    IVirtualBox {3b2f08eb-b810-4715-bee0-bb06b9880ad2}

    Callee RC:
    VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)"

If you copy virtual machines and disks through a file manager to create new VM's then the VMs and drives have the same UUID. This is how VirtualBox tracks its' registered assets. You can't have the same asset with the same UUID as this violates VirtualBox's internal rules for inventory tracking. It is one way of stopping you inadvertently adding the same disk to multiple machines.

If you want to spin off multiple copies of a virtual disk for re-use, there is an easy way how to deal with this, using a little terminal wizardry and a VBoxManage command.

First, check the  UUID's of the disks you want to re-register to make sure you're amending the correct asset:

VBoxManage showhdinfo "[path/virtual disk name]"

For example:

VBoxManage showhdinfo "/medio/medio/VDI/Windows10tp//Windows10_32gb.vdi"

Produces:

UUID:           8d4178a6-1a06-4a68-a5ac-a4f44a26098e
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /medio/medio/VDI/Windows10tp/Windows10_32gb.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       32768 MBytes
Size on disk:   32671 MBytes
Encryption:     disabled


Next run the command to generate a new UUID for the asset in question:

    VBoxManage internalcommands sethduuid [path/virtual disk name]

For example

    VBoxManage internalcommands sethduuid "/medio/medio/VDI/Windows10tp//Windows10_32gb.vdi"

The confirmation message should return:

    UUID changed to: 9becb195-425a-4c71-bc95-dec119ee77aa
 
You can now register and attach the copy of the disk to a different virtual machine. RC

Image credit: Kitten and partial reflection in mirror, Paul Reynolds / CC BY (https://creativecommons.org/licenses/by/2.0)

No comments:

Post a comment

At least try to be nice, it won't kill you...