By Andy Syrewicze and Richard Siddaway

Save 37% off Learn Hyper-V in a Month of Lunches with code learnhyperv.

 

If you’ve been in IT for any length of time, you know that software upgrades are a part of life. Every month, you get a list of patches from Microsoft that need to be applied both to the operating system and the Windows Server roles and features inside of your environment. Eventually these patches cause something to break. If only there was a way to quickly rollback a failed patch. Perhaps your testing routine would be made easier if you could click a “go-back” button? Well, we’re going to talk about one such technology in this article: Hyper-V Checkpoints!


Hyper-V Checkpoints

In this article we’re going to build Hyper-V Checkpoints. It’s important to know how to use checkpoints, because you’ll use them regularly. Checkpoints are normally used prior to software upgrades and patch testing, but are really useful anytime you’re making a fundamental change within the guest operating system of the virtual machine, like file relocation or a large settings change within an application.

Note I regularly use checkpoints to roll back changes when testing demonstrations for presentations at conferences.

You should train yourself to think about a checkpoint anytime you get ready to do a software change within a VM.

Note Making a checkpoint could save you a ton of time, and possibly your job, by allowing you to undo a change relatively quickly.

This technology can save huge amounts of time and effort, if used properly. The ability to hit an undo button on everything that’s occurred to a virtual machine since the last checkpoint is immensely powerful. Unfortunately, there are pitfalls. Checkpoints can be dangerous if used improperly. We’ll be covering the proper use cases and how NOT to use them, allowing you to use this technology without potentially causing data loss within your organization. Yes, you read correctly. Misuse of Checkpoints can, and does, cause data loss. Let’s start working through the article to help you use this technology properly.


What are Hyper-V Checkpoints?

The simplest explanation is to think of a checkpoint as a snapshot in time for a VM. You’re taking a copy of a virtual machine, at a point in time, and then you’re setting it aside for later use. The checkpoint can be taken while the machine is live. The guest OS inside of the VM doesn’t even know that it’s being done. If you decide a day or two later that you want to revert the virtual machine back to the configuration that existed when the checkpoint was created, you apply the checkpoint, and it reverts back to the settings from that time. This is one of those things that’s easier to understand by seeing it in action.


Using Hyper-V Checkpoints via Hyper-V Manager

Checkpoints can be managed with Hyper-V manager or PowerShell. In this section, I’ll show you how to use checkpoints in Hyper-V manager. To create a checkpoint:

  1. In Hyper-V Manager select the Hyper-V host with a VM that you have already created;
  2. Choose one of the virtual machines and open the virtual machine’s console window;
  3. Log into the virtual machine. Using notepad, create a new text file and save it as PRE-CHECKPOINTSTATE.txt onto the desktop of the guest OS;
  4. At the top of the virtual machine console window, click the “Action” dropdown, then click “Checkpoint”;
  5. On the Checkpoint Name dialog screen type: Pre-Software Installation and click “Yes”;
  6. Monitor the Checkpoint status using the “Status” column next to the target virtual machine in Hyper-V Manager and wait for completion;
  7. To verify the Checkpoint was taken successfully, review the Checkpoint section in Hyper-V Manager with the target virtual machine selected. It should look like figure 1;
  8. Delete the CHECKPOINTSTATE.txt file that we placed on the desktop earlier;

    Figure 1 Hyper-V Manager Checkpoint View

  9. Open PowerShell within the guest, with an account that has administrative privileges;
  10. Type: Install-WindowsFeature –Name “WDS”
    and press enter to install the Windows Deployment Services Role;
  11. Type: Get-WindowsFeature –Name “WDS” | Select InstallState
    and verify the InstallState is “Installed”;
  12. In the virtual machine console window, click the “Action” drop down and click “Revert”;
  13. Monitor the state of the virtual machine with Hyper-V Manager as the machine turns off, and the earlier checkpoint is restored;
  14. Once the checkpoint is restored, verify that the PRE-CHECKPOINTSTATE.txt file exists on the desktop;
  15. Open a PowerShell prompt with an account that has administrative privileges;
  16. Type: Get-WindowsFeature –Name “WDS” | Select InstallState and note that the InstallState now shows as “Available” meaning that the role is no longer installed;
  17. Leave the checkpoint in place. We’ll be using it later in the article.

