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.

  1. 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.

  2. Vagrant associates your project with your VM in the .vagrant/machines/default/virtualbox/id file (based off the location of your Vagrantfile). This file contains the VM's unique ID.

  3. 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?
  4. 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.