We started using Vagrant last year in 2014 mainly because we find it really good for managing virtual machines and also for provisioning the platforms. Most of the developers in our company use fedora, but some also use Ubuntu and Windows too. Now it is possible to setip LAMP or XAMP in all the platforms but it is difficult to develop your application in one fedora and expect it to work perfectly in other operating system. Well one solution is to ask all the developers use same operating system with exact same configurations to make sure the development environment is exactly the same but this is far from possible.
Using Vagrant the developers can create a working environment whose configurations are defined in a Vagrantfile, which can be included in the version control and other developers can use the same Vagrantfile to create a virtual machine which is exactly same as used by others.
We use shell files to provision the virtual machines. In a blank operating system, we need to install basic tools and softwares, mainly apache, mysql and php along with other tools like git, wget, setting up firewall, drush and also drupal. However there are times when we need to share the whole provisioned virtual machines with others, in that case it is also possible to generate a clone of a virtual machine which can be shared with others. In this blog we want to share the procedure for copying the vagrant virtual machines.
Make sure Virtual Machine is shut down
Use the Package command to generate the .box file
This command will take some time and it will generate a file called package.box in the vagrant project folder
Copy this file to a separate location
You need to copy the package.box file to a different location, may be to a different machine. It is a good idea to rename
package.box to something like centos-6.5-base.box
Setup a new vagrant machine
Now to restore the cloned .box file, you can create a new folder on your machine and initiate it.
This command will generate a Vagrantfile in your project folder.
Use the .box file generate above
Open the Vagrantfile in your favorite editor and add the following lines in it.
config.vm.box = "centos-6.5-base"
config.vm.box_url = "file:///c:/vagrant-boxes/centos-6.5-base.box"
It is important to not that the box name "centos-6.5-base" should not be used earlier by other vagrant based virtual machines. If your host is windows based then use the "file:///" text prefixed on the actual path.
Once the location of the box is specified simply do Vagrant up and your would have a cloned or duplicate virtual machine.