Vini
Vini

Reputation: 2134

Creating a copy of the Virtual machine using vagrant

I have a project that is deployed on a CentOS6 using vagrant. I am trying to create a different machine with a different name and IP address using vagrant. Despite me changing the name of the box and IP on the Vagrantfile, it says the machine is already up and running.

I also changed the name of the VM1 and did the vagrant up, still it renames my VM1 to its old name and do not create a second VM.

How can I try to create a so called copy of the VM using vagrant?

Upvotes: 1

Views: 1736

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53703

When you copy the full vagrant project folder, you also copy a .vagrant folder, this folder contains the id (and uuid) of the VM.

So after you did a copy, when you run vagrant up from the new folder, it will still operate the same VM than the original folder.

  1. If you want to create a new VM from scratch (if you have all your provisioning steps automated)

you just need to remove the .vagrant folder from the new project folder, vagrant will create a new VM

  1. If you want to operate the same VM as the original one

first, you need to clone your VM, the easiest is to do that from VirtualBox UI, select your original VM and make a clone (integral clone). You can also do a clone from CLI (actually vagrant runs a clonevm command when it creates a new VM from the vagrant box)

Then, you need to check the id of the new VM. You can run from command line

$ VBoxManage list vms

This will list all vms with their associated Id, you can then edit the id file from the .vagrant/machines/default(or machine name)/virtualbox folder. You can also check the index_uuid

This should do the trick. After you made the edit, if you run vagrant up again; vagrant will operate the new VM you've just cloned

Upvotes: 6

Related Questions