Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch Vagrant virtual machine?

I was working on a virtual machine that I set up with Vagrant when I realized that I needed to access it through port 8000 to test a web interface so I did vagrant halt in order to modify the Vagrantfile and forward port 8000 then I saved the file and did vagrant up to boot back up that machine and to my surprise instead Vagrant built a new machine from scratch. Now when I look inside the folder named 'VirtualBox VMs' I can see two VMs with the same name + a long number that differs. I believe one is the first machine that I want to boot with all my packages and settings while the other is the new empty one. How can I switch back to the first one so when I do vagrant up it actually boots that one? And optionally how do I get rid of the new, empty one?

like image 857
Bastian Avatar asked Sep 30 '13 22:09

Bastian


1 Answers

My understanding is each Vagrant project directory (home of the Vagrantfile) is associates with a Virtual Machine managed by vagrant in VirtualBox (default provider). Normally in the pattern of "baseboxname_id".

Your problem could be caused by bugs in old Vagrant versions. Please make sure you are running the latest Vagrant 1.3.3 + VirtualBox 4.2.18. OR, possibly mixed up multiple Vagrantfile (not likely to be the case based on your description).

Figuring out the ID of the vagrant box

  1. Change directory to where the Vagrantfile resides
  2. View the contents of => /path/to/Vagrantfile/.vagrant/.vagrant/machines/default/virtualbox/id, you'll get an id like a90df491-4c25-4a07-be1a-be137908058c.

    NOTE: This is the uuid of the Virtual Machine associated with the Vagrantfile managed by VirtulBox.

Getting rid of the new/empty VM

Now that you know the uuid, you can unregister the VM and delete it => VBoxManage unregistervm <uuid> --delete.

Re-associate the Vagrantfile with the 1st VM

  1. Get the list of VM names and uuids managed by VirtualBox
  2. Replace the id with the uuid of the 1st VM in /path/to/Vagrantfile/.vagrant/.vagrant/machines/default/virtualbox/id
  3. Bring the 1st VM up => vagrant up
  4. Done!
like image 51
Terry Wang Avatar answered Oct 08 '22 21:10

Terry Wang