共用方式為


Hyper-V generation 2 virtual machines – part 10

Part 1: Introduction to generation 2 virtual machines
Part 2: Networking and boot order
Part 3: Storage
Part 4: Keyboard for Windows 8 & Windows Server 2012
Part 5: Kernel debugging
Part 6: Secure Boot
Part 7: FAQ
Part 8: Manually migrating generation 1 virtual machines to generation 2
Part 9: Installing from ISO
Part 10: Utility for converting generation 1 virtual machines to generation 2 (Convert-VMGeneration)

The final part (at least for now, I’m hoping a guest author will write part 11) of this series on generation 2 virtual machines in Hyper-V re-visits conversion of a generation 1 virtual machine to a generation 2 virtual machine. Part 8 walked through the manual process, assuming it is possible. However, there is an easier way with a PowerShell script I wrote and recently released. Called Convert-VMGeneration.ps1, it can be downloaded from https://code.msdn.microsoft.com/ConvertVMGeneration. The script is intended to make life as simple as possible, reducing as many as reasonably possible manual post-migration fix-ups that may be required.

Convert-VMGeneration.ps1 is self-documenting – after downloading to a local drive, running get-help .\Convert-VMGeneration.ps1 –full will give you everything you need to know on how to use. I will assume that you have read part 8 of this series before use so you understand the three phases of conversion – capture, apply and clone.

A few tips worth mentioning:

  • Run reagentc /disable in the guest operating system prior to shutting down and converting (if reagentc /info indicates it is enabled). After conversion, in the generation 2 virtual machine, run reagentc /enable. This makes life a lot easier in terms of the Windows Recovery Environment and (lack of) manual intervention.
  • I strongly recommend you use the –Path parameter. Alternately, after a VM has been created, move the VM and its related storage to the right path using Hyper-V Manager. Note that if you subsequently perform a storage move, data-disks which were in use by the generation 1 virtual machine will no longer be valid from its perspective.
  • For the first few times of use, you might want to specify the name of the temporary .WIM file using the –WIM parameter, combined with –KeepWIM. That’ll save some time if a failure occurs during the apply or clone phases as you’ll not need to redo the potentially time-consuming capture phase. Using the -WIM parameter also makes it easier if you are running short of disk space and want to use an alternate location.
  • Be aware that you may not be able to start both the generation 1 and generation 2 virtual machines simultaneously (for example if they share a data VHDX). In reality, you really don’t want both machines on the network at the same time anyway. Be cautious of other implications too such as domain joined machine account passwords changing and so on.
  • Perform a move of the VM and all its data to another path after migration and you’ve verified the functionality of the converted generation 2 virtual machine. This will make it much cleaner to delete the old generation 1 virtual machine and clean up any old files which may be lingering.
  • The conversion performs a highly destructive step which completely wipes a disk. If everything is to plan, it’s the blank VHDX used as the boot disk for the generation 2 virtual machine. However, things could go wrong. For that reason, I strongly recommend you heed the warning (which cannot be suppressed) and make appropriate verifications. Should data loss occur for reasons such as coding error, no liability is assumed. If in doubt, export the generation 1 virtual machine, and import it onto a scratch box. Then do the conversion. That way, you are assured you will not lose anything important IF there is a bug.
  • Similar to HVRemote which some of you may have used, this script is not supported or endorsed by Microsoft Corporation.
  • Don’t close the PowerShell window while a conversion is in progress. Due to a bug in Windows, you may leave your system in a state whereby a drive letter is ‘leaked’ – it will be visible in Windows File Explorer, but unusable until the system is restarted. To cancel the script while it is progress, use Control-C and wait for it to clean-up instead.

Here’s an example of the conversion of a Windows Server 2012 virtual machine. The original virtual machine is highly available. The resulting generation 2 virtual machine will need to be made highly available after migration has completed.

clip_image002

Here’s an example where there are some (potential) issues to resolve. One is that there is an additional data partition on the boot disk for the source VM. Windows Recovery Environment was left enabled during the migration and will not operate correctly in the generation 2 virtual machine. Lastly, the original source boot disk was a differencing disk. Appropriate fix-ups may be required to mirror the configuration on the generation 2 virtual machine.

clip_image004

