21

I'm not sure what search term to use and skimming through the VirtualBox manual didn't help me either, so I ask my two questions here...

My setup is this: PC with dual boot into Windows 7 and a Debian operating system (both 64bit). I've created a virtual machine (Kubuntu, 64bit) under Windows and put it's VDI file on a SMB share of my NAS.
Then I created a VM under linux using the same settings for memory etc and assigned the existing VDI file to it. My idea was that I could use that virtual machine from Windows and Linux as well. (1) Is this generally something that should work without problems?

I noticed that snapshots get me into trouble because they appear to be not visible from the other operating system: The snapshots I took after installing the guest system are not visible under Linux. That's why I shut down the VM after usage and not save its state while it's running.

My current problem is this: I have used the VM under Windows first, then under Linux. Now it will only start on Linux. When trying this on Windows the guest OS detects some kind of hard disk error and fails to boot because it cannot mount its drive. Obviously the virtual hard disk won't fail so it must have something to do with me using it under Linux.
(2) How can I fix that?
Update: It also looks like any changes I made in the VM under Linux have been reset by trying to boot it under Windows. Looks like it's back to the latest snapshot. I'm confused...

Update

The answer to my first question can be found below. In short: It works, as long as you don't use snapshots.

The answer to my second question is this: Under Windows set the VM back to the latest snapshot and then discard the snapshot so it gets merged. There should be no snapshots left at the end. If you have multiple snapshots, discard the earliest ones first (Snapshot 1, then 2, 3, ...). I'm not sure what happens if you start at the end (.., 3, 2, 1).
This of course leads to some data loss since you revert all changes since the last snapshot. But at least the VM is usable again.

foraidt
  • 6,628

5 Answers5

12

Yes, you can share the VDI file as you're doing because you've only got one instance of VirtualBox accessing the VDI file at a time.

However, there is another caveat that you should take into consideration - you cannot share VDI files once you create a snapshot.

Even though this thread is a little old, it should give you a reasonable understanding of why you cannot share a VDI file once you've created a snapshot.

So, avoid snapshots and you should be able to share your VDI file between your Windows and Linux installations.

Convict
  • 734
7

To correct some of the miss information on this post.

  • You can share a single VDI (Virtual Disk Image) between multiple machines.
  • These machines can ALL be running at the same time, with divergent changes.
  • Also, they can all take advantage of Snapshotting.
  • Even after a snapshot has been taken, you can branch and spawn new machines from any point in a machines history.

I wrote a post a while back just for this...

http://blog.mrverrall.co.uk/2010/06/spawning-many-virtualbox-machines-from.html

Also see the previous post on "Cloning VMs with Multiple Snapshots in VirtualBox" Which would have got around the original posters main issue... i.e. moving a machine, snapshots and all to a new OS.

:)

mrverrall
  • 874
2

To amplify what Convict said, don't use snapshots, just close the VM and "Save state". That saves all changes back into the VDI file itself.

If you need to perform the equivalent of snapshotting, you can make an actual copy of the VDI file. Takes up some disk space of course, but disk is cheap.

CarlF
  • 8,872
0

Maybe you should try to go to "File"->"Preferences" and on "General", change the "Default Machine Folder" to your SMB share. Like that the snapshots are saved in the share and available to both OS. Not tested.

0

Just clarify one thing ... VirtualBox machines are not only the VDI files, VBOX files are as important as VDI ones.

I share a Virtual Machine (i do not use a server but it is the same concept) between two Operating Systems that run on physical hardware on the same computer (only one at a tiem).

I install VirtualBOX on Linux and make it to save VirtualBox.xml on another disk, that i use only for Virtual Machines.

I install VirtualBOX on Windows and make it to save VirtualBox.xml on another disk, that i use only for Virtual Machines.

I really make that using (Linux Symbolic Link to folder) & (Windows Junction).

The i create the virtual machine (no matter if on Linux or on Windows), it will be seen on both, since the base store of Virtual Machines is on the same disk, both Linux VirtualBOX & Windows VirtualBOX will read/write to the same place.

That way any change maded to the VBOX file, or snapshots, etc... done while physical computer runs Linux will be seen while physical computer runs Windows and vice-versa.

