198

I created a virtual disk file VM_1_Ubuntu.vdi. Then I moved it into another folder. I tried to update VM settings (right click on virtual machine -> settings -> Storage -> Controller SATA tab, VM_1_Ubuntu.vdi path). I wanted to set a new path.

It says Cannot register the hard disk already exists

Yan Khonski
  • 12,225
  • 15
  • 76
  • 114

11 Answers11

290

I found a solution

File -> Virtual Media Manager -> Removed existing images (note, I removed them only from the registry).

I followed these steps.

http://www.webdesignblog.asia/software/virtualbox-moving-vdi-file-re-linking-guest/#sthash.1QOHeiw5.dpbs

After that I could update the path in the VM settings.

Yan Khonski
  • 12,225
  • 15
  • 76
  • 114
  • 3
    If drive where disk was stored is not available then first Release (Ctrl + L) disk from the VM and the Delete (Ctrl +D). Otherwise before releasing the disk you will not able to delete. After that follow the steps in above link or Open "Settings" of the Virtual Machine, go to "Storage", click "Add Attachment", select "Add Hard Disk" and "Choose existing disk", then selected the vdi file and you are done. – Syed Nasir Abbas Apr 18 '19 at 11:08
  • 1
    you have to delete all snaphots so that remove button is not greyed out. – Rishi Sep 28 '19 at 06:32
  • Works thx! First release, then remove right! – Harvey68 Dec 14 '22 at 08:55
  • Now Virtual Media Manager is moved to File > tools > Virtual Media manager – Adeel Raza Azeemi May 31 '23 at 08:07
180

It's possible to change the UUID on the VDI file using the command:

 VBoxManage internalcommands sethduuid <file.vdi>

It seems this command assigns a new "random" UUID to the file. No much documentation on it, though.

The Impaler
  • 45,731
  • 9
  • 39
  • 76
  • 2
    Perfect for my needs (resizing a virtual hard drive wasn't working, without moving it). – shiri Sep 11 '17 at 12:58
  • 5
    VBoxManage is an exe that for me was in "C:\Program Files\Oracle\VirtualBox", so just run from a cmd window. – Giles Apr 18 '18 at 09:32
  • 2
    This is the ideal solution when you have a base OS image and want to make a copes to install multiple apps on copies of the base without having to change the base itself. – Jersey_Guy Jun 25 '18 at 19:29
  • 2
    Helped me resizing a drive – Zumteufel Sep 07 '19 at 03:52
  • 1
    This solution also solved a situation where I had copied the VM to another location, removed the original from VirtualBox, and was trying to compact the disk. The command: $ VBoxManage modifymedium Windows\ 7\ Professional.vdi --compact The error: VBoxManage: error: Cannot register the hard disk '/Users/c/VirtualBox VMs/Windows 7 Professional/Windows 7 Professional.vdi' {a510ee0d-2cef-47db-b25f-acae9e341d45} because a hard disk '/Volumes/ramdisk/Windows 7 Professional/Windows 7 Professional.vdi' with UUID {a510ee0d-2cef-47db-b25f-acae9e341d45} already exists – EmpathicSage Feb 06 '20 at 06:49
  • the command sethduuid also works for .vmdk. – Gilson Nov 01 '21 at 17:30
  • NB: _WARNING: This is a development tool and shall only be used to analyse problems. It is completely unsupported and will change in incompatible ways without warning_ – golimar Oct 20 '22 at 04:44
  • **This command removed some of my VMs from VirtualBox** (the VM folders and .vdi files are still there), I'm guessing because some paths contained symlinks. Backup your VirtualBox.xml and VMs xml files first – golimar Oct 20 '22 at 08:28
34
  1. Select File from Oracle VM VirtualBox Manager
  2. Virtual Media Manager
  3. Remove the file (highlighted yellow) from Hard disks tab.
Syed Nasir Abbas
  • 1,722
  • 17
  • 11
16

Here is the solution for that find the UUID of box

vboxmanage list hdds

then delete by

vboxmanage closemedium disk <uuid> --delete
  • Before running these two commands, don't forget to navigate to the virtualbox directory at `C:\Program Files\Oracle\VirtualBox` and then run command prompt in this directory. – Hasanuzzaman Sattar Mar 08 '22 at 10:08
9

If there is no possibility to remove or change path to a hard disc file using Virtual Media Manager (in my case) then:

  1. Open '.vbox' and '.vbox-prev' (if exist) files in any text editor.
  2. Edit 'location' attribute of the element 'HardDisk' to your path, for example: "d:/VM/VirtualBox/Win10/Win10.vmdk" (screenshot).
Oleg Tatarchuk
  • 101
  • 1
  • 3
5

In some cases first your need to Release, then Remove and Re-add via Virtual Media Manager

Stefan Georgiev
  • 119
  • 2
  • 4
4

I really appreciate the suggestions here. The Impaler's and Oleg's comments helped me to piece my solution together.

Use the VBoxManage CLI. There's a modifymedium command with a --setlocation option.

I suggest opening the VBox GUI (on VM VirtualBox Manager 6.0)
- select "Virtual Media Manager" (I used the File menu)
- select the "Information" button for the disk giving you this error
- copy the UUID
Note: I removed the controller from the "Storage" setting before the next step.
- open your command prompt and navigate to the location of the .vdi file
It's a good idea to type VBoxMange to see a list of options, but this is the command to run:

VBoxManage modifymedium [insert medium type here] [UUID] --setlocation [full path to .vdi file]

Finally, reattach the controller to any VM--preferably the one you'd like to fix.

C Marshall
  • 41
  • 2
3

1 - Open the files '.vbox' and '.vbox-prev' (if exist) files in any text editor and replace the first character of HardDisk uuid (take note to revert this change on step 6)

Example: nano /home/virtualbox/WindowsServer/WindowsServer.vbox

Change:

<HardDisks>
        <HardDisk uuid="{3ebaa9b6-8318-4b81-b853-8f30dd278bdc}" location="/home/virtualbox/WindowsServer/WindowsServer.vdi" format="VDI" type="Normal"/>

To:

<HardDisks>
        <HardDisk uuid="{2ebaa9b6-8318-4b81-b853-8f30dd278bdc}" location="/home/virtualbox/WindowsServer/WindowsServer.vdi" format="VDI" type="Normal"/>

2 - Reboot machine

4 - Stop Virtual Machine (if started)

5 - On terminal:

su vbox
cd /home/virtualbox/WindowsServer/
VBoxManage modifyhd WindowsServer.vdi --resize SIZE
exit
exit

change SIZE for a number in Megabytes, example 80000 (80GB)

6 - Open again the files '.vbox' and '.vbox-prev' (if exist) files in any text editor and replace the first character of HardDisk uuid whith the original value

Example: nano /home/virtualbox/WindowsServer/WindowsServer.vbox

Change:

<HardDisks>
        <HardDisk uuid="{2ebaa9b6-8318-4b81-b853-8f30dd278bdc}" location="/home/virtualbox/WindowsServer/WindowsServer.vdi" format="VDI" type="Normal"/>

To:

<HardDisks>
        <HardDisk uuid="{3ebaa9b6-8318-4b81-b853-8f30dd278bdc}" location="/home/virtualbox/WindowsServer/WindowsServer.vdi" format="VDI" type="Normal"/>

7 - Reboot machine

Lucas Catani
  • 37
  • 1
  • 11
2

The solution that worked for me is as follows:

  1. Make sure VirtualBox Manager is not running.
  2. Back up the files ~\.VirtualBox\VirtualBox.xml and ~\.VirtualBox\VirtualBox.xml-prev.
  3. Edit these files to modify the <HardDisks>...</HardDisks> section to remove the duplicate entry of <HardDisk />.
  4. Now run VirtualBox Manager.

Example:

  <HardDisks>
    <HardDisk uuid="{38f266bd-0959-4caf-a0de-27ac9d52e3663}" location="~/VirtualBox VMs/VM1/box-disk001.vmdk" format="VMDK" type="Normal"/>
    <HardDisk uuid="{a6708d79-7393-4d96-89da-2539f75c5465e}" location="~/VirtualBox VMs/VM2/box-disk001.vmdk" format="VMDK" type="Normal"/>
    <HardDisk uuid="{bdce5d4e-9a1c-4f57-acfd-e2acfc8920552}" location="~/VirtualBox VMs/VM2/box-disk001.vmdk" format="VMDK" type="Normal"/>
  </HardDisks>

Note in the above fragment that the last two entries refer to the same VM but have different uuid's. One of them is invalid and should be removed. Which one is invalid can be found out by hit and trial -- first remove the second entry and try; if it doesn't work, remove the third entry.

Sanjeev Sachdev
  • 1,241
  • 1
  • 15
  • 23
  • This is the solution that worked for me, after a windows update and reboot left my VB broken, unable to start with the error that a hard drive UUID already exists. On windows the two files are located in C:\Users\user\.VirtualBox. I made a copy of each before editing and removed the UUID it said already exists, and was than able to start VB. – Chris Jenks Sep 24 '21 at 12:40
0

After struggling for many days finally found a solution that works perfectly.

Mac OS open ~/Library folder (in your home directory) and delete (move to a safe place) the VirtulBox folder. This will remove all configurations and you can start the virtual box again!

Others look for .virtualbox folder in your home directory. Remove it and open VirtualBox should solve your issue.

Cheers!!

Lasithds
  • 2,161
  • 25
  • 39
  • I followed this solution on my Virtualbox VMs and I lost all my VMs instances. Don't follow this answer it could be dangerous. – Hasanuzzaman Sattar Mar 08 '22 at 09:58
  • @HasanuzzamanSattar It worked back then but I have no clue if it's the case now. Did you permenently delete it? Move is a safe option before deleting!! – Lasithds Mar 08 '22 at 14:37
0

Following the answer from @syed-nasir-abbas. On a Virtualbox (Version 7.0) GUI, Click on Tools-> Media or go to file -> Tools -> Virtual Media Manager. Mark the hard Disks highlightend with a Warning Triangle Icon and then remove them. With that you are ready to go.