There are some VM configurations which aren’t handled, and the script will block the conversion:

  • The VM is running. The reason is simply that you cannot reasonably expect an operating system to continue running correctly if the firmware is fundamentally changed from under it.
  • Checkpoints (snapshots) are in use by the generation 1 virtual machine. The reasons partly relate to the above statement – an online checkpoint is equivalent to a running VM. While offline checkpoints could be converted in theory, there are further problems:
    • The mount-diskimage cmdlet that the script uses under the covers does not support .AVHDX files which are used by checkpoints. Further, the time to do the conversion would be prohibitive – each checkpoint would have to done individually.
    • Rebuilding the checkpoint tree with parent/child would be pretty much impossible – at best an individual offline checkpoint could be converted to a ‘standalone’ generation 2 virtual machine.
  • Hyper-V replica is enabled. The reason was simply my time to validate this scenario. In theory it should work. Obviously replica would need to be re-enabled after the conversion. The workaround is to disable replica prior to conversion, or use the “-IgnoreReplicaCheck” parameter.
  • When a guest cluster is configured in the generation 1 virtual machine using a shared VHDX. A highly available/clustered VM from the parent partition perspective works fine though. I am somewhat doubtful a guest cluster would come across cleanly, and have done no validation. The script hard blocks if any VHDX in the generation 1 virtual machine is shared.

I hope you find Convert-VMGeneration.ps1 useful. I’ll try to fix any bugs you report as time permits! A note for PowerShell aficionados reading the code – I make no apologies for my lack of PowerShell skills. This was the first time I’ve undertaken writing anything of reasonable complexity in PS. I’m sure there are many ways to make the code more powershellesque in efficiency.

So with that, I’ve reached the end of the planned parts of this series on generation 2 virtual machines in Hyper-V in Windows 8.1 and Windows Server 2012 R2. I hope you enjoyed them and found them and the conversion utility useful. As always, comments, questions and feedback are welcome.

Cheers,
John.

