You are here

How to copy or clone a Vagrant box

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

vagrant halt

Use the Package command to generate the .box file

vagrant package

This command will take some time and it will generate a file called in the vagrant project folder

Copy this file to a separate location

You need to copy the file to a different location, may be to a different machine. It is a good idea to rename to something like

Setup a new vagrant machine

Now to restore the cloned .box file, you can create a new folder on your machine and initiate it.

vagrant init

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.

  1. = "centos-6.5-base"
  2. config.vm.box_url = "file:///c:/vagrant-boxes/"

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.