Try it Now

– Make a checkpoint using Hyper-V manager

– Now revert the checkpoint

– Is there any difference between the original configuration and the current one, after reverting the checkpoint?

 

We made the checkpoint, made file changes, installed additional software, and then we told Hyper-V to forget those changes, and take us back to where we started. How many times have you, or a colleague, installed a piece of software or a patch that caused a failure and you had to spend hours fixing it? In this case, that breakage would be fixed in minutes, instead of hours. This is the power of Hyper-V Checkpoints.


Managing Multiple Checkpoints with Hyper-V Manager

Earlier you performed a single snapshot procedure and a revert operation, but the checkpoint view in Hyper-V Manager displays the checkpoints in tree format. This is because Hyper-V is capable of tracking multiple checkpoints for a virtual machine at any given time. This is extremely useful for operations such as software revision testing, where you may be testing different software versions and different software combinations on the same server. Checkpoints allow you to move between the different configurations with ease. Let’s try this now to get a feel for it:

  1. In Hyper-V Manager select the Hyper-V host with a VM you have created;
  2. Select the virtual machine that was used in the previous exercise and that contains the “Pre-Software Installation” checkpoint;
  3. Using PowerShell within the guest virtual machine install the WDS role once again;
  4. Rename the PRE-CHECKPOINTSTATE.txt file on the desktop to CONTAINSWDS.txt;
  5. In the Checkpoints section for the VM in Hyper-V Manager right-click the “Pre-Software Installation” Checkpoint and then click “Apply”;
  6. The “Apply Checkpoint” dialog appears, as shown in figure 2. Click “Create Checkpoint and Apply”;

    Figure 2 Apply Checkpoint Dialog

  7. Monitor the creation of the new Checkpoint in Hyper-V Manager;
  8. Note the new Checkpoint in the checkpoints tree for the virtual machine. The default format of “VM-NAME – Date” will have been used for the new checkpoint;
  9. Right-click on the new checkpoint and click “Rename”. Rename the checkpoint to “Contains Windows Deployment Services”;
  10. Verify that the VM is back to its original state and then open PowerShell with a user with administrative privileges;
  11. Type: Install-WindowsFeature –Name “DHCP”
    and press enter to install the Windows DHCP service inside the virtual machine;
  12. Type: Get-WindowsFeature –Name “DHCP” | Select InstallState
    and verify the InstallState is “Installed”;
  13. Rename the PRE-CHECKPOINTSTATE.txt file on the desktop to CONTAINSDHCP.txt;
  14. Using Hyper-V Manager apply the “Pre-Software Installation” checkpoint. Select “Create Checkpoint and Apply” on the “Apply Checkpoint” dialog UI;
  15. Monitor the creation of the new Checkpoint in Hyper-V Manager;
  16. Rename the Checkpoint to “Contains DHCP Service”;
  17. Note that your snapshot tree should now look like the one found in figure 3;

    Figure 3 A more complex Checkpoint Tree in Hyper-V Manager

  18. Right-Click on the “Contains Windows Deployment Services” checkpoint and click “Apply”;
  19. Click “Apply” on the Apply Checkpoint Dialog UI. There’s no need to create another new “Pre-Software Installation” Checkpoint at this time;
  20. Verify that the file on the desktop is named “CONTAINSWDS.txt” and that the WDS role is showing installed using the Get-WindowsFeature PowerShell cmdlet;
  21. Using Hyper-V Manager, apply the “Contains DHCP Service” Checkpoint and repeat the previous step to verify that the DHCP checkpoint is now in use;
  22. Note how the Checkpoint tree in Hyper-V Manager changes with each modification;
  23. Re-Apply the “Pre-Software Installation” Checkpoint without creating an additional checkpoint in the Apply Checkpoint dialog UI;
  24. Leave the checkpoints in place. We’ll be using them later in the article.

Try it now

Follow the instructions in this section to create and use multiple checkpoints

Managing and utilizing Hyper-V checkpoints in this manner allows for agile software testing and verification. Gone are the days of having to maintain multiple servers to be able to effectively test software procedures. Checkpoints make this process easy and safe.

Deleting and Merging Checkpoints with Hyper-V Manager