Comments

  • Anonymous
    January 01, 2003
    Allen - it's next to impossible to give you an indication. It's so highly dependent on the speed of your storage. Open Resource Monitor and go to the Disk Tab and sort by total (B/Sec). If the interim WIM and the new VHDX are still making a lot of reads/writes, it's still going. If they've stalled and the overall disk I/O is next to zero, then there's something else wrong. I guess you could take a comparative look at the size of the new VHDX to see how close it is to the source VHD(X) as well to determine progress, but it may not necessarily be a direct correlation in the case of the source being a dynamically expanding VHD(X)

  • Anonymous
    January 01, 2003
    Mur - yes, use the "-WIM" parameter to specify the full file path for where the interim WIM is stored.

  • Anonymous
    January 01, 2003
    John,Thanks for another great series of articles. Also enjoyed your SR-IOV insight emensly.A couple of small things:- Does a generation 2 conversion trigger a reactivation of the OS? (HAL being replaced?)- Having a problem with a 2012VM claiming integration comp. need upgrading. Doing so produces no change.VM has SR-IOV enabled.

  • Anonymous
    January 01, 2003
    I'm not the right person to comment on how Windows deals with reactivation triggers, although in the past it is true that hardware was a part of that. So on that basis, I would not be surprised if re-activation of non VL OS installations is triggered if a conversion is performed as generation 1 vs generation 2 hardware has significant differences. There is however a known bug you're hitting - there is a KB in the pipeline for publishing. When a 2012 VM runs on 2012 R2 and the VM is restarted with SR-IOV in use, we will incorrectly display that the Integration Services are out of date. This is display only. However, you should verify that they are indeed up to date by turning SR-IOV off temporarily.

  • Anonymous
    January 01, 2003
    There is no effect on licensing, although reactivation MAY be triggered due to the hardware changes depending on the SKU and VL vs non-VL.

  • Anonymous
    November 14, 2013
    The comment has been removed

  • Anonymous
    November 14, 2013
    The comment has been removed

  • Anonymous
    November 14, 2013
    The comment has been removed

  • Anonymous
    November 15, 2013
    The comment has been removed

  • Anonymous
    November 21, 2013
    Conversion worked on a DC (VM-2012R2), but unfortunately there is no Network Adapter at all installed now? Is it possible to get a "Microsoft Hyper-V Network Adapter" working manually? (I added such, but have "This device cannot start (Code 10)

  • Anonymous
    November 21, 2013
    Fridolin - thanks for reporting this. I assume the network adapter was working before the conversion. A question worth asking just in case. We can't think of any obvious reason this would be the case, and unfortunately code 10 is a very generic code. Can you try in device manager removing the device and letting it re-enumerate by right-clicking on the computer and scanning for changes to see if it comes back correctly. Also, windowsinfsetupapi.dev.log would be an interesting file to get ahold of to see if there any errors (you can email it using the link at the top right) if the remove/reinstall doesn't work. And lastly, if there's anything interesting in the event logs. Select the device in device manager, properties and on the events tab. Thanks, John.

  • Anonymous
    November 22, 2013
    Working again. I had some problems, because on my Server2012R2 (the virtualization host) the physical network adapter was gone completely after the update to R2  (ASUS-Mini ITX.... board) I checked what NIC was in and found new drivers on the Intel page, which are working perfectly [PROWinx64.exe for 64-bit (x64) editions of Windows Server 2012 R2*.] Then (after conversion to Gen2 - which by the way was working perfectly, just could not map the previously mapped ISO / CD Drive) just Do not start the VM but first go to settings, add Network Adapter => Virtual Switch => Ext .... Then start the new VM Gen2... and everything was fine. Again thanks a lot for your great support!

  • Anonymous
    January 04, 2014
    The comment has been removed

  • Anonymous
    January 04, 2014
    The comment has been removed

  • Anonymous
    January 04, 2014
    The comment has been removed

  • Anonymous
    January 04, 2014
    The comment has been removed

  • Anonymous
    January 04, 2014
    The comment has been removed

  • Anonymous
    March 12, 2014
    Hello John,
    Thanks for the utility, is there a way to change the temp path to another drive because I am currently getting the error

    " There is not enough space on the disk. The DISM log file can be found at C:WindowsLogsDISMdism.log error code 112

    Completed with error. Trace status code 830"

  • Anonymous
    March 14, 2014
    John...
    Thank you so much for your time and effort to create this script. I am currently in the process of testing it out. I am wondering if there is a way to tell how long a conversion will take to complete.
    I started the conversion on a VHD that is 30GB in size, and 4 hours later, it still says" Applying image. This will take some time..."
    Since I do not know how long the conversion will take, I am left wondering if the script has frozen or if it is still running.
    It would be helpful to know an average time per GB it will take to convert an image.

  • Anonymous
    March 25, 2014
    Is there anything that will convert a Windows 7 VM to Gen 2?

  • Anonymous
    March 25, 2014
    Duh, I should have read up more on Gen 2 VMs before asking my last questions. I see now why only Windows 8 and Server 2012R2 support Gen 2

  • Anonymous
    April 14, 2014
    Hi John,

    Thanks for your amazing script ! I tried it on few VM, works like a charm ! But on few VMs (our Exchange DAG), it keeps stucked a "bios" level with "Getting devices ready".

    What could be the mistake ?

  • Anonymous
    May 13, 2014
    John when I runnig this script I recived the error:
    CatgoryInfo: Security Error: PSsecurityException
    FullQualifiedErrorID: UnauthorizedAccess
    Can help me?

    Marcus

  • Anonymous
    May 15, 2014
    Just upgraded my virtual Exchange 2013 (SP1) server with this (after running two ADDCs since months as Gen2 :-)), working like a charm... THX again for this great tool.

  • Anonymous
    May 24, 2014
    Hi, What effect (if any) does this have on the license of the converted VM?

  • Anonymous
    June 24, 2014
    Conversion worked fine (it was a vmware to hyper-v converted machine - Gen1) but now something strange happens. The virtual machine is seen in Hyper-v hosts (Hyper-v 2012R2) and in failover cluster manager console but not in SCVMM 2012R2 console. All other virtual machines converted from VMware and newlly created are seen except this one converted.
    Any ideias?
    Thanks.

  • Anonymous
    November 07, 2014
    Great scrip thank you very much. I just did a test Win 8.1 VM and it worked great. A few notes:
    1) I got the warning "WARNING: WinRE is configured and will need manual fixing after migration" even though it was disabled already. No worries the Gen 2 booted right up.
    2) I found if you do a little maintenance on your Gen 1 VM first you can reduce your conversion time. I like to do a Disk Cleanup (2012 you need Desktop experience for this) first. Then I like to defrag twice on the VM first to do free space consolidation then a normal optimization. Finally I compact the VM's disk. This gets the VM disk as small as possible before the conversion. Just a personal preference I thought I would share.

    Now off to do my dev server VMs.

    Thank you very much once again!

  • Anonymous
    August 03, 2015
    Recently, Microsoft released an updated Demonstration VM for Dynamics AX 2012 R3 CU9. You can find it

  • Anonymous
    August 03, 2015
    Recently, Microsoft released an updated Demonstration VM for Dynamics AX 2012 R3 CU9. You can find it