restoring a VM from the .vdi file

Discussions related to using VirtualBox on Windows hosts.
Post Reply
LMHmedchem
Posts: 78
Joined: 7. Feb 2013, 19:35

restoring a VM from the .vdi file

Post by LMHmedchem »

Hello,

I had to restore my OS from an image a few days ago and I keep forgetting that vbox defaults to keeping the VM profiles in a location on the C: drive (which I overwrote with the restore). I have never understood why applications install by writing files all over the place instead of just keeping everything under the install directory, which was intentionally placed off of the C: drive.

There is a VM that I created since the image was written that I need to get back. The VMs are stored on another drive, so the .vdi file is still there along with the snapshots directory. I need to restore the .vbox file to the profiles directory in order to access the VM.

Can someone point me to instructions for doing this? I have the snapshots but there is nothing in them that I need. I have tried moving the profile directory in the past but just ended up breaking everything.

This is vbox 5.1.14 r112924 on a Windows XP 32-bit host.

LMHmedchem
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: restoring a VM from the .vdi file

Post by scottgus1 »

LMHmedchem wrote:I have never understood why applications install by writing files all over the place instead of just keeping everything under the install directory, which was intentionally placed off of the C: drive.
If the guests get put in the install directory, and you don't place Virtualbox off the C: drive, then the guests go in Virtualbox's install directory, defaulting to C:\Program Files\Oracle\Virtualbox, which requires Admin rights to write in. So you need to run Virtualbox as Administrator every time (a round of UAC prompts for the house, please) to access the Program-Files-based guests, which enables everything Virtualbox does to have Admin rights, and since Virtualbox punches all sorts of holes, (legitimate holes, true, but holes nonetheless) in the security model to allow more than one operating system to access the hardware, now you have all the guests automatically running with Admin rights on your host, and there's a cluster-cuss of epic proportions just waiting for the first malware or accidental-malicious pebcak to come along.

So having the guests in the install folder isn't a workable idea. Another reason to spread the guests around is when you have lots of guests that all need to run, they might need multiple drives to run on. More than two modern OS's will swamp the I/O on a platter drive. However, you can pick what folder you want your new guests in, see the main Virtualbox window, File menu, Preferences, General, Default Machine Folder. All new guests will go to the folder you set. Old guests will stay where they are. They can be moved, see Moving a VM. If your guest disk file(s) are in a different folder than the guest's .vbox file, then the paths to the disk files are absolute and need to be either reproduced or manually edited if you're moving the guest to a new host PC.

The most optimum setup for a guest is the guest .vbox file, guest disk file, Logs and Snapshots folders together inside one folder, on any host disk, even if it is not the C drive. Then a backup consists of a simple file-copy of the whole guest folder. 'FC' file-compare or hashes can be used to confirm backup integrity.

You post that you have the guest vdi and some snapshot files, but not the .vbox file. Or you have an old .vbox file you can restore?

Please post the absolute paths to each file that you still have that makes up this guest.Also post exactly what OS the guest was running, how many cores it had, the memory, 2D or 3D acceleration, USB, serial, etc. Let's see if we can put it all back together.
LMHmedchem
Posts: 78
Joined: 7. Feb 2013, 19:35

Re: restoring a VM from the .vdi file

Post by LMHmedchem »

I guess I was spectacularly unclear about how I had things set up. Most especially, I forget to mention that my virtualbox installation is not on the C: drive. My intent was to keep everything off of the C: drive as I usually do for many of the reasons that you mention.

The issue was that even though virtualbox was installed to,

H:\Windows_VM\vBox_install

there were still important virtualbox data installed in,

C:\Documents and Settings\user_name\.VirtualBox\
C:\Documents and Settings\user_name\VirtualBox VMs\

The profile directories are in VirtualBox VMs\. I never use spaces in file or directory names, so I don't think this is a directory I set up. I believe that I could have moved the default location for some of this if I had paid better attention when I first set this up but subsequent efforts to move this data have not been helpful. I was surprised that even though I installed virtualbox to the H: drive, there were still important configuration information installed to the C: drive. This is a practice I don't particularly like. I like to keep things separate. The H: drive is an SSD I set up just for VMs.

For the VM I am trying to recover, I have the following files,

