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
and create a package.box file (default name) in the same folder with
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
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:
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:
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.
I tried following these instructions. I have a DEV folder with many sites (/www) underneath it and wanted to create a BACKUP folder and clone these sites, to remain backups and untouched. But I’m either not understanding it well or doing something wrong. First, vagrant package seems to have just captured the vagrant box, and not my sites. Second, while it seems to boot up in the end, it’s very slow and there are a number of reports that start “default: Warning: Connection timeout. Retrying… / default: Warning: Remote connection disconnect. Retrying… /” Any advice much appreciated.
I had to use –name
vagrant box add –name xirrus-xms /home/[USER]/vm/[box-file]
If you use the long method then instead of “config.vm.box=”name-of-box” you may use: vagrant init name-of-box
Awesome! Thanks for this guide!
Thank you so much for this information!! :)