Visual people: Watch this screencast
Anti-video readers: Keep reading.
This morning I ran into an issue with my Vagrant upgrade (I went from 1.0.7 to 1.2.1) that took me a few hours to figure out. I did, however, solve it in the end and thought it’d be useful to share how. It’s an easy fix.
First, the error I was getting was:
The box ‘boxname’ could not be found.
(where boxname was the actual name of the box, e.g. precise32)
The box did show up when I ran vagrant box list, so I knew that it should have been working.
After trying an assortment of things, including converting my Vagrantfile configuration to the version 2 format and trying to use the box in a fresh directory and with a fresh Vagrantfile, I decided to try re-adding the precise32 box that Vagrant provides. I did that, and then typed vagrant init precise32d. (I had called it precise32d.) This worked fine. I deduced that there must have been some change in the box itself. So I fired up DiffMerge.
DiffMerge told me that there weren’t any files it could compare. This, I discovered, was because everything in the new box I had downloaded was under a virtualbox directory. A-ha! I was on to something. I looked in that directory and saw these files:
Vagrantfile box.ovf box-disk1.vmdk metadata.json
Wait, metadata.json? That wasn’t in my existing box’s folder at all! What could be in there, I wondered?
$ cat virtualbox/metadata.json
Ah. So it’s relying on this to figure out the provider, since Vagrant 1.1+ has the concept of providers other than VirtualBox. That explained a lot. The simplest fix is just as you may suppose:
To eliminate the potential for human error, we’ll use an existing metadata.json file. Run:
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
Wait for it to download and be added.
$ cd ~/.vagrant.d/boxes/yourbox
$ mkdir virtualbox
$ mv * virtualbox (or you can specify all the filenames manually)
$ cp ../precise32d/virtualbox/metadata.json virtualbox
You should now be able to vagrant up any projects that are relying on your pre-upgrade box. And they should work just as well as they did before!
- I assume your boxes are VirtualBox VMs. If they’re not, then you probably wouldn’t have this issue anyway.
- Don’t type the $ marks. That’s just to show you type the command in a terminal.