H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64\vCentOS-7.7.1908_x86_64.vdi
H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64\snapshots\{bc536b4d-b841-4afc-ab97-f16f20755d3f}.vdi
H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64\snapshots\2019-10-10T01-06-05-812500000Z.sav
H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64\snapshots\2019-10-10T22-50-11-421875000Z.sav

There is no .vbox file since that was in the directory that I overwrote. If there was one, it would be called,

C:\Documents and Settings\user_name\VirtualBox VMs\vCentOS-7.7.1908_x86_64\vCentOS-7.7.1908_x86_64.vbox

The guest OS was CentOS-7.7.1908 x86_64, so the interface was set to Linux/RedHat (64-bit). I am not entirely sure about all of the details. My guess is that it had 2 cores, 1.5GB RAM, no 2D or 3D acceleration, bridged network adapter, no serial ports, and USB 2.0. There is also supposed to be a shared folder G:\shared_data.

I have .vbox files for several other VMs, but not the one I am trying to restore. Can I copy and manually edit one of the other .vbox files to replace the missing one?

Thanks for the help and please let me know if I have forgotten something,

LMHmedchem
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: restoring a VM from the .vdi file

Post by scottgus1 »

LMHmedchem wrote:there were still important virtualbox data installed in,

C:\Documents and Settings\user_name\.VirtualBox\
C:\Documents and Settings\user_name\VirtualBox VMs\

The profile directories are in VirtualBox VMs\. I never use spaces in file or directory names, so I don't think this is a directory I set up
These are default directories made by Virtualbox when it is first started. Virtualbox is a 'userland' program, and if you log on in a different account you can have a different list of guests and different global Virtualbox settings. The manual tells all about these folders and files, look at section 10 in your manual. The .Virtualbox folder can be moved to a different place with the %VBOX_USER_HOME% environment variable, and Virtualbox VMs can be reset to another folder for new guests via the Default Machine Folder setting mentioned above.

FWIW forum advice is to let Virtualbox install in the default C:\Program Files location, and if desired, point to folders on other locations besides the defaults for Virtualbox's .Virtualbox and default guest folder. If your MSI installation database ever goes south (and it does) you might have to remember where you installed stuff instead of the installers remembering for you. But that's a subject for another day.

Here's how I would fix this:

1. Temporarily change the name of the 'H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64' to 'H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64temp'.

2.Set the Default Machine Folder to 'H:\Windows_VM\virtual_machines'

3. Make a new CentOS guest called 'vCentOS-7.7.1908_x86_64' (this is why we needed to temporarily rename the old guest folder, so Virtualbox can make a new guest with the same name as the old guest.) Make a new drive to go with this new guest. This new drive will not be used, it is just for telling which disk controller port the old guest disk was likely attached to. You should now have a new folder 'H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64' with a 'vCentOS-7.7.1908_x86_64.vbox' file and a small vdi file in it.

4. Set as many of the new CentOS's guest settings as you can to the old guest's settings you remember.

5. Decide if you want the data in the snapshot or not. If yes, go to 5a. If no go to 6.

5a. Download Mpack's CloneVDI. Follow the CloneVDI instructions to merge the snapshot vdi and the base vdi. Keep the old disk UUID. This will make a clone of the disk file with all the data pushed into the clone. We will attach the clone disk file to the new guest. Keeping the old disk UUID should keep the grub loader happy, as I have heard that grub uses UUIDs to figure out which disk is which. Change the name of the clone to the final name you want the guest's disk to be called. The new guest will not have a snapshot.

6. In the guest Storage settings, note which disk controller and port number or master/slave setting the guest disk is on. Release the new guest disk. Go to the File menu, Virtual Media Manager, and release/remove the new guest disk.

7. Move either the old base disk vdi file or the clone, whichever you chose, to the new guest folder with the .vbox file in it. Only move one or the other, not both.

8. In the guest's Storage settings, attach your old base vdi file or clone in the folder with the .vbox file to the same slot/port the new guest disk was on.

9. Now your guest is in the standard format and should be ready to start.
Last edited by scottgus1 on 9. Jan 2020, 19:52, edited 1 time in total.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: restoring a VM from the .vdi file

Post by mpack »

Like it or not, modern operating systems distinguish between code and data areas of the filesystem. The former is heavily protected and prone to being deleted and replaced whenever an update occurs. The latter are files that should be backed up, or mirrored in cloud space, and the host OS will generally not deliberately delete.

