146

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?

apaderno
  • 28,547
  • 16
  • 75
  • 90
CJAY
  • 6,989
  • 18
  • 64
  • 106
  • 1
    Paths having space characters should be enclosed in double quotes, as you have discovered already. – A.B. Jul 18 '16 at 13:32

9 Answers9

194

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
CJAY
  • 6,989
  • 18
  • 64
  • 106
  • 29
    I really wish VirtualBox will have some UI or a window that allow us to change this – fedmich Feb 11 '15 at 15:49
  • 3
    This needs to be quoted due to the space in the filepath. – Chris Stryczynski Jun 29 '18 at 14:14
  • It would be nice if the VirtualBox UI gave the option to generate a new UUID when you tried to open a disk that's already known. Honestly I don't really use the disk manager for anything, I'd rather VirtualBox just treat virtual disks as file paths instead of trying to treat them like resources to manage and track. – jrh Apr 10 '20 at 03:12
  • Got this error after running the command: UUID {abc} of the medium 'D:\path\to\vdi' does not match the value {123} stored in the media registry ('C:\Users\Test\.VirtualBox\VirtualBox.xml'). – SZT Oct 20 '22 at 10:36
45

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

borchvm
  • 3,533
  • 16
  • 44
  • 45
  • 1
    I think this answer is more helpful for anyone (including me) who wants to copy the virtual machine. – cbuchart Apr 03 '16 at 22:02
  • 1
    Just wondering - why did you need to change Machine uuid? If I just want to copy vmdk disk from one machine to another, I don't need that, right? – Oleg Gryb Dec 15 '16 at 22:45
  • 1
    You need to change the Machine uuid if you copy the virtual disk on the same machine – borchvm Dec 15 '16 at 22:52
  • @borchvm Machine UUID doesn't match its UUID in the registry file. I go to edit VirtualBox.xml MachineEntry uuid to match, but this file gets refreshed every time i restart virtual box. I need to edit this uid. Do you know how? I am searching online – Fabrizio Bertoglio Apr 18 '17 at 07:34
  • 1
    Worked perfect in my case- thanks! I didn't need to adjust the Machine UUID. – Benco Nov 01 '18 at 01:40
  • 2
    @FabrizioBertoglio hopefully you have your answer - but you need to stop vbox services of any kind in order to edit those files - otherwise you get same ole same ole. Also make sure your UUID for SATA HardDisk at the bottom of config file matches the UUID for the Hard Disk in the HardDrive section at the top of the config file. Before you do any of this though you will also want to add a your . – Ken Feb 21 '19 at 22:10
  • In my vbBox i found multiple with all of them having different values. Are we supposed to change all of those? – SZT Oct 20 '22 at 10:37
15

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.

Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • You are probably right. I followed your instruction and I have still the error Querying UUID Failed, even if the Hard Disk show up correctly both on `file -> Virtual Media Manager` and on the Machine Settings with the correct UUID – Fabrizio Bertoglio Apr 18 '17 at 07:54
  • I'm not sure what your case is. What I've described above is exactly what I did and it worked for me on Mac with VB 5.1.8 – Oleg Gryb Apr 19 '17 at 18:00
  • I have solved the problem with the following steps: `1. re-installing virtual box using synaptic package manager` then `2. In the virtual box machine configuration, I did not disable the Floppy disk and EFI Setting. I kept them enabled.` The problem was fixed. – Fabrizio Bertoglio Apr 21 '17 at 08:31
  • @OlegGryb It might depend on Host OS and also Guest OS. – Ken Feb 21 '19 at 22:12
12

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"
al3x2ndru
  • 598
  • 5
  • 8
11

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.

JavaNoScript
  • 2,345
  • 21
  • 27
6

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
januarvs
  • 398
  • 3
  • 7
5

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.

masterxilo
  • 2,503
  • 1
  • 30
  • 35
4

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 !

aniston
  • 3,007
  • 2
  • 11
  • 3
2

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
Whitaker
  • 31
  • 3