How to take a snapshot of a disk in VirtualBox (and restore it later)

Updated: January 29, 2024 By: Guest Contributor Post a comment

Overview

Managing virtual machines effectively often involves taking snapshots of the virtual disks to save states at specific time points. This tutorial focuses on Oracle’s VirtualBox, a free and open-source virtualization tool used by millions worldwide for creating and working with virtual machines (VMs). We’ll look at snapshots, why they’re useful, how to create and restore them, and some advanced snapshot management.

Understanding Snapshots

Snapshots in VirtualBox allow you to save a particular state of a virtual machine, including its entire operating system, installed software, and files. It’s like taking a picture of the VM’s disk at a specific point in time, and you can return to it later. It saves time and can be a lifesaver when testing software that might damage your system or when trying to configure a complex system state.

Prerequisites

  • Oracle VirtualBox installed on your machine
  • Virtual machine created in VirtualBox

Taking a Snapshot

To take a snapshot of a disk in VirtualBox, you’ll need to follow these steps:

  1. Open Oracle VirtualBox Manager.
  2. Select the machine you want to snapshot.
  3. Click on ‘Machine’ in the menu, then ‘Take Snapshot’, or simply press Host+T where ‘Host’ key is typically the right ‘Ctrl’ key.
  4. Enter a name and description for the snapshot and click ‘OK’.

This process will momentarily pause your VM, take the snapshot, then resume operations.

Snapshot Management via Terminal

In some situations, such as in a server environment or when scripting, it’s beneficial to manage snapshots from the command line. Here’s how to use the VBoxManage tool, which comes with VirtualBox, to work with snapshots:

1. Open Terminal (or Command Prompt in Windows).

2. To take a new snapshot, run:

VBoxManage snapshot <VM name> take <snapshot name> --description <description>

You’ll see output which confirms your snapshot was taken, with its unique UUID.

3. To list all snapshots, you will run:

VBoxManage snapshot <VM name> list

This outputs all snapshots and their details.

4. To restore a snapshot via command line, use the following command, replacing <snapshot name> with the actual name printed in the list command:

VBoxManage snapshot <VM name> restore <snapshot name>

This sets your virtual machine back to the state it was in when the snapshot was taken.

5. For deleting a snapshot, the command is:

VBoxManage snapshot <VM name> delete <snapshot name>

This will remove the snapshot from your list, but be cautious as this action is irreversible.

Snapshot Management via VirtualBox GUI

After taking a snapshot, managing it is quite straightforward:

  1. Go to the main window, select your VM and click on ‘Snapshots’.
  2. You’ll see a list of all snapshots taken for the selected VM. From here, you can take additional snapshots, restore an existing one, or delete snapshots you no longer need.
  3. To restore a snapshot, simply select it and click on ‘Restore Snapshot’. The VM will return to the exact state it was when that snapshot was taken. Note that restoring does not delete the snapshot—you can use it to restore the VM an unlimited number of times.
  4. If you’ve taken multiple snapshots, you also have the option to clone a VM from a snapshot creating an entirely separate VM at that state.

Advanced Snapshot Techniques

Now that we have covered the basics, here are some more advanced techniques for managing snapshots in VirtualBox:

  • Automating snapshots: If you regularly take snapshots, it may be wise to write a simple batch script (on Windows) or shell script (on Linux/Unix) that runs the appropriate VBoxManage commands, possibly triggered by scheduled tasks (cron jobs in Linux/Unix).
  • Handling disk space: Snapshots can quickly take up a lot of disk space. It’s crucial to have a strategy, such as a limit on the number of snapshots for a VM and regularly merging, deleting, or archiving old snapshots to conserve space.
  • Using snapshots for backups: Although not a replacement for proper backups, snapshots can serve as quick rollback points before making significant changes to a VM. Always backup your data in multiple places.

Conclusion

In conclusion, snapshots are an extremely powerful feature in VirtualBox that can save you enormous amounts of time and energy. With the knowledge on how to take, restore, and manage snapshots effectively using both the GUI and command line, you are well-equipped to manage the states of your virtual machines seamlessly and safely.