The 1990's are way behind us!
LMHmedchem
Posts: 78
Joined: 7. Feb 2013, 19:35

Re: restoring a VM from the .vdi file

Post by LMHmedchem »

Thanks you for the instructions. I have a question about the following,
scottgus1 wrote:6. Move either the old base disk vdi file or the clone, whichever you chose, to the new guest folder with the .vbox file in it. Only move one or the other, not both.
This would result in having two files in the guest folder with the name vCentOS-7.7.1908_x86_64.vdi. Do I delete the small .vdi file the was created with the new VM? Do I rename the small .vdi file to something else? Do I rename the original .vdi file?

Thanks

LMHmedchem
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: restoring a VM from the .vdi file

Post by scottgus1 »

LMHmedchem wrote:Do I delete the small .vdi file the was created with the new VM?
This one. Delete the little disk file. The only vdi in the guest folder would be the original base disk or the clone.
LMHmedchem
Posts: 78
Joined: 7. Feb 2013, 19:35

Re: restoring a VM from the .vdi file

Post by LMHmedchem »

I have followed the steps.

In the storage settings under the SATA controler there is the yellow triangle warning indicator that the UUID of the attached disk (the old one I am trying to restore) does not match the UUID in the storage registry.

I did the following,

Code: Select all

delete new small .vdi file
dropped in the old .vdi file
open "storage" for the VM in the vbox manager
remove the new small .vdi file storage attachment
add the old .vdi file as an attachment to the same controller
click ok
When I try to start the VM, it fails to start with the message,

Code: Select all

Result Code: E_FAIL (0x80004005)
Component: MediumWrap
Interface: IMedium {4afe423b-43e0-e9d0-82e8-ceb307940dda}

UUID {e5fa2ba8-37c5-45e8-8f56-2b639a9710fb} of the medium
'H:\Windows_VM\virtual_machines\vCentOS-7.7.1908_x86_64\vCentOS-7.7.1908_x86_64.vdi'
does not match the value {1af1cdbb-891a-48e7-986a-81faaacf1b36}
stored in the media registry ('C:\Documents and Settings\user_name\.VirtualBox\VirtualBox.xml').
Did I not make the switch incorrectly?

Can I fix this by closing virtualbox and manually editing the entry in .VirtualBox\VirtualBox.xml to switch out the UUID of the new .vdi file for the UUID of the old file since I have the values for both?

LMHmedchem
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: restoring a VM from the .vdi file

Post by scottgus1 »

I think I missed something, sorry.

When you remove the small drive from the guest, you also need to go into the File menu, Virtual Media Manager and release/remove the small drive from the Media Manager. For safety's sake. move the original/clone disk out of the guest folder, first, before releasing/removing. There's a Delete button along the way and that's a permanent Delete. After the release/remove, move the original/clone back in. You might need to do the attach again.

I updated the list, hope I didn't mess anything up too much.
LMHmedchem
Posts: 78
Joined: 7. Feb 2013, 19:35

Re: restoring a VM from the .vdi file

Post by LMHmedchem »

scottgus1 wrote:I updated the list, hope I didn't mess anything up too much.
I always work on copies of files, so there is not much chance of a mistake that cannot be recovered.
scottgus1 wrote:When you remove the small drive from the guest, you also need to go into the File menu, Virtual Media Manager and release/remove the small drive from the Media Manager. For safety's sake. move the original/clone disk out of the guest folder, first, before releasing/removing. There's a Delete button along the way and that's a permanent Delete. After the release/remove, move the original/clone back in. You might need to do the attach again.
This still does not fix the issue. I still get the same error. I think the issue is that the old .vdi drive and the new .vdi drive have exactly the same name and so vbox finds the wrong UUID for the old file.

I just changed the name of the old .vdi file and followed the same procedure and everything works fine.

I think I would have been able to manually edit the VirtualBox.xml with the correct UUID but since it is now working, I will not mess with it.

Thanks again for the help.

LMHmedchem
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: restoring a VM from the .vdi file

Post by scottgus1 »

LMHmedchem wrote:everything works fine.
Great news! Glad you're up and running.

The UUID thing has gotten in the way a few times, glad you found a way around it. I'll try to remember the change-the-name thing next time this comes up.

Editing the Virtualbox.XML probably would have worked, too, except that all Virtualbox processes, windows, and services need to be off, or the edits would get overwritten. Just means to wait a minute then make the change.
Post Reply