Create Clones and Snapshots of Virtual Machines in VirtualBox

Make copies of Ubuntu images quickly and easily

Virtual circle of prisms


oxygen / Getty Images

Virtual Machines have been a game changer for testers, admins, and data centers. For those who prefer using open source technology, VirtualBox is an incredible way of creating and managing virtual machines. Two features of VirtualBox that every admin should understand how to use are clones and snapshots.

What are clones and snapshots? Simply put, clones are an exact copy of a working virtual machine, while snapshots allow you to save a particular state of a virtual machine (which can be handy when you want to test something, or you're about to make a change to that virtual machine, and need to be able to roll back to a working instance, should something break).

Let’s see how to create both clones and snapshots in the latest version of VirtualBox (5.2.20). We’ll demonstrate using a Ubuntu Server 18.04 instance, but the process is the same, regardless of what guest operating system you are working with.

Creating a Clone

The VirtualBox main window, ready for you to clone a virtual machine.

As stated, clones are one of the best ways to create an exact copy of a virtual machine. One very handy way to make use of clones is to create a clean virtual machine of, say, Ubuntu Server, and then clone the original for a fresh base that can be used for any purpose. So with a clean Ubuntu Server 18.04 virtual machine in place (and either off or in a saved state, as clones cannot be created while a virtual machine is running), you can create a clone by following these steps:

Creating a clone of a Ubuntu Server virtual machine.
  1. Open VirtualBox.

  2. Select the virtual machine to be cloned in the left pane.

  3. Right-click the virtual machine to be cloned.

  4. Press Clone from the popup menu.

  5. When prompted, give the clone a name, and press Next.

  6. Select Full clone from the Clone type window, and press Clone.

    Naming the clone in VirtualBox.

Depending on how large your virtual machine is, the cloning process can take anywhere from five to twenty minutes. Make sure to give the clone a fitting name for its usage, otherwise you might wind up with a lot of clones with similar names (which could be confusing).

When the process completes, your clone is ready to use.

Creating and Using Snapshots

Creating a snapshot of a Ubuntu Server virtual machine.

Snapshots are a great way to save a particular state of a virtual machine (VM). Say, for instance, you plan on installing something new on (or making a change to) a working VM and you want to make sure you have a “saved point” that you can roll back to (in case things go awry). Let’s use the same Ubuntu Server VM to create a snapshot. Say you’re about to install a LAMP stack (or a major upgrade) and you want to make sure you can roll back, on the off-chance the install/upgrade breaks something you’ve installed and configured. To create the snapshot, select the VM to be used in the left pane, and select the Snapshots tab near the top of the window. In the resulting screen, press Take.

It is important to give the snapshot a unique name and full description.

In the resulting window, give the snapshot a name and a description. Make sure to leave adequate notes in the description, so you know the reason this snapshot was taken and/or how the state of the VM was prior to what was done post-snapshot. Press OK, and the snapshot will be taken. You should now see the name of the snapshot listed with Current State below.

Restoring a snapshot after changes were made to the virtual machine.

To restore a snapshot, follow these steps:

  1. Select the virtual machine to work with from the left pane in the main window.

  2. Press Snapshots near the top of the window.

  3. Select the snapshot you want to restore.

  4. Press Restore.

  5. In the resulting window, uncheck the box for Create A Snapshot Of The Current Machine State.

  6. Press Restore.

  7. Select the snapshot you want to restore.

The reason why to uncheck the box for Create A Snapshot Of The Current Machine State is simple. If you’re rolling back to a previous state, because the current state is broken, you don’t want to take a snapshot of that broken state. When you uncheck that box, the broken state will be discarded.

It is also possible to restore a snapshot from the Close dialog.

Another way of restoring a snapshot is through the Close Virtual Machine dialog. With a VM running, select File > Close. In the resulting window, check Power off the machine and then check Restore current snapshot. The one caveat to this method is that it only allows you to restore to the previous snapshot (instead of being able to select a specific snapshot, as you could in the previous method). Press OK and the snapshot will be restored.

At this point, your virtual machine will have rolled back to the state found in the restored snapshot. Any change made after that snapshot will be gone.