Virtual PC Guy's Blog

-- Ben Armstrong, Virtualization Program Manager

Talking about core virtualization at Microsoft (Hyper-V, Virtual PC and Virtual Server).

Welcome to MSDN Blogs Sign in | Join | Help

Virtual Machine Snapshotting under Hyper-V

A number of people have been asking me how snapshots actually work "under the covers". So here we go: When you take a snapshot of a running virtual machine:

  • We pause the virtual machine.
  • We create a new differencing disk for each virtual hard disk and hook it up to the virtual machine.
  • We make a copy of the virtual machine's configuration file.
  • We resume the virtual machine (note that this happens so quickly that you do not know that the virtual machine was paused at all.
  • Once the virtual machine is running again we start saving the contents of the virtual machine's memory to disk.
  • While this is happening we monitor memory activity inside the virtual machine and if the the guest operating system attempts to modify memory that we have not copied, we intercept the write attempt and copy the original memory contents then allow the write to go through.

Once the snapshot is completed we have a set of the virtual machine configuration file, the virtual machine saved state files and the snapshot differencing disks (.AVHDs) stored in a folder under the virtual machine's snapshot directory.

This is now treated as a read-only "point in time" image of a virtual machine.  You can apply a virtual machine, in which case we set the virtual machine to start from a copy of the snapshot.  You can change the virtual machine settings after applying a snapshot - but you cannot change the snapshot settings themselves.

You can also delete a snapshot.  If you delete a snapshot that has no descendants (snapshot with differencing disks that reference the snapshot being deleted) then the files associated with the snapshot will just be deleted.  If you delete a snapshot with only one descendant the configuration and saved state files for the snapshot will be deleted and the snapshot differencing disks will be merged with those of it's descendant.  If you delete a snapshot with more than one descendant the snapshot configuration and saved state files will be deleted - but the differencing disks will not be merged until the number of descendant snapshots is reduced to one.

Cheers,
Ben

Published Tuesday, March 11, 2008 2:07 PM by Virtual PC Guy
Filed under:

Comments

# re: Virtual Machine Snapshotting under Hyper-V

A question with snapshot technology.   This is more "trivia" than complaint.

Shadow Copy

DPM

Hyper-V

All are limited to 64 entries.   Is this a present limit to all three or just an "arbitrary" number than can be changed in the registry?

Thanks

BTW Just DYING to see the release of Hyper-V.  Can't wait to get drivers for Vista and others in there!

Excellent job on it so far Microsoft, keep up the good work!

Tuesday, March 11, 2008 9:00 PM by Sean Kearney

# re: Virtual Machine Snapshotting under Hyper-V

Great article, Ben, as usual!

On a side note, I published an article, "Getting Networking to Work on Hyper-V," referencing your article on Hyper-V networking.

Read it here: http://www.expta.com/2008/03/getting-networking-to-work-in-hyper-v.html

Jeff

Wednesday, March 12, 2008 11:06 AM by jguillet

# re: Virtual Machine Snapshotting under Hyper-V

Is there any performance hit when I have snapshots? For example, say I build a base server, snapshot, install software, snapshot again, promote it to a DC, and snapshot again.

Does the VM "read" through all these snapshots, thereby impacting performance?

Wednesday, March 12, 2008 11:18 AM by Ken

# re: Virtual Machine Snapshotting under Hyper-V

I think there's still more than meets the eye here..

My observation -

Create a snapshot and you see the .avhd file appear in \snapshots\guid

But it isn't read only - this file gets bigger. What' s interesting is the behaviour when you apply the snapshot, the .avhd CHANGES FILE NAME and reverts back to the size when I took the snapshot.

So I'm currently a little unclear about where the "third" virtual disk file is:

1 = the original .vhd which doesn't get touched once you snap (until you 'collapse' snaps)

2 = the read only snapshot .avhd

3 = the one where the writes are going :)

Wednesday, March 12, 2008 12:44 PM by Andy Hawkins

# re: Virtual Machine Snapshotting under Hyper-V

I have a question too:

what about moving a VM with its snapshots to another Hyper-V Host Server?

Thanks for your great work Ben.

Greets from Italy,

Simone

Wednesday, March 12, 2008 5:47 PM by Simone

# re: Virtual Machine Snapshotting under Hyper-V

I too would be very interested in learning what it would take to move a VM to a different Host.

Thanks for the great info!

Andy

Thursday, March 13, 2008 12:18 PM by Andy Schneider

# re: Virtual Machine Snapshotting under Hyper-V

I have attempted to trigger the merge process by deleting my snapshots, as indicated above.  The XML file has the global setting of <disk_merge_pending type="bool">True</disk_merge_pending>

However, it has been several days with the machine OFF and still no merge.  

Can I force this merge to start?  Which service or process is responsible for the merge?

Monday, March 17, 2008 10:56 AM by Darrin

# re: Virtual Machine Snapshotting under Hyper-V

Ken -

Yes there is performance hit, but it is minimal.

Simone -

You need to export the VM and then import it on the other computer.

Darrin -

No, but there are bugs in the merging code that we are trying to fix.

Cheers,

Ben

Thursday, March 20, 2008 4:21 PM by Virtual PC Guy

# re: Virtual Machine Snapshotting under Hyper-V

I've deleted all the snapshots in Hyper-V. But in the Snapshots folder, the snapshots and the avhd files are still there and the VHD has not been update. When and how do the avhd, and other data get saved back and committed to the VHD file?

You mentioned a bug in the merge code. If the bug gets fixed, will my problems be sorted out as well and the merge will handle the saving back into the VHD?

Monday, March 24, 2008 4:51 AM by Carlo

# re: Virtual Machine Snapshotting under Hyper-V

Hi Ben,

Thanks for another informative article - I'm a little confused though and hop you can help.  If I create a snapshot then carry on working, am I using the original VHD or the AVHD?  I'm currently fighting with the AVHD merge bug and trying to rescue my VHDs to upgrade from Hyper-V beta to RC0 and wondered if it's safe to work with just the VHD (or will that take me back in time to the point when my first snapshot was taken?)

Regards, Mark

Wednesday, March 26, 2008 12:52 PM by Mark Wilson

# re: Virtual Machine Snapshotting under Hyper-V

I am interested in changing a VM snapshot via the WMI API.  Any idea if this is possible?  I can start/stop machines, change lots of settings, but I don't see this (in RC0).

Thursday, April 03, 2008 1:40 PM by tim
New Comments to this post are disabled
 
Page view tracker