Sometimes i want not ALL virtual machines be identical (VirtualBOX list) on both physical systems ... sometimes i want them to have a different list of virtual machines ... for that i create one or more folders on that drive (i call them Host_Windows10, Host_Windows11, Host_LinuxUbuntu, Host_LinuxManjaro, etc... each one represents an operating system that runs on physical hardware on the same computer.

That way VirtualBox.xml is different for each operating system.

But i want the same virtual machine on more that one of them... so i place all files (and folders) of that virtual machime onto that disk on an specific folder, then i boot the computer with the first operating system where i want that machive to be and add it to the list... then i boot the other operating system where i also want that machive to be and add it to the list... so on as many i want.

After that, each operating system has its own ´VirtualBox.xml´ and inside them, some of them has the reference to the same Virtual Machine.

Think of this:

Linux has VirtualBox.xml on /MyDrive/Host_LinuxManjaro/ Windows has a differente VirtualBox.xml on D:\Host_Windows10`

/MyDrive and D:\ are the same root folder on the same drive.

Virtual Machine files & folders are stored on: If seen on Linux: /MyDrive/MyVirtualMachine/ If seen on Windows: D:\MyVirtualMachine\

Inside that folder is the VBOX file, all VDI/VHD/etc, Logs folder, Snapshot folder, etc... all the virtual machine is inside there (except the line that tells VirtualBox List that machine must appear on the list).

I edit the machine VBOX file to ensure there is no full path.

And that it, any change maded to the virtual machine (snapshoting, installing programs, etc) is done on a Route that is know by both VirtualBOX (Linux & Windows) that runs on the same hardware (boot Linux or boot Windows).

Beware both versions of VirtualBOX must be the same, if you update one do not forget to uptade the other prior to run the virtual machine.

It also works with ... running virtual machine, close it saving it state, reboot to other physical operating system and resume the virtual machine.

The key point here is where VirtualBOX saves what... not olny VDI is important... it is also important where VBOX files is and where is VirtualBox.xml file.

Tip: I normally make the changes to the VBOX of my virtual machines with Notepad++, not with the GUI of VirtualBox, that way i have much more fine control on what i change.

Extra: To all of thoose of you that want Inmutable machines to not loose changes on boot after a secure power off, inside the <HardDisk ...> section (inside the <MediaRegistry> section), it can be inside virtual machine VBOX file or inside VirtualBox.xml, ther is the text autoReset="true", just replace it with autoReset="false" or simply remove the parameter.

Tip (when autoReset is not true): If after define the machine (or after a reset is done) you can copy (to another sub-folder of the parent folder) the file in /Snapshots/ folder (small size), then when you want to do a reset you copy back the small file and all changes get lost... tip: do not put such copied files on any folder of the full path of the file been copied, for example if file is on /A/B/S/here do not put it on /A nor /A/B, nor /A/B/S etc... put it for example on /A/B/BackUPs ... VirtualBox and some tools on some operations looks for a file (any name) on the path going up to parente till they find a file with the UUID searched, changing the name does not help.

Extra: On <AttachedDevice ...> section for SSD/NVME it can be usefull to have nonrotational="true".

Extra: On <AttachedDevice ...> section for making the disk seen as removable it can be usefull to have hotpluggable="false".

Extra: To be able to connect a disk while machine is running, it is vital that machine has more ports defined that ports in use, on the <StorageController ...> section the parameter PortCount="..."; if no free ports VirtualBox will not allow to add on the fly another disk.

Extra: You can rename files inside Snapshots folder if you also change the reference inside the VBOX files (or VirtualBox.xml) wherever the file is registered inside <MediaRegistry> section.

Do not panic, all changes to VirtualBox.xml and / or VOXs files do them with Notepad (Notepad++) a plain text editor but with VirtualBox fully closed (no machine running, no GUI of VirtualBOX, etc); make a backUP of them before changing them, then do the changes, run VirtualBOX and see the reesults.

Some modifications must be done manualy (or at least i still not know how to do them).

Please ensure all paths inside that files that point to disk images are relative, not full paths; path delimiter is not important / or \ will work, also mixing them on the same route seems to work well.

Please ensure if you have physical Windows and physical Linux that VirtualBox.xml is saved on different folders Host_Windows10, Host_Windows11, Host_LinuxManjaro, etc... if is a pain to deal having it in common with multiple different (Linux/Windows) physical operating systems.

Hope all this info helps... sometimes manual edit VirtualBox.xml and *.vbox files is vital to get what one wants.

And sorry to make it so looooooong ... too much to teach for a single post, this VirtualBOX internal lines (on text files) need a full tutorial by them self, more when wanted 'special' things to happen... i only want to teach ... and to loudly say ... why on the hell VirtualBOX GUI lacks a lot of what can be done editing by hand the text files? such as Save/NotSave state on boot for inmutable virtual disks; allow doing inmutable the diferencing virtual disk of an inmutable disk (aka more than one level of changes) without needing snapshoting, aka inmutable chain, inmutable branches, etc... all that must be done by hand and is far long away of 'normal' users and totally undocumented.

Laura
  • 1