Advanced VirtualBox Administration

VirtualBox is very flexible software, allowing you to clone an existing virtual machine, take snapshots of it’s disk’s data, or even migrate it to another host while still running (called teleporting). These instructions take place on a Debian 7 (Wheezy) host, but nothing is distribution specific as we’re only concerned with VirtualBox in this article.

We’ll take a look at how to take a snapshot of a virtual machine’s data first. Good practice dictates that you should always take a snapshot of your VM immediately after you have configured it, but before you’ve put your mission critical data on it. This way you can redeploy it easily in similar-but-different circumstances. The name is required, and the description is optional.

VBoxManage snapshot take $NAME $DESCRIPTION

To delete, and restore, the commands are obvious.

VBoxManage snapshot delete $NAME
VBoxManage snapshot restore $NAME

There’s also a shortcut to restore to the last snapshot you took. Handy if you accidentaly hose the system, or are done testing changes.

VBoxManage snapshot restorecurrent

Now we’ll learn how to clone a virtual machine. It is a very straighforward process. If you don’t give the cloned VM a name, it’s name will default to the original VM’s name, with “Clone” appended to the end. The “–register” is there so the new cloned VM will be registered with VirtualBox.

VBoxManage clonevm $ORIGINAL_VM --rename "New Cloned VM" --register
Additionally you can clone from a previous snapshot.
VBoxManage clonevm $ORIGINAL_VM --rename "Just Another Test" --snapshot "after config" --register

The last bit we’ll cover is teleporting. This is the act of moving a running guest VM to a different host VM, with no interruption. To do this, there are a few prerequisets, all of which are beyond the scope of this article.

  • The hosts must have shared storage, where the disk images are stored. SMB, NFS, and iSCSI are common choices for this.
  • Both hosts must have the VM configured and registered

Further configuration of the guest VM is required for this to work. On the host that the VM will be teleported to, run this, then start the VM.

VBoxManage modifyvm $VM_NAME --teleporter on --teleporterport $PORT
VBoxHeadless -s $VM_NAME

Instead of it running, it will sit patiently waiting for the teleport to occur. Now, on the source host, with the VM running, you can teleport it on the fly like so.

VBoxManage controlvm $VM_NAME teleport --host $DESTINATION_HOST --port $PORT