With snapshots, you can save a particular state of a virtual machine for later use. At any later time, you can revert to that state, even though you may have changed the VM considerably since then. A snapshot of a virtual machine is thus similar to a machine in "saved" state, as described above, but there can be many of them, and these saved states are preserved.
You can see the snapshots of a virtual machine by first selecting a machine in the VirtualBox Manager and then clicking on the "Snapshots" button at the top right. Until you take a snapshot of the machine, the list of snapshots will be empty except for the "Current state" item, which represents the "Now" point in the lifetime of the virtual machine.
There are three operations related to snapshots:
-
You can take a snapshot. This makes a copy of the machine's current state, to which you can go back at any given time later.
-
If your VM is currently running, select "Take snapshot" from the "Machine" pull-down menu of the VM window.
-
If your VM is currently in either the "saved" or the "powered off" state (as displayed next to the VM in the VirtualBox main window), click on the "Snapshots" tab on the top right of the main window, and then
-
either on the small camera icon (for "Take snapshot") or
-
right-click on the "Current State" item in the list and select "Take snapshot" from the menu.
-
In any case, a window will pop up and ask you for a snapshot name. This name is purely for reference purposes to help you remember the state of the snapshot. For example, a useful name would be "Fresh installation from scratch, no Guest Additions", or "Service Pack 3 just installed". You can also add a longer text in the "Description" field if you want.
Your new snapshot will then appear in the snapshots list. Underneath your new snapshot, you will see an item called "Current state", signifying that the current state of your VM is a variation based on the snapshot you took earlier. If you later take another snapshot, you will see that they will be displayed in sequence, and each subsequent snapshot is derived from an earlier one:
VirtualBox imposes no limits on the number of snapshots you can take. The only practical limitation is disk space on your host: each snapshot stores the state of the virtual machine and thus occupies some disk space. (See the next section for details on what exactly is stored in a snapshot.)
-
-
You can restore a snapshot by right-clicking on any snapshot you have taken in the list of snapshots. By restoring a snapshot, you go back (or forward) in time: the current state of the machine is lost, and the machine is restored to the exact state it was in when the snapshot was taken.[4]
Note
Restoring a snapshot will affect the virtual hard drives that are connected to your VM, as the entire state of the virtual hard drive will be reverted as well. This means also that all files that have been created since the snapshot and all other file changes will be lost. In order to prevent such data loss while still making use of the snapshot feature, it is possible to add a second hard drive in "write-through" mode using the
VBoxManage
interface and use it to store your data. As write-through hard drives are not included in snapshots, they remain unaltered when a machine is reverted. See Section 5.4, “Special image write modes” for details.To avoid losing the current state when restoring a snapshot, you can create a new snapshot before the restore.
By restoring an earlier snapshot and taking more snapshots from there, it is even possible to create a kind of alternate reality and to switch between these different histories of the virtual machine. This can result in a whole tree of virtual machine snapshots, as shown in the screenshot above.
-
You can also delete a snapshot, which will not affect the state of the virtual machine, but only release the files on disk that VirtualBox used to store the snapshot data, thus freeing disk space. To delete a snapshot, right-click on it in the snapshots tree and select "Delete". As of VirtualBox 3.2, snapshots can be deleted even while a machine is running.
Note
Whereas taking and restoring snapshots are fairly quick operations, deleting a snapshot can take a considerable amount of time since large amounts of data may need to be copied between several disk image files. Temporary disk files may also need large amounts of disk space while the operation is in progress.
There are some situations which cannot be handled while a VM is running, and you will get an appropriate message that you need to perform this snapshot deletion when the VM is shut down.
Think of a snapshot as a point in time that you have preserved. More formally, a snapshot consists of three things:
-
It contains a complete copy of the VM settings, including the hardware configuration, so that when you restore a snapshot, the VM settings are restored as well. (For example, if you changed the hard disk configuration or the VM's system settings, that change is undone when you restore the snapshot.)
The copy of the settings is stored in the machine configuration, an XML text file, and thus occupies very little space.
-
The complete state of all the virtual disks attached to the machine is preserved. Going back to a snapshot means that all changes that had been made to the machine's disks -- file by file, bit by bit -- will be undone as well. Files that were since created will disappear, files that were deleted will be restored, changes to files will be reverted.
(Strictly speaking, this is only true for virtual hard disks in "normal" mode. As mentioned above, you can configure disks to behave differently with snapshots; see Section 5.4, “Special image write modes”. Even more formally and technically correct, it is not the virtual disk itself that is restored when a snapshot is restored. Instead, when a snapshot is taken, VirtualBox creates differencing images which contain only the changes since the snapshot were taken, and when the snapshot is restored, VirtualBox throws away that differencing image, thus going back to the previous state. This is both faster and uses less disk space. For the details, which can be complex, please see Section 5.5, “Differencing images”.)
Creating the differencing image as such does not occupy much space on the host disk initially, since the differencing image will initially be empty (and grow dynamically later with each write operation to the disk). The longer you use the machine after having created the snapshot, however, the more the differencing image will grow in size.
-
Finally, if you took a snapshot while the machine was running, the memory state of the machine is also saved in the snapshot (the same way the memory can be saved when you close the VM window). When you restore such a snapshot, execution resumes at exactly the point when the snapshot was taken.
The memory state file can be as large as the memory size of the virtual machine and will therefore occupy quite some disk space as well.
[4] Both the terminology and the functionality of restoring snapshots has changed with VirtualBox 3.1. Before that version, it was only possible to go back to the very last snapshot taken -- not earlier ones, and the operation was called "Discard current state" instead of "Restore last snapshot". The limitation has been lifted with version 3.1. It is now possible to restore any snapshot, going backward and forward in time.