Hey–why does it sometimes take so long to delete a virtual machine from the Hyper-V console?

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.

VM in Hyper-V console

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.

Delete VM

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:

VHD files just before delete(new)

This is what it looks like 73 percent into the “delete” process:

Deleted 62 percent

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.

Done deleting

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.

Apply first snapshot before delete

Another possible workaround is to remove the virtual hard drive from the virtual machine before you delete it as shown below.

Remove HD before delete

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.

By | 2011-04-13T22:46:40+00:00 April 13th, 2011|Application Virtualization (App-V)|1 Comment

About the Author:

Coretech

One Comment

  1. Tony October 18, 2014 at 4:14 - Reply

    Hello,

    Thanks for your article. I think it is along the line of what I’m trying to do, but I am unsure. I have windows server 2008 r2, and I added the Hyper-V role to use it Remote desktop function. I loaded the 2008 r2 OS onto the virtual machine, and it takes up about 28Gb on my c: drive. My c: drive is only 80Gb, and I only have about 1Gb of free space left. If I want to uninstall Hyper-V role and the 2008 r2 OS to gain about 28Gb, what would be the correct process? Uninstall the Hyper-V role, and then delete the vhd and the avhd files? Will deleting these files have any affect on the 2008 r2 OS on the physical machine?

    If I can’t uninstall hyper-v and delete the 2008 r2 OS in the virtual machine, I guess my other option would be to reduce my d:, which has 800Gb of free space, and added to the c:.

    If you can give me any feedback or guidance, I would greatly appreciate it.

    Tony

Leave A Comment