How do I change the UUID of a virtual disk?

Virtual MachineVirtualbox

Virtual Machine Problem Overview


I am trying to create a new virtual machine with Oracle VirtualBox, using an already-existing hard disk. When I try to select the existing hard disk file, a .vhd file, it displays an error saying the virtual hard disk cannot be used because the UUID already exists.

So I tried the following command to change its UUID.

VBoxManage internalcommands sethduuid /home/user/VirtualBox VMs/drupal/drupal.vhd

I get this error.

> Syntax error: Invalid UUID parameter

How can I resolve this?

Virtual Machine Solutions


Solution 1 - Virtual Machine

The correct command is the following one.

VBoxManage internalcommands sethduuid "/home/user/VirtualBox VMs/drupal/drupal.vhd"

The path for the virtual disk contains a space, so it must be enclosed in double quotes to avoid it is parsed as two parameters.

Solution 2 - Virtual Machine

The following worked for me:

  1. run VBoxManage internalcommands sethduuid "VDI/VMDK file" twice (the first time is just to conveniently generate an UUID, you could use any other UUID generation method instead)

  2. open the .vbox file in a text editor

  3. replace the UUID found in Machine uuid="{...}" with the UUID you got when you ran sethduuid the first time

  4. replace the UUID found in HardDisk uuid="{...}" and in Image uuid="{}" (towards the end) with the UUID you got when you ran sethduuid the second time

Solution 3 - Virtual Machine

If you've copied a disk (vmdk file) from one machine to another and need to change a disk's UUID in the copy, you don't need to change the Machine UUID as has been suggested by another answer.

All you need to do is to assign a new UUID to the disk image:

VBoxManage internalcommands sethduuid your-box-disk2.vmdk
UUID changed to: 5d34479f-5597-4b78-a1fa-94e200d16bbb

and then replace the old UUID with the newly generated one in two places in your *.vbox file

<MediaRegistry>
  <HardDisks>
    <HardDisk uuid="{5d34479f-5597-4b78-a1fa-94e200d16bbb}" location="box-disk2.vmdk" format="VMDK" type="Normal"/>
  </HardDisks>

and in

    <AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0">
      <Image uuid="{5d34479f-5597-4b78-a1fa-94e200d16bbb}"/>
    </AttachedDevice>

It worked for me for VirtualBox ver. 5.1.8 running on Mac OS X El Capitan.

Solution 4 - Virtual Machine

I have searched the web for an answer regarding MAC OS, so .. the solution is

cd /Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/MacOS/

VBoxManage internalcommands sethduuid "full/path/to/vdi"

Solution 5 - Virtual Machine

Though you have solved the problem, I just post the reason here for some others with the similar problem.

The reason is there's an space in your path(directory name VirtualBox VMs) which will separate the command. So the error appears.

Solution 6 - Virtual Machine

The command fails because it has space in one of the folder name, i.e. 'VirtualBox VMs.

VBoxManage internalcommands sethduuid /home/user/VirtualBox VMs/drupal/drupal.vhd

If there is no space at folder name or file name, then the command will work even without quoting it, e.g. after changing 'VirtualBox VMs' into 'VBoxVMs'

VBoxManage internalcommands sethduuid /home/user/VBoxVMs/drupal/drupal.vhd

Solution 7 - Virtual Machine

Even though this question asked is old, note that changing a UUID on a virtual HDD in a windows system will make windows treat it as a not activated machine (as it notices the disk change) and will ask for reactivation !

Solution 8 - Virtual Machine

Same solution as @Al3x for Windows x64, in cmd.exe:

cd %programfiles%\Oracle\VirtualBox

VBoxManage internalcommands sethduuid "full/path/to/.vdi"

This randomizes the UUID of the disk. Pro tip: Right click the .vdi file while holding shift and select "Copy as path" to obtain "full/path/to/.vdi" and enable quick edit in cmd.exe, then right click to paste.

Solution 9 - Virtual Machine

Another alternative to your original solution would be to use the escape character \ before the space:

VBoxManage internalcommands sethduuid /home/user/VirtualBox\ VMs/drupal/drupal.vhd

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCJAYView Question on Stackoverflow
Solution 1 - Virtual MachineCJAYView Answer on Stackoverflow
Solution 2 - Virtual MachineborchvmView Answer on Stackoverflow
Solution 3 - Virtual MachineOleg GrybView Answer on Stackoverflow
Solution 4 - Virtual Machineal3x2ndruView Answer on Stackoverflow
Solution 5 - Virtual MachineJava XuView Answer on Stackoverflow
Solution 6 - Virtual MachinejanuarvsView Answer on Stackoverflow
Solution 7 - Virtual MachineanistonView Answer on Stackoverflow
Solution 8 - Virtual MachinemasterxiloView Answer on Stackoverflow
Solution 9 - Virtual MachineWhitakerView Answer on Stackoverflow