I want to show to anyone who’ll need it, how I managed to clone a Vagrant virtual machine using VirtualBox and some XML editing.
First of all ensure that you can access to you Vagrant-vm also with user and password (not only by public/private key files). You should try using vagrant/vagrant that should be the default credentials.
By the way if you can’t find username and password you can always change the password for “vagrant” user.
After that when you’re ready to clone, open Virtualbox, right click on your Vagrant vm (you should recognize it by the name, if you can’t find it go at end of this article) and click on “Clone”.
Change the vm’s name according your destination folder for the cloned Vagrant virtual machine. Please ensure to check the “Reinitialize MAC address” option if you plan to let the two virtual machines communicating each other.
You can choose two types of cloning: “Full” and “Linked”. The Full clone will have its own disk, the Linked clone will have a disk based on the original and increased for differences (it reduces disk size!).
And now it comes the tricky part. Go to the new cloned vm’s path and look for a .VBOX file:
Open this file with a smart text editor, search for the Machine uuid and copy it:
After that go on your original Vagrant machine’s directory and copy the whole content (including the .vagrant directory) to the new destination (the directory for the cloned vm).
Now you have to edit these two file copying the machine uuid inside: “id” and “action_provision”. You will find this file placed somewhere under “.vagrant” directory. REMEMBER: you have to edit them on your cloned environment NOT in the original one.
PAY ATTENTION: in “action_provision” file you don’t have to remove the starting prefix: ‘1.5:’
Now it’s almost done, BUT if you planned to let the two vms to inter-operate each other and you re-initialized the network MAC addresses, so you have to follow this step more:
*) You have to manual login to your Vagrant vm by starting it through VirtualBox. After that you have to change (supposing you are on a RHEL-style linux distro):
/etc/sysconfig/network-scripts/ifcfg-ethX (where X is your iface number)
Changing all the occurrences of the MAC address and UUID respectively, but you can simply comment or remove them.
After that you have also to edit the file:
And change the hwaddr for ethX with new one. You have also to remove the ethX+1 configuration (you will find new HWADDR on the ethX+1 config line)
NOTE: If for some reason you can’t find any Vagrant vm on your Virtualbox and you are using cygwin so take a look into cygwin home directory and look for a directory named “VirtualBox VMs”. After that you should search on Google how to change the home directory for current cygwin user (tip: look into /etc/passwd) and after that move the contents of this folder to the default one under Documents or whatever you defualt folder is (look into VirtualBox settings).