I use VirtualBox every day. Many times I've already created a Virtual Machine (VM) that will serve as the building block for a new server. To that end, I'll clone the original VM, and then use it to create the new machine. That's very simple with the GUI. But what if you make use of VirtualBox on a GUI-less server? If that's the case, your best bet is cloning those VMs with the help of a built-in command.
I'm going to show you how to do just that—clone VMs from the command line. I'll be demonstrating this on an Elementary OS host, but the process is the same on most hosts. If you're using Windows as the host, the command must be run from within directory housing the VirtualBox executables (so adjust accordingly).
Finding the names of your VMs
The first thing you must do is find out the actual names of your Virtual Machines. To do this, open a terminal window and issue the command:
VBoxManage list vms
The above command will list out all Virtual Machines on your host ( Figure A).
Say I want to clone UbuntuServer to UbuntuServer_3. For that, I would use the VBoxManage command in two steps. The first step is to export a Virtual Machine as an .ova file. To do this, open a terminal window and create a new folder to house the file with the command mkdir UbuntuServer_3. Make sure this folder is in the same directory that houses your other VM folders. To export the VM to an .ova file, issue the command:
VBoxManage export UbuntuServer --output UbuntuServer_3/UbuntuServer_3.ova
Once that .ova file has successfully exported, import it with the command:
VBoxManage import UbuntuServer_3/UbuntuServer_3.ova
The good thing about the import command is that it will automatically reinitialize the MAC address, so you don't have to worry about conflicts. Issue the VBoxManage list vms command and you will see that the new UbuntuServer_3 VM has been successfully imported ( Figure B).
Congratulations, your VirtualBox VM has been cloned and is ready to use.
Who needs a GUI?
Although the VirtualBox GUI makes this process significantly easier, it's not necessary. For anyone that makes use of a headless VirtualBox host, using the VBoxManage command is invaluable. And since the export and import process re-initializes the hardware address, you won't have to worry about networking errors.
- How to enable USB in VirtualBox (TechRepublic)
- How to enable copy and paste in VirtualBox (TechRepublic)
- How to set bridged networking in a VirtualBox virtual machine (TechRepublic)
- How to connect VirtualBox VMs to your company network (TechRepublic Video)
- VirtualBox: Everything the pros need to know (TechRepublic)
- How to run Windows 10 on your Mac (ZDNet)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.