Accidental deletion of vmdk and subsequent restoration

Discussions related to using VirtualBox on Linux hosts.
Post Reply
leomar85
Posts: 5
Joined: 10. Nov 2022, 10:58

Accidental deletion of vmdk and subsequent restoration

Post by leomar85 »

Hello guys, thanks for your help in advance.

I have a Windows VM running on Debian Host. For some reason (stupidity mostly) we accidentally delete the vmdk disk file of this VM. This VMDK also have Snapshots that we keep.
Now, we have a backup of that VMDK disk that we took a moments ago before deleting it. All we do is just to put our backup vmdk in the correct place, but VirtualBox complains about this:

Code: Select all

Failed to open a session for the virtual machine servidor.
UUID {c852c1b9-0732-4d85-99c3-d70ec749fb62} of the medium '/mnt/virtualbox/servidor/servidor.XX.local-0.vmdk' does not match the value {65b5340c-608e-4c15-b606-2290668e5190} stored in the media registry ('/root/.config/VirtualBox/VirtualBox.xml').

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: MediumWrap
Interface: IMedium {ad47ad09-787b-44ab-b343-a082a3f2dfb1}
We already try to generate new UUID with: VBoxManage internalcommands sethduuid servidor.XX.local-0.vmdk, and we have the new UUID. We try to put that UUID in "servidor.vbox" file replacing the old UUID (With virtualbox closed), but then when we open Virtualbox again, the VM turns Inaccessible with the error:
"A differencing image of snapshot {UUID] could not be found. Cloud not find an open hard disk with {OLD_UUID}
Result Code: NS_ERROR_FAILURE
Component: SnapshotMachine

Any clues?.

Again, thanks so much for your help.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accidental deletion of vmdk and subsequent restoration

Post by mpack »

That error message says that you didn't make a backup, you made a clone, a rather different animal. A clone is a different PC with the same contents on the disk. For snapshot (and some software activation and boot) purposes that is not good enough. To make a real backup you should simply copy the entire VM folder to secondary storage using a host file copy command.

If hacks are possible then you are on the right track with sethduuid. If you examine the snapshot chain using CloneVDI you can confirm that you have the links correctly configured, because at the moment that can't be the case.
leomar85
Posts: 5
Joined: 10. Nov 2022, 10:58

Re: Accidental deletion of vmdk and subsequent restoration

Post by leomar85 »

Hello mpack, thanks for your answer, We are very worried about this.

Actually all we do is to do a qemu-img convert in order to convert from vmdk to qcow2 to migrate to other virtualization host. But, for accident, we delete the originals vmdk files, so we run again the convertor to convert from qcow2 to vmdk again. I think in this context is that the disk losts his UUID.
Now, I already set a new UUID to the disk, the question is, how can I tell VirtualBox what the new UUID is?.
I already try to replace the disk UUID in "servidor.vbox" but it doesn't work.
If i create a new machine and attach the vmdk, its working fine, but of couse with loss of data that is saved in snapshots.

Please tell me if i didn't explain myself well, I don't speak to much english.

EDIT: maybe, another option, is to set the correct UUID to the disk, i mean, assign to the disk the UUID that virtualbox is waiting for.
mpack wrote:That error message says that you didn't make a backup, you made a clone, a rather different animal. A clone is a different PC with the same contents on the disk. For snapshot (and some software activation and boot) purposes that is not good enough. To make a real backup you should simply copy the entire VM folder to secondary storage using a host file copy command.

If hacks are possible then you are on the right track with sethduuid. If you examine the snapshot chain using CloneVDI you can confirm that you have the links correctly configured, because at the moment that can't be the case.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accidental deletion of vmdk and subsequent restoration

Post by mpack »

I don't think it's practical for you to use a new UUID for the main disk, since that UUID is referenced by VirtualBox and by the next in line in the snapshot chain. And that's just the elements you've mentioned so far. Far more practical is to change the clone UUID using sethduuid, as I mentioned already.
leomar85
Posts: 5
Joined: 10. Nov 2022, 10:58

Re: Accidental deletion of vmdk and subsequent restoration

Post by leomar85 »

Thanks mpack,
The thing is, we do not have a clone of the main disk, we only have one main disk and that is the one who lost his UUID.

This is what we have in our vbox file:

Code: Select all

       <HardDisk uuid="{65b5340c-608e-4c15-b606-2290668e5190}" location="servidor.XX.local-0.vmdk" format="VMDK" type="Normal">

          <HardDisk uuid="{f7695b81-5117-498c-893b-401af8521359}" location="Snapshots/{f7695b81-5117-498c-893b-401af8521359}.vmdk" format="VMDK">

            <HardDisk uuid="{f4e83357-67cd-4e00-8af0-ce30e419ea2f}" location="Snapshots/{f4e83357-67cd-4e00-8af0-ce30e419ea2f}.vmdk" format="VMDK">

              <HardDisk uuid="{7535db7f-d91d-4d6d-a441-059f662554f5}" location="Snapshots/{7535db7f-d91d-4d6d-a441-059f662554f5}.vmdk" format="VMDK">

                <HardDisk uuid="{e4a4a92c-b3f1-4422-b479-484c950a039f}" location="Snapshots/{e4a4a92c-b3f1-4422-b479-484c950a039f}.vmdk" format="VMDK"/>

              </HardDisk>

The disk with UUID 65b5340c-608e-4c15-b606-2290668e5190 is our main disk file, the other ones are snapshots. The problem is, the main disk no longer has that UUID.

mpack wrote:I don't think it's practical for you to use a new UUID for the main disk, since that UUID is referenced by VirtualBox and by the next in line in the snapshot chain. And that's just the elements you've mentioned so far. Far more practical is to change the clone UUID using sethduuid, as I mentioned already.
Last edited by leomar85 on 10. Nov 2022, 12:30, edited 1 time in total.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accidental deletion of vmdk and subsequent restoration

Post by mpack »

As I already said above, your main disk IS a clone.
leomar85
Posts: 5
Joined: 10. Nov 2022, 10:58

Re: Accidental deletion of vmdk and subsequent restoration

Post by leomar85 »

mpack wrote:As I already said above, your main disk IS a clone.

OK, so I change the UUID of the clone disk, like this:

VBoxManage internalcommands sethduuid servidor.xx.local-0.vmdk

That will generate a new UUID, but virtualbox still trying to find a disk with the original UUID, how can I tell VirtualBox that the new UUID is the one we generate with sethduuid ?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accidental deletion of vmdk and subsequent restoration

Post by mpack »

I assumed you were aware of the complete "internalcommands" syntax, e.g. because you got VBoxManage to list it, but maybe not.

The command to change a VDI to a specific UUID is:

Code: Select all

VBoxManage internalcommands sethduuid <filename> <UUID>
leomar85
Posts: 5
Joined: 10. Nov 2022, 10:58

Re: Accidental deletion of vmdk and subsequent restoration

Post by leomar85 »

My god, all this time I was too close to solve this problem, and I never realize that I missing the part of actually set the UUID I want, I was just running:

VBoxManage internalcommands sethduuid filename.vmdk

And I never realize that I have to specify the UUID at the end of that command, so the sethduuid was generating a random uuid.

Thanks A LOT.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Accidental deletion of vmdk and subsequent restoration

Post by mpack »

You're welcome. Hopefully you'll have it working now.
Post Reply