How to create a Hyper-V VM template without VMM

Windows Server 2012 R2

In this post I will look at creating a virtual machine (VM) template that you can use to quickly deploy new VM’s from, without having to install and patch them each time.

It is particularly useful if you are in a small Hyper-V environment and don’t have System Center Virtual Machine Manager (VMM).

The beauty of using a template for VM deployment is standardisation. You deploy a known configuration which can be pre-patched which reduces time during the post deployment tasks.

1. First, create a VM, install the operating system and patch it. Unfortunately you have to do this at least once. In the image below you can see I’ve created a gerenation 1 and generation 2 Windows 2012 R2 virtual machine template.

Hyper-V Manager with generation 2 template

2. On your template VM browse to C:WindowsSystem32Sysprep folder, and run Sysprep. Select the option to Generalize, and select Shutdown from the drop down menu.

Sysprep

3. In the Hyper-V Manager export the VM, right click your template VM and select Export.

Export template vm

4. Select a folder and click Export.

Export Virtual Machine
If you selected mostly default settings when creating your virtual machine template it should only take a minute or so to export. You now have a known good VM template located in D:\Templates.

I would leave the original virtual machine template in Hyper-V Manager, as every few months after more patches have been released you will want to update it and create a new template.

Now let’s look at how to deploy a new virtual machine from the template. It’s not just a case of selecting Import in the Hyper-V Manager, because the exported virtual machine and it’s disks still exist and when you import a VM you don’t have the option to rename them.

1. Create new VM without the disks, select New then choose Virtual Machine, configure the machine, selecting the same generation as the template you created, but CPU, memory and networking settings can be different. When you get to the Connect Virtual Hard Disk option, select Attach a virtual hard disk later, click Next and Finish.

Connect Virtual Hard Disk

2. Browse to your template VM folder (D:\Templates\Win 2012 R2 G2\Virtual Hard Disks) and copy the VHDX file locally.

Copy VHDX

3. Rename the copied VHDX to be the same as the virtual machine you have just created. In the example below, Phoenix.VHDX

Rename VHDX

4. Cut and paste the disk into the default location on your Hyper-V server for your VHDX files. In this example, D:\Hyper-V\Virtual Hard Disks.

5. In Hyper-V Manager, right click the new VM you have deployed and select Settings, then select the SCSI Controller option (for Generation 1 virtual machines, select the IDE Controller 0). Highlight Hard Drive and click Add.

SCSI Controller Add Hard Drive

6. Browse to D:\Hyper-V\Virtual Hard Disks and select the VHDX file you cut and pasted earlier in step 4. Click Apply.

Hard Drive

7. Now go to the Firmware option, select the hard drive you have just added and click Move Up, so it is the first boot entry. Click Apply. Click OK.

Firmware Boot Order

You can now boot the virtual machine, once it has finished detecting devices it will run through a short wizard to select the language, license terms and set the administrator password, and you’ve got a patched virtual machine ready to be deployed.

Related Posts:

1. Windows update fails on Hyper-V 2012 R2 generation 2 virtual machines

2. Windows Server 2012 Hyper-V Best Practices

3. How to convert a Hyper-V VHDX to VMDK for VMware Workstation

4. How to enable Data Deduplication in Windows 2012

5. How to enable Windows 8.1 Windows 2012 R2 dual boot – boot to VHD

16 thoughts on “How to create a Hyper-V VM template without VMM

  1. adrian

    Thank you. In your opinion, can that be image be uploaded to Azure. And second do you think its possible to ‘export’ the underlying OS (not HyperV image) such that one could also use in VMware VSphere, Amazon AWS (?)

    Reply
  2. Cirius Lee

    This procedure will fail after a certain number of syspreps. After patching your base image, you should take a snapshot/checkpoint before running sysprep. Then after sysprep and shutting down the guest, you can export the post -sysprep state safely to make a deployment template. Then revert/apply the pre-sysprep snapshot, and remove the snapshot. Now you are in a pristine state, ready for patching all over again the next month. Just remember to save a snapshot before you sysprep again, and to revert to it after exporting your deployment vhd. each month.

    Reply
    1. OxfordSBSguy.com

      Hi Cirius, good point, we’ve recently been doing some physical imaging and came up against the three sysprep limit.

      I’ll update the post to include the checkpoint step.
      Thanks,
      Carl

      Reply
    2. Dave

      Isn’t that going to make the patch list longer and longer each month? Perhaps I am understanding you wrong….?

      Reply
      1. srslygtfo

        Actually, no it won’t increase the number of patches you run each month. The Checkpoint will save the state of the freshly patched image, BEFORE sysprep runs. Reverting to the checkpoint will undo the sysprep step, not the patching you did for the month.

        Reply
  3. Patrick

    Hi,
    if a create a snapshot and export the vm, the vhdx file does not contain the sysprep-part (because its saved in the corresponding avhdx-file). So if I copy the .vhdx file and use it for the new vm if have to do a manual sysprep. Is there any solution for it?

    Kind regards
    Patrick

    Reply
    1. Just some guy

      I was wondering the same thing as Patrick; I followed the referenced steps but the cloned VM hasn’t been sysprepped when I boot it.

      Reply
      1. OxfordSBSguy.com Post author

        I’ve not had chance to test Cirius’s method yet. When I have I’ll post my findings.
        Carl

        Reply
  4. Simn

    Hello Patrick,
    I’m just about done building an image which is Server 2012 R2, SQL Server 2008 + Reporting + Integration, SQL Server 2012 + Reporting + Integration.
    I was hoping to clone it but I read that sysprep + sql isn’t too good.
    I’m already past the SQL installs and missed the ‘prepare image’ install option (which I’m not sure works for Report Server etc.).
    Given that I probably only want two vms on separate networks (LAN & DMZ) can I just maybe copy / export / import the files?
    Cheers,
    Simn.

    Reply
    1. OxfordSBSguy.com Post author

      Hi Simn,

      If this was me and the server is going into production I’d start over and do it again. I’ve no exeprience of Sysprepping SQL but I’d always try and stick to best practices. A little extra time now could save you a lot of support in the future!

      Cheers,
      Carl

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.