Understanding and Using Microsoft Windows Server 2008 Hyper-V Snapshots


What is a Hyper-V Snapshot?


If you use Microsoft Virtual Server 2005 R2 in a test and development or support environment, you probably quickly figured out how to employ differencing and undo virtual hard disks (VHDs) to create hierarchies of virtual machines with incremental configuration variations and rollback capabilities. You can much more easily implement these types of environments using the new Hyper-V snapshot feature, which allows you to capture the configuration and state of a virtual machine at any particular point in time, and provides you with the ability to load any existing snapshot within a matter of seconds.



How does Hyper-V Create a Snapshot?


There are three distinctive elements included in Hyper-V: a Windows hypervisor, child partitions, and a parent partition. The Windows hypervisor runs directly above the hardware and ensures the isolated execution of the parent and child partitions. The role of a child partition is to provide a virtual machine environment to install and execute guest operating systems and applications. Lastly, the parent partition is a special virtual machine that executes Windows Server 2008 and controls the creation and operations of child partitions.


The parent partition creates and manages child partitions through a set of components referred to as the virtualization stack. One of the components in the virtualization stack is the Virtual Machine Management Service (VMMS). The VMMS includes many critical subcomponents, including the Worker Process Manager (WPM) and the Snapshot Manager (SM). The WPM creates a Virtual Machine Worker Process (VMWP) for each virtual machine when it is started. The VMWP manages the creation of snapshots for a virtual machine that is in an online state (started and running). If a virtual machine is offline, and therefore does not have an active VMWP, the Snapshot Manager handles the snapshot creation process.


Figure 1 shows the default virtual machine folder and file set which includes:



  • A folder that stores one or more virtual hard drives (VHDs) containing the operating system files, application files, and data.

  • A Snapshots folder that originally does not contain any files.

  • A Virtual Machines folder that contains an XML-based virtual machine configuration file named using a globally unique identifier (GUID), and a folder named with the same GUID that contains two files. The first file is a saved state file (named using the same GUID as the XML file with a .VSV extension) that is used to store virtual machine state information, such as processor register data. The second file is a binary file (also named with the same GUID as the XML file with a .BIN extension) that is used to store the virtual machine memory contents.


Figure 1: Default virtual machine folder and files before a snapshot


In Figure 1, you can see that the default location for the VHD folder is C:\Users\Public\Documents\Microsoft Hyper-V\Virtual Hard Disks, and that Snapshots and Virtual Machines folders are located in C:\ProgramData\Microsoft\Windows\Hyper-V. These folder locations can easily be modified in the Hyper-V settings using the Hyper-V Manager console.


For a virtual machine without snapshots, all changes made to the virtual machine guest operating system files, application files, and data are applied to the VHDs associated with the virtual machine. Any state information is stored in the .VSV and .BIN files. If you make changes to the virtual machine settings, the changes are reflected in the XML configuration file.


Essentially, the snapshot creation process results in several new files associated with the virtual machine. As shown in Figure 2, the Snapshot Manager creates the following folders and files in the Snapshots folder:



  • A new folder named using the original GUID. In this folder, a new differencing VHD is created for each parent VHD associated with the virtual machine. The new differencing VHD has the name of the original VHD appended with a new GUID and ends with a .AVHD extension.

  • A copy of the original virtual machine configuration file named using a new GUID and .XML extension

  • A new folder named using the same GUID as the new XML file. This folder contains the saved state file (.VSV) and binary file (.BIN) which are created during the virtual machine snapshot. Both files are named with the same GUID as the new folder.

  • The original virtual machine configuration file is updated to replace the original VHD filenames with the new differencing drives.


Figure 2: Virtual machine folders and files after a snapshot


Once a snapshot is created, all guest operating system, application, and data changes made during the execution of the virtual machine are stored in the associated differencing VHDs. If a virtual machine is offline or powered-down when a snapshot is created, there is no virtual machine state or memory contents to save.


For each subsequent snapshot that is created, a new set of folders and files is generated to capture the virtual machine state and configuration. One important item to note is that the new differencing disks created for each subsequent snapshot are related in a parent and child hierarchy with the original VHDs as the top-level nodes.


Creating a Snapshot


In order to create a snapshot of a virtual machine, you can use the Hyper-V Manager. This is an MMC-based console that is enabled when the Hyper-V role is added to Windows Server 2008. As shown in Figure 3, simply right-click on the virtual machine and select the Snapshot option from the menu.



Figure 3: Creating a virtual machine snapshot using the Hyper-V Manager console


Figure 4 illustrates the changes in the Hyper-V Manager console when the snapshot completes. Basically, the Snapshots section now shows a tree structure that reflects the existing virtual machine snapshot hierarchy. The root node of the tree is the snapshot that was just created and includes the creation timestamp. Under the root node, there is a child named Now which represents the running version of the virtual machine.



Figure 4: Snapshot display in the Hyper-V Manager console


As you make changes to the configuration of a virtual machine, you can create and save additional snapshots. For example, if you want to load and test multiple applications on a particular virtual machine, you can load one application at a time, test it, and take a snapshot of the virtual machine before proceeding to load and test the next application. As shown in Figure 5, snapshots that are generated after the initial one are displayed in a parent and child hierarchy that also reflects the relationship of the differencing disks that are created during each snapshot to capture changes to the virtual machine operating system, application, and data.



Figure 5: Snapshot hierarchy display in the Hyper-V Manager console


Reverting to a Previous Snapshot


If after making a series of changes to a virtual machine you decide that you need to go back to the previous snapshot, Hyper-V provides a Revert option to perform this action as shown in Figure 6. Once the Revert option is applied to a virtual machine, the resulting configuration and state of the virtual machine are returned to the settings saved in the snapshot files. This means that any and all configuration changes made since the snapshot was created including virtual hardware modifications to RAM, number of processors, virtual hard disk adapters, and so on, will be lost.



Figure 6: Using the Snapshot Revert Option in the Hyper-V Manager console


When a Revert is performed, the running virtual machine is stopped and the active differencing disks (.AVHD) are deleted. New differencing disks are created and named using a new GUID. The virtual machine configuration saved during the snapshot is reinstated and the names of the new active differencing disks are updated. The virtual machine is then restarted and the save state files (.VSV and .BIN) are loaded. If the snapshot was created when the virtual machine was powered-off, then there are no save state files to load and the virtual machine remains powered-off.


Conclusion


Although the inner workings of the Snapshot feature included in the release of Windows Server 2008 Hyper-V are intricate, it is extremely easy to create and revert to a snapshot using the Hyper-V Manager console. The ease of use of the Snapshot feature within Hyper-V facilitates the creation of virtual machine hierarchies with configuration variations that accommodate test and development environments, incremental desktop and server image builds, and many other complex scenarios. This is one of many improvements in Windows virtualization technology which makes it competitive with other established virtualization products like VMWare.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top