Hyper-V: Background Merging of AVHD’s… When’s it done?

image

I think it might be best to start at ground zero with this topic and explain what a snapshot really is and how it work’s (if you already know skip a head…).  Hyper-V introduced a new feature called a snapshot – snapshots allow you to capture and save the point in time state of a running or saved virtual machine and then go back to that state at a latter point in time.  For example you can have a Windows XP RTM virtual machine running take a snapshot, install SP1, take a snapshot and install SP2 and then latter revert back to the SP1 snapshot and either discard the SP2 installation or keep it around so you can apply that state latter.  Snapshot’s are pretty handing in this regard – you can create pretty extensive tree’s of snapshots and you can rapidly apply specific states to virtual machines.  Under the covers snapshots primarily use a technology that was implemented back in the pre-Microsoft days of Virtual PC called differencing VHD’s.  What a differencing VHD effectively does is point back to a parent VHD for it’s data but any updates made to the VHD reside in the new differencing VHD and subsequent requests for that same data will be overridden by the child differencing VHD.  These parent child relationships can get many levels deep and a parent can have many children – however if a parent is ever modified it’s children's state is now invalid since the child was unaware of the changes.  So back to snapshots – when a snapshot is taken we create a new differencing disk to point the virtual machine to and we call it an AVHD or automatic VHD since it was created automatically by requesting the snapshot – at the same time we will save off the virtual machines running state if it’s running including it’s memory state and it’s device state (network adapter IP etc…).  When you revert back to a previous snapshot you reload the memory and device state and the VM is pointed at a new AVHD from the parent of that time.  And that’s snapshots in a nut shell…

OK now back to topic at hand – when you delete a snapshot the next time the virtual machine is off or saved we will merge the AVHD created by the snapshot back into it’s respective parent…  We do this automatically and in the background – so lets say you wanted to know when it’s was done programmatically…  It’s not too hard just run the following query to see if any merges are going on presently - PS C:\> Get-WmiObject -Namespace "root\virtualization" -Query "select * from Msvm_ConcreteJob" | Where {$_.ElementName - eq 'Merge in Progress'} .  Below you can see the full output of that query when a merge is occurring.  Hope this helps!

 

PS C:\> Get-WmiObject -Namespace "root\virtualization" -Query "select * from Msvm_ConcreteJob" | Where {$_.ElementName -eq 'Merge in Progress'}

__GENUS : 2 __CLASS : Msvm_ConcreteJob __SUPERCLASS : CIM_ConcreteJob __DYNASTY : CIM_ManagedElement __RELPATH : Msvm_ConcreteJob.InstanceID="E3675DEB-A13C-440D-AEAD-B6CEB5ADF1D7" __PROPERTY_COUNT : 36 __DERIVATION : {CIM_ConcreteJob, CIM_Job, CIM_LogicalElement, CIM_ManagedSystemElement...} __SERVER : TAYLORB __NAMESPACE : root\virtualization __PATH : \\TAYLORB\root\virtualization:Msvm_ConcreteJob.InstanceID="E3675DEB-A13C-440D-AEAD-B6CEB5ADF1D7" Cancellable : True Caption : Merge in Progress DeleteOnCompletion : False Description : Merge in Progress ElapsedTime : 00000000000000.000000:000 ElementName : Merge in Progress ErrorCode : 0 ErrorDescription : ErrorSummaryDescription : HealthState : 0 InstallDate : 16010101000000.000000-000 InstanceID : E3675DEB-A13C-440D-AEAD-B6CEB5ADF1D7 JobRunTimes : 1 JobState : 4 JobStatus : LocalOrUtcTime : 2 Name : Merge in Progress Notify : OperationalStatus : {0, 0, 0} OtherRecoveryAction : Owner : PercentComplete : 13 <----Percent Complete Priority : 0 RecoveryAction : 0 RunDay : 0 RunDayOfWeek : 0 RunMonth : 0 RunStartInterval : 00000000000000.000000:000 ScheduledStartTime : 16010101000000.000000-000 StartTime : 16010101000000.000000-000 Status : StatusDescriptions : {, , } TimeBeforeRemoval : 00000000000500.000000:000 TimeOfLastStateChange : 20090309234922.000000-000 TimeSubmitted : 16010101000000.000000-000 UntilTime : 16010101000000.000000-000

Taylor Brown
Hyper-V Integration Test Lead
https://blogs.msdn.com/taylorb

clip_image001