My other car is a cadr
My other car is a cadr

Reputation: 1431

How do share the same VM between Windows and Linux when using Vagrant?

I have two hosts, one Windows and one Linux, both with Vagrant and VMware Workstation installed and everything works perfectly fine in their own environment. However, when I create an guest VM in Linux and I do vagrant up in Windows, then Vagrant will delete(!) everything in the .vagrant directory and attempt to fetch the base image. The same thing happens if I do a vagrant init and vagrant up in Windows and then a vagrant up in Linux. How do I prevent this from happening? Is there anyway to share the same VMs between Windows and Linux using Vagrant?

I'm running Windows 7, Ubuntu 14.04, Vagrant 1.6.5, VMware Workstation 10.0.3. This problem occurs for all guest operating systems.

Upvotes: 3

Views: 1055

Answers (2)

Jaime Hablutzel
Jaime Hablutzel

Reputation: 6342

The following has been tested using the VirtualBox Vagrant provider with Windows 10 and Ubuntu 18.04 in a dual boot setup with a shared NTFS drive where D:\ in Windows is accesible as /mnt/d/ in Linux.

First (but not indispensable if I'm not wrong), set the VAGRANT_HOME environment variable in both Windows and Linux to the same place, e.g.:

  • Windows, D:\.vagrant.d
  • Linux, /mnt/d/.vagrant.d

Then create a new machine from one of the OSes, from Linux in the following example:

$ cd /mnt/d/vagrant_machines/machine1
$ vagrant init
$ vagrant up

Then boot in Windows and first backup D:\vagrant_machines\machine1\.vagrant just in case case its contents get accidentally deleted.

Then register from VirtualBox the existing VM, e.g. D:\virtualbox_machines\machine1_default_1587262647987_91775\machine1_default_1587262647987_91775.vbox.

Then run the following:

>vagrant.exe status
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.

The UID used to create the VM was: 1000
Your UID is: 0

And update D:\vagrant_machines\machine1\.vagrant\machines\default\virtualbox\creator_uid to your current UID (0 in this example).

Then start the machine:

>vagrant status
>vagrant up

Finally, note that you will require to update the creator_uid each time that you switch OSes, which you might want to automate.

Upvotes: 1

tmatilai
tmatilai

Reputation: 4176

The content of the .vagrant directory can be OS specific, and the internal state of VMware for sure.

I don't think there is easy way to share the same VM instance between the two hosts. The Vagrant way is to provision the VM so you only share the base box and then each user/OS spins up their own instance.

Another option would be to use vagrant package and vagrant box add to transfer the configured box, but that doesn't work with the VMware provider.

Yet another approach would be to use a cloud provider like AWS or Digital Ocean and just ssh into the box. Or maybe even use the vagrant-managed-servers plugin. Your question didn't hint what you use the Vagrant VM for, so it's difficult to tell what would be the best solution.

Upvotes: 2

Related Questions