What happens when I delete a snapshot? [Hyper-V]

What happens when I delete a snapshot? [Hyper-V]

Rate This
  • Comments 8

A lot of people have asked me what happens “under the covers” when they delete a snapshot.  Unfortunately, the answer is relatively complicated as there are multiple things that could happen.

As previously discussed – a snapshot is composed of a configuration file, saved state files and differencing disks (AVHDs).  When you delete a snapshot the snapshot configuration file and saved state files are always deleted immediately – and the snapshot entry is removed from the user interface.

What happens to the AVHD depends on the situation of the snapshot and the state of the virtual machine.  Here I have a virtual machine setup with a bunch of snapshots:

snapshot3

Let’s look at what would happen if I deleted various snapshots associated with this virtual machine:

  1. Snapshot 4

    If I delete this snapshot – the AVHD will be deleted immediately.  There are no other snapshots that refer to this snapshot, and the virtual machine is not currently running off of it – so it can be quickly and easily deleted.

  2. Snapshot 1, Snapshot 3, Snapshot 5

    All three of these snapshots have a single other snapshot dependant on them (or in the case of Snapshot 5 – the running virtual machine).  This means that if they are deleted their AVHD files will be merged into the chain.  AVHD merging can only happen when the virtual machine is not running – so the AVHD will remain while the virtual machine continues to run but will be merged as soon as the virtual machine stops.

  3. Snapshot 2

    Snapshot 2 has two snapshots dependant on it (Snapshot 3 and Snapshot 5).  As such we will do nothing to the AVHD file when this snapshot is deleted.  We could merge the AVHD into both of the branches that depend on Snapshot 2 – but this is almost guaranteed to end up using more disk space – which could result in the whacky scenario where deleting a snapshot would fail because there was not enough space available.  Note that if Snapshot 2 were deleted, and later on both Snapshots 3 and 4 were deleted – we would detect this and merge the AVHD for Snapshot 2 away as soon as possible.

This answer has probably raised some questions in your mind – so let me take a shot at answering some of them:

  • Why do you call this “deleting a snapshot” when there could still be files left around afterwards?

    In all three cases above the “snapshot” is deleted.  Which is to say that the point in time image of your virtual machine is gone, and you can no longer go there.  If you had an important document that only existed in a specific snapshot of a virtual machine – and you deleted that snapshot – then the document is gone.  It does not matter whether we are deleting or merging the AVHDs under the covers- the snapshot is still effectively gone.

  • Why not use a different word than “delete”, like “remove”, as “delete” carries very specific connotations in my mind?

    This is an argument that I have often had with our text team.  The two main arguments for using “delete” are as follows: 1) From an end user impact, “delete” – with all of its connotations – is appropriate.  The fact that it does not line up completely with what is happening under the covers is a far removed secondary point. 2) Where ever possible we try to stick to known and established computing terms.  This aids in the process of localization, and is easier for users who do not have English as their native language.

  • Why not say “delete snapshot” when the AVHD is going to be deleted and “merge snapshot” when the AVHD is going to be merged?

    Today all of this logic is part of the core platform – and the only option exposed through our WMI interfaces is to “delete” a snapshot.  If we changed this it would place a burden on anyone scripting / programming to our interfaces where they would have to determine whether it was appropriate to merge or delete the snapshot.  Also – many people would be confused by what “Merging a snapshot” actually meant.

Cheers,
Ben

Leave a Comment
  • Please add 2 and 5 and type the answer here:
  • Post
  • First: Thanks for your blog!!  It’s always well written and very informative.

    My questions are somewhat off-topic and pertain to the next version of Hyper-V (Windows Server 2008 R2)

    1) I've seen max number of processors used by a Hyper-V Server has been increased, but I don't see anywhere talking about increasing a Vm's assigned processors.  Will the max number of processors per VM be increased from 4?  to perhaps 8?

    2) Will Copy and Paste work like in a RDP window?  (and like VMware's VM management tools: Vi Center, Vm Server, Vm Workstation).  I know I can always open a RDP window, but I do software dev + testing and spend a lot of time in a bunch of different VMs and find the Hyper-V Manager's [Connect...] *much* more convenient.  Except when I need to copy and paste text into (or out-of) the VM - it's a big a pain if I need to copy any more than a little text (typed text takes too long and truncates after a just a too few characters).  And it's a pain to copy text from the VM to my host - I typically keep a .txt file on a network share to replace the missing copy and paste functionality :-(

    Other than these two issues, I'm becoming a Hyper-V convert and slowing leaving behind the world of VmWare, ESX, VmWorkstationa and VmServer.

    Also, are there any other interesting UI or performance enhancements to the next Hyper-V version?  I’m waiting for the RC before I try out Windows Server 2008 R2.

  • Great article, however how could you "shrink" or "defrag" the disks after deleting some snapshots, I undestand if you delete from a sub-tree they would merge but I am having a hard time to makde this snapshots cleanup reflect in to the disk size.

    I have several Images set for differents projects and the snapshots grow daily, I have exported them and obtained the same size of the images I have exported with less snapshots, as being said the snapshot deletion does not "flush" data from the disk, what would be the solution?

    Thanks!

  • How can we detect that a merge is going on in the background?

  • Good article - thanks. I used it as the basis for my snapshot cleanup process...

  • "Also – many people would be confused by what “Merging a snapshot” actually meant"

    If they are confused about that they shouldn't be in IT

  • What is the effect of running off a snapshot over a long period on a highly transactional server like Exchange. I can only imagine this will have a advers effect on normal operation and backup operation.

  • Well, it is still does not works as described here.

    I had a single snapshot, afterthat the guest machine runned several days.

    I did "delete snapshot" action, which is supposed to merge existing single AVHD with the original VHD.

    The snapshot indeed disappeared from UI.

    I shut down the machine, and started the machine again.

    The machine did not merged AVHD with VHD, but happiliy continued to use AVHD.

    Now i need to merge these VHDs manually.

    I have a great respect to mircrosoft, but, MS folks, by yourselves you just push people to try VMWare, how one can resist ?

  • <rant>Why the heck cant it say merge when you merge a snapshot, and delete when you delete one. Everytime I have to go spend 20 mins googling to make sure I dont revert my virtual machine back to some worthless state it was in months or years ago... This entire system is semi retarted.. If you run on a snapshot for too long and dont have enough disk space to merge the snapshot into the vhd - it will basically crash your host!! Grrr...</rant>

Page 1 of 1 (8 items)