Categories
Blog Tutorials

Fix for Vagrant not detecting existing VM

Recently, I had to restart my Vagrant to apply some changes. When I went to vagrant  up, a scary thing happened: vagrant started to download the entire box over again. Vagrant wasn’t detecting my existing box! Not only is this inconvenient if you have specific configurations you made to your Vagrant after the initial install, but it could be detrimental if you use Vagrant to hold your database and didn’t have a backup handy. Luckily, I was able to point Vagrant back in the right direction.

Problem Solving

I looked into my other Vagrants and saw that they had a number of files under:

.vagrant > machines > default > virtualbox > id

that my current box was missing all these files. I’m not sure how they got deleted, but they definitely weren’t there. I opened up the files in Sublime to see what was in there.

The Solution

To find out the ID of currently existing VMs, run the following in terminal:

$ VBoxManage list vms

You should see a list of all the VMs on your system. Find the one that matches the Vagrant you are trying to repair, and copy the ID from it. They will show in the following format: “name_of_vagrant” {id_of_vagrant_here} Now, create a new file called ‘id’ in your Vagrant directory under:

.vagrant > machines > default > virtualbox > id

and paste the ID of your VM into there. Finally, go back to terminal, run your vagrant up command and you should be good to go!

9 replies on “Fix for Vagrant not detecting existing VM”

Thanks Zack you saved me from recreating a box from scratch basically.

What happened in my case is that my company decided to install some software on my Mac and I would get the following error when doing vagrant up
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: 896703041
Your UID is: 1194079782

So what I did is I deleted .vagrant folder and then recreated it (vagrant up && vagrant halt). Then I just followed your solution section. I replaced the value in the id file with the ID that I got from running VBoxManage list vms

Hey Dmitry,

That’s awesome! I’m glad you found it useful and it saved you from having to redo your environment completely 🙂

Hi Zach,

Thanks for the article. I am experiencing the exact same issue, but am having an issue. Per your instructions, I opened the file .vagrant > machines > default > virtualbox > id, and it contained a single ID number. But when I run vboxmanage list vms, it returns the exact same ID. Am I misunderstanding something about your instructions?

I should also note:

* All the files for my current box still exist, in the same directory–except my nginx.conf file, which I cannot locate.
* When I navigate to the URL of my current box, instead of loading my WordPress site as usual, it prompts me to begin the process of installing a fresh version of WordPress.
* In addition to my WordPress files located on my local machine, I also have a full backup located in my online GitHub repository. And I have a backup of my WordPress database on my web server.

Any thoughts?

Hey C,

It sounds like the issue is with your local environment’s connected database not having WordPress installed yet. Since you are seeing the WordPress install screen, that should indicate that your Vagrant is working as expected.

Thanks. It was an issue where my WordPress database was removed (or corrupted?). After making backups, my solution was to briefly walk through that setup-new-WordPress process. My wp-content directory was preserved during that process, meaning my theme and plugins were still present in that new WordPress installation. I then used my usual database migration plugin (Migrate DB) to pull my WordPress database from my web server to my local WordPress install (since they were identical).

Leave a Reply

Your email address will not be published. Required fields are marked *