You may have noticed that it sometimes take quite some time to delete a virtual machine from within the Hyper-V console. It can take hours in some cases.
This happens if the virtual machine has snapshots and it is by design. What actually happens when you delete the virtual machine is that the snapshot(s) is being merge into the VHD file and then the virtual machine is deleted from the Hyper-V console.
I have created a virtual machine and installed Windows Server 2008 R2. It is just a basic install. After the install I created a snapshot while the virtual machine was still running and named it Basic Install.
Then I copied approximately 25 GB of data into the virtual machine and then I created another snapshot called Basic Install with Data. Then I shut down the virtual machine.
I then right-clicked the virtual machine, clicked on Delete
Let´s have a look and see what is really going on…
Before I pressed delete, the virtual machines VHD (Virtual Hard Disk) and AVHD (Snapshot) files looked like this:
This is what it looks like 73 percent into the “delete” process:
As you can see from the above screen shot, a fairly huge amount of data has already been merged (copied) into the VHD files of the virtual machine. After 40 minutes it is done “deleting” the virtual machine and it has been removed from the Hyper-V console.
The VHD and AVHD files from that virtual machine is still present at the storage location and it is up to you to delete those files manually because the Hyper-V Manager will only delete the virtual machine but not the actual files it consist of.
Okay – but what is the logic behind this seemingly unlogical behavior of the Hyper-V Manager? It basicly boils down to that even though you delete the virtual machine from the console you might have another use for the VHD file itself. Because the files have not been deleted and the VHD and AVHD files put together actually is the virtual machine as it “was” when it was deleted it makes sense to merge those together. You can then resuse that VHD file.
Okay - that´s fine, but what if you really just want to delete the virtual machine and do not have a need for the any of the files afterwards? And you do not want to wait hours before the delete is actually done.
Well – the workaround is pretty simple:
Apply the first snapshot before you delete the virtual machine, in this example that would be the Basic Install snapshot.
Another possible workaround is to remove the virtual hard drive from the virtual machine before you delete it as shown below.
But that logic unfortunately breaks down if you are using Virtual Machine Manager 2008/R2 (VMM). Because if you delete a virtual machine from within the VMM console, it will do the merge thing first, and that could take hours, and then it will delete the virtual machine from the VMM console and all the files associated with that virtual machine.
The reaon behind this is that VMM is actually calling a Hyper-V function telling it to delete the virtual machine and that function is the same one used by the Hyper-V console.