Fixing a Disassociated Vagrant VM
We recently switched over to using git and vagrant at work and during one of my trainings with a new programmer his computer crashed. After his computer rebooted and he got everything back up and running when he ran vagrant up
it started recreating his VM. It hit a point where it tried to rename the newly created VM and reported an error (I'm actually amazed that vagrant doesn't check for this initially) when it found one already existed with the same name. We could have just deleted the VM and started over but he had already started to enter test data that we didn't want to loose.
In order to fix this we found out a couple things.
-
Every VM in VirtualBox has a unique ID. If you open the .vbox file for a VM there will be a section that looks like this:
<Machine uuid="{2489fd71-90eb-4142-848d-d06dab9bfa9b}"
The part after the
uuid=
is the ID. -
Vagrant associates your project with your VM in the
.vagrant/machines/default/virtualbox/id
file (based off the location of yourVagrantfile
). This file contains the VM's unique ID. - If the UID in the vagrant id file doesn't match the UID in the .vbox file Vagrant won't be able to operate on your VM. Duh! Right?
- Copying the UID from the .vbox file to the id file fixs the problem.
Ultimately, I'm happy that it was all simple text files so we didn't have to spend the time exporting his test data and waiting while a new VM was created.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows