Somehow my Vagrant project has disassociated itself from its VirtualBox VM, so that when I vagrant up
Vagrant will import the base-box and create a new virtual machine.
Is there a way to re-associate the Vagrant project with the existing VM? How does Vagrant internally associate a Vagrantfile with a VirtualBox VM directory?
WARNING: The solution below works for Vagrant 1.0.x but not Vagrant 1.1+.
Vagrant uses the ".vagrant" file in the same directory as your "Vagrantfile" to track the UUID of your VM. This file will not exist if a VM does not exist. The format of the file is JSON. It looks like this if a single VM exists:
{
"active":{
"default":"02f8b71c-75c6-4f33-a161-0f46a0665ab6"
}
}
default
is the name of the default virtual machine (if you're not using multi-VM setups).
If your VM has somehow become disassociated, what you can do is do VBoxManage list vms
which will list every VM that VirtualBox knows about by its name and UUID. Then manually create a .vagrant
file in the same directory as your Vagrantfile
and fill in the contents properly.
Run vagrant status
to ensure that Vagrant picked up the proper changes.
Note: This is not officially supported by Vagrant and Vagrant may change the format of .vagrant
at any time. But this is valid as of Vagrant 0.9.7 and will be valid for Vagrant 1.0.