June 29, 2022
How to Delete a Snapshot Using Hyper-V Manager or PowerShell
Snapshots, which are known as checkpoints in Hyper-V, come in handy when you need to retain the last properly running state of a VM before deploying new software or installing an update. However, you have to be careful while deleting snapshots otherwise, you might lose important data.
In today’s post, we explain the mechanism of Hyper-V checkpoints. We will cover when to use these checkpoints and show how to delete snapshots from the Hyper-V Manager interface and by using PowerShell.
Download our white paper to learn how to improve the Hyper-V backup processes.
Hyper-V Checkpoints Mechanism
Before we go into detail about how Hyper-V checkpoints work, let me clear up any confusion related to the terms snapshots and checkpoints.
Snapshots and checkpoints represent the same capability of saving the state of a VM at a particular point in time. This state can be reverted to in the future if an issue occurs with the VM. Microsoft refers to the feature of saving the state of a VM as snapshots for releases before Windows Server 2012 R2. In subsequent releases, Microsoft uses the term checkpoints. In addition, snapshots is the term used in VMware environments. In this post, we are using both terms interchangeably as the covered mechanism and procedures apply to both snapshots and checkpoints. So, how do checkpoints/snapshots work?
How Hyper-V checkpoints are saved
Hyper-V VM data is saved in the form of a .vhdx file. When a checkpoint is created, the .vhdx file becomes a read-only file. New modifications applied to the VM are saved in a differencing virtual hard disk. This differencing virtual hard disk is saved in the form of a .avhdx file in the same folder as that containing the .vhdx file.
You can create a chain of checkpoints. Each checkpoint represents the state of the VM at a specific point in time. Each checkpoint is represented by an .avhdx file.
The mechanism of Hyper-V checkpoints is efficient with storage utilization. However, the performance of virtual disk reading operations is significantly reduced. The reason is that reading files would require checking the whole chain of checkpoints (.avhdx files) until the VM’s .vhdx file is reached.
In the screenshot below, you can see one parent .vhdx virtual disk and two .avhdx disks after creating two Hyper-V checkpoints for a VM.
According to this mechanism, deleting a .avhdx file does not delete the checkpoint. Instead, this kind of deletion breaks the chain and leads to data loss.
To delete a checkpoint without losing data, the .avhdx file should be merged with another (parent) .avhdx file (or .vhdx file) in the chain. If this checkpoint is the only checkpoint for the VM, the .avhdx file is merged with the .vhdx file, and the .vhdx file becomes writable again.
In the next section, we will show how to delete snapshots (checkpoints) from the Hyper-V Manager interface without losing data.
Delete Snapshots by Using the Hyper-V Manager Interface
Hyper-V Manager is a free GUI tool for managing Hyper-V hosts and VMs. It can be used to provision VMs, allocate RAM, create snapshots or delete them.
To delete the Hyper-V snapshot (checkpoint) from the Hyper-V Manager interface:
- Select the host from the left pane.
- Select the VM from the Virtual Machines pane.
- Right-click the checkpoint to be deleted from the Checkpoints pane. Select Delete Checkpoint…
In the screenshot below, you can see a parent .vhdx virtual disk and an .avhdx snapshot file after deleting the second Hyper-V checkpoint.
Delete Snapshots by Using PowerShell
To perform bulk actions on Hyper-V VMs, Windows PowerShell is more efficient than the Hyper-V Manager GUI as you can use commands to delete multiple snapshots at once. Besides, some actions, such as deleting a checkpoint that has no delete option in the GUI, can only be accomplished via PowerShell.
A checkpoint that cannot be deleted from the Hyper-V Manager is called a lingering checkpoint. Lingering checkpoints happen when a VM backup job fails.
When a VM backup job begins using a backup solution, the VM is placed into read-only mode. The new data submitted by VM users is saved to a special type of checkpoint called a recovery checkpoint. When the backup job completes successfully, the recovery checkpoint’s .avhdx file is merged with the VM .vhdx file, and the checkpoint is automatically deleted. However, if the backup job fails, the recovery checkpoint is not deleted automatically and remains as a lingering checkpoint.
To delete a checkpoint by using PowerShell:
- Open the Windows PowerShell ISE as administrator.
- Get the checkpoint exact name with the command Get-VMSnapshot. Provide the VMName when prompted.
- Run the command:
Get-VM -Name <VMName> | Get-VMSnapShot -Name <CheckpointName> | Remove-VMSnapshot
- Verify that the checkpoint has been successfully deleted with the command:
Creating checkpoints is a good practice for the sake of testing and creating an acceptance environment. However, keeping checkpoints is not recommended in a production environment. Checkpoints adversely impact the Hyper-V performance of reading operations.
Deleting checkpoints’ files from the disk directly leads to data loss. Checkpoints should be deleted from the Hyper-V Manager. The PowerShell can be used as well to delete them specially if they have no delete option in the Hyper-V Manager GUI.
Adopting a backup and replication solution is crucial for your data and application protection. Download NAKIVO Backup & Replication Free Edition and start protecting your data and applications