The best practice is to remove checkpoints as soon as you’re done with them. If you leave them in place, all new incoming writes get written to the checkpoint and will eventually fill your storage. What happens to the changes contained inside the checkpoint? Two possibilities exist. The first option is to retain all the changes in a checkpoint and roll them into the next upstream object in the tree, regardless of whether that’s the base virtual disk, or another checkpoint. The second option is deleting the changes outright without retaining them. This is performed by using the delete action.

If you delete the currently active snapshot, Hyper-V will conduct a merge operation and roll the changes contained in the checkpoint into the next upstream object. If you delete a checkpoint that’s not currently active, the changes within that checkpoint will be purged and lost forever.

Note Remember, if you want to retain the changes you’ve made, you’ll want to merge the checkpoint; if you don’t want them saved, you’ll want to delete it.

Again, this is one of those situations where it’s best to learn by doing. Let’s say we need to retain the DHCP service permanently for this particular virtual machine, and we’ve determined that Windows Deployment Service isn’t needed. Let’s clean up our checkpoints from earlier for practice:

  1. In Hyper-V Manager select the Hyper-V host with the two VMs you created;
  2. Select the virtual machine that was used in the previous exercise with the “Pre-Software Installation”, “Contains DHCP Service”, and “Contains Windows Deployment Services” checkpoints;
  3. Verify that the “Pre-Software Installation” Checkpoint is currently active. Your checkpoint tree should look like the one in figure 3;
  4. In the Checkpoints Tree view for the selected virtual machine, right-click the “Contains Windows Deployment Services” checkpoint and click “Delete Checkpoint”;
  5. Click “Delete” when the Delete Checkpoint Verification UI shows up;
  6. Monitor the deletion progress in the virtual machine status column in Hyper-V Manager and wait for completion. Notice the merge process occurring?
  7. Apply the “Contains DHCP Service” checkpoint. Don’t create another checkpoint during the application process;
  8. Right-Click on the “Contains DHCP Service” checkpoint and click “Delete Checkpoint”;
  9. Click “Delete” when the Delete Checkpoint Verification UI shows up;
  10. Monitor the deletion progress in the virtual machine status column in Hyper-V Manager and wait for completion. Note that an extra merge process executes as well;
  11. Right-Click on the “Pre-Software Installation” checkpoint and click “Delete Checkpoint”;
  12. Click “Delete” when the Delete Checkpoint Verification UI Shows up;
  13. Monitor the deletion progress in the virtual machine status column in Hyper-V Manager and wait for completion. Note that another merge operation occurs;
  14. Verify that no further checkpoints are displayed in the Checkpoints tree for the selected virtual machine. All changes have now been merged back into the virtual machine’s virtual disk.

Try it Now

Delete the checkpoints you created in this article by following the procedure in this section

You’ve decided that the intended changes are safe and you’ve merged them back into the base virtual disk that’ll continue running the production workload. Clicking delete on a checkpoint may seem counter-intuitive if you want to keep it, but that’s how to merge process is called.

Alternatively, you could use the “Delete Checkpoint Subtree” option to delete more than one checkpoint at a time. If you wanted to omit any of the changes, apply the previous checkpoint, and then delete the checkpoint containing the changes you no longer want.

You’ve walked through the entire checkpoint testing process. Using this method when testing and applying software updates can save you a lot of time and heartache, and it can be a powerful tool in your toolbox.

*Important warning*

It’s important that upon successful testing and verification of the changes contained within a checkpoint, that it be deleted and merged back into the base virtual disk as soon as possible.

When a checkpoint is created, an .AVHDX file is created and associated with the virtual machine’s virtual hard disk. If the checkpoint and its associated .AVHDX file exists, all incoming disk writes are occurring within the .AVHDX file and NOT the virtual hard disk. If you write 200 GBs of data when a checkpoint is present on a 300 GB large virtual machine, you’re potentially consuming 500 GBs of storage, depending on how the VM’s virtual hard disk has been provisioned.

It’s best to remove checkpoints as soon as you’re done with them. Otherwise, you risk consuming all the storage in your Hyper-V environment if the checkpoint is left for an extended time.

 

That’s all for this article. For more on Hyper-V, download the free first chapter of Learn Hyper-V in a Month of Lunches and see this Slideshare presentation. Don’t forget to use code learnhyperv to save 37%.