How to copy Vagrant boxes (or duplicate them)
Copy vagrant box & compress it
Making a real 1:1 copy of a Vagrant box is really easy ! Simply turn off the box (if she is currently running – yes, for me a Vagrant box is female!) with
vagrant halt
and create a package.box file (default name) in the same folder with
vagrant package
That’s it. The package.box contains the full virtual machine, compressed. You can put this file whereever you want now.
Create a new VM from the new box file (quick method)
Now create a new folder somewhere (for your new project that uses the box) and initialize a new default Vagrantfile via
vagrant init
Open the file, and edit this: Rename the default boxname (which might be precise64) to something new, like “my-zend-framework-box“.
config.vm.box = "my-zend-framework-box"
Uncomment and edit the default box location from
# config.vm.box_url = "http://domain.com/path/to/above.box"
to the filepath of your package.box. Windows users need to write the path this way:
config.vm.box_url = "file:///d:/folder/package.box"
Then uncomment and change the default IP to something you want, I recommend increasing the last number of the IP.
config.vm.network :private_network, ip: "192.168.33.101"
Run your Vagrant box with:
vagrant up
Create a new VM from the new box file (long method)
If you want to add the box to your vagrant box list (to use the box by it’s name, not by giving the file location) do it like this:
vagrant package
Add the box to Virtualbox (chose a box name for name-of-this-box):
vagrant box add name-of-this-box package.box virtualbox
Now you can create virtual machines from this box by simply giving the name of the box in the Vagrantfile, like
config.vm.box = "name-of-my-box"
A config.vm.box_url is not necessary anymore.
Be aware of synced folder issues !
There’s a weird issue going on with the synced folder: When packing a box and creating a new virtual machine from it, you might loose the content of the synced folder in the guest system. Obviously the fresh and empty synced folder on the host deletes the synced folder’s content in the guest. I haven’t tried yet, but maybe turning off the synced folder before packing is a solution.