TOP

Hyper-V: Making Template Virtual Machines

Hyper-V_Manager Using Windows 7 and Windows Virtual PC has it’s benefits. It’s useful for managing a few virtual machines and you get decent graphical quality on the virtualized machines (Windows Aero Desktop). The biggest issues with Windows Virtual PC, is the fact that it cannot virtualize 64-bit OS. That means if you need to test Windows Server 2008 R2, you can’t virtualize it with Microsoft’s products but have to turn to third parties. If your need for virtualization is a bit more demanding, you can step it up with Hyper-V, which of course supports 64-bit virtualized OS. Hyper-V is only available with Windows Server 2008 and upwards.

Let me tell you how I have configured and setup my own virtual machine templates using the latest Windows Server 2008 R2 with Hyper-V.

Base Virtual Machine

The first thing to do is create a couple or more virtual machines where you run a normal installation of any OS you need. I made myself two different machines, one with Windows 7 and another with Windows Server 2008 R2.

I won’t go into details on how you setup a new virtual machine with Hyper-V, you just go through the wizards to create a new machine and you choose which boot device you want to use (physical DVD, ISO file, network share).

When the machine is fully installed and you’re on the desktop, make sure you patch the OS fully. You can additionally install anti virus or other software if needed. Additionally you might want to install the Integration Services, if you are using other OS than Windows 7 and Windows Server 2008.

Both of those comes with Integration Services pre-installed. Avoid everything that you don’t want to have on every new machine.

Step #1: Shut down your machine and make a backup copy of the VHD. This is useful when you in the future want to re-create the base template. Do this copy before you run sysprep.

Step #2: Boot the machine (not the copy you just made) and run sysprep. Sysprep is now included with the latest versions of Windows, you will find it under C:\WINDOWS\SYSTEM32\SYSPREP\SYSPREP.EXE.

Step #3: Configure sysprep to do an OOBE, make sure you check the Generalize button or else it will not create a new SSID. Choose Shutdown in the Shutdown Options.

sysprep_options

Step #4: Copy your VHD once again, this time you are making copies of all the new machines you want to create. My advise is to make the finished sysprep image read-only, so you won’t boot and destroy the finished base template.

Creating Virtual Machine From Base Template

Now it’s time to create new virtual machines that will use the sysprepped VHD copies we have made. I created multiple copies of the server that I will use for development and testing. One of them is for Microsoft Office SharePoint Server 2007, one for SharePoint 2010, another for Team Foundation Server 2010 and a bunch of others, even one for Ubuntu Linux.

Create a new virtual machine using the wizard as you’ve done before, only that this time you’ll choose to use an existing virtual hard disk.

new_virtual_machine

Start the newly created virtual machine and your new machine will start and ask you a few standard questions like machine name. After a few minutes, you should have a completely new machine that is distinct from the base template, it does not share the same SSID or network MAC address.

sysprep_startup_2

Set_Up_Windows

Final Notes

I was amazed how simple and easy it has become to make your own template machines, with both Integration Services and SYSPREP now pre-installed with the OS (Windows 7 and Windows Server 2008 R2). This makes the management, testing and development with various instances of the OS much easier than it ever has been.

22 comments. Leave a Reply

  1. Phil

    Thanks v much SondreB. I am impementing this for a client and don’t have SCVMM- so this was extremely useful!

  2. Pingback: Deploy virtual PC based on snapshot using Hyper-V - Admins Goodies

  3. Hyper

    Hi, very useful guide, thanks!

    However, after creating a new VM from the template, it is stuck in an endless loop, saying “Windows could not finish configuring the system…..” – it restarts, and pops up the same message.

  4. Hyper

    I googled the issue and it turns out it was Avira – I uninstalled it in the original image, did the SYSPREP again and now it works like a charm.

    Thanks again for a very helpful tutorial :-)

    • SondreB

      Thanks and I’m glad you found it useful!

      • David

        Hello. This is very interesting, but what if I want to clone a production server? My dev team are forever asking for an exact copy of a server
        David

  5. Paul

    Thanks very much, this was really clear and straight forward instructions.

  6. Thabang

    Thanks for this enlightening info. The only part I am still not clear about is when you deploy vm’s from the template and you point them to the existing vhd. Does this mean that you will have all you deployed vms sharing a single vhd file or do you have to make a copy of this file for every deployment before the deployment?

    • SondreB

      After you have created a template, what you can do is either copy the full VHD or create a differencing disk. I suggest using differencing disks if you are building multiple machines from the same base OS. It’s easy to create a differencing disk, just choose New>Hard Disk in the Hyper-V Manager and select the Differencing type. Then you select the base, and then location of any changes you make. After making a differencing disk, you can move on to making a Virtual Machine which then points to the differencing .VHD file.

  7. Stephen Campbell

    Couple questions.
    1. So I can’t deploy multiple Virtuals using the same HyperV.vhd I just created. Gives me an error.
    So I don’t save any time, like in ESX, where I can right click the template and just deploy from image.
    2. After sysprepping my new build, I couldn’t get back into the machine. I guess it reset all my user account passwords. Sigh. Not ideal. Luckily, I had the before build .vhd still available to use.
    3. To piggy back on issue 1. This means, that for every new build I create. I have to manually copy a new .vhd from the original working one. So no difference.

    • SondreB

      Creating new machines should be done using the differencing hard disk option. Then all new machines will be based around the sysprepped base .vhd and only write changes that occurs after. Just be sure to never boot from the base image after you start making differencing disks on it. I’m sorry that your machines was reset, but luckily you had backups :-D

      • Sachin

        Running Sysprep remove the Activation Key. Is there any way to create a template like in VMware and use it without loosing the windows activation? Much thanks.

  8. James

    Can the template be already in our active directory domain?

  9. Anwar

    Thanks a lot . It worked without any issues.

  10. Amita

    Hi, This is my first time working Hyper-V. Can I get some help from you? Please let me know. I am trying to create my Dev environment template using hyper -v

  11. Dominic

    Thanks for the tip.

    btw, you should have a look at this: http://pmilev.blogspot.ca/2011/02/create-templates-in-hyper-v.html
    it looks like a ripoff of your page …
    He didn’t even bother to copy the images, they are hardlinked to your site.

    GL.

    • SondreB

      Thanks for the comment Dominic! All my work is released under Creative Commons and I would like anyone who re-publish my content to mention my name. Sharing ideas and information is never bad, so I have no problems with anyone ripping off any of my content. Thanks anyway :-)

  12. # PowerShell Script for creating a new server from a sysprep’d .vhdx (you will have to create the sysprep’d vhdx and make sure the paths in the copy command are specific to your environment)

    $newservername = Read-Host “Enter the new VMName”
    $CPU = Read-Host “Enter the number of CPU”
    copy “C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Templates\SV2012.vhdx” “C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Virtual Hard Disks\$newservername.vhdx”

    New-VM -Name $newservername -BootDevice IDE -VHDPath “C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Virtual Hard Disks\$newservername.vhdx” -MemoryStartupBytes 536870912
    Get-VMSwitch | Connect-VMNetworkAdapter -VMName $newservername
    Set-VMMemory -VMName $newservername -DynamicMemoryEnabled $true
    Set-VMProcessor -VMName $newservername -Count $CPU
    start-vm $newservername

  13. DavidD

    Good write up! I am new to Hyper-V after using ESX for the last 5 years. I am learning all the little tricks that I am used to being able to do with a few clicks is in vSphere. Kudos to SondreB for this one. What would we do without templates!

  14. Sadiq

    Great Work.
    You made my life easy for lab setups

  15. Pingback: Hyper-V and SystemCenter prep | RaSor's Tech Blog

  16. Pingback: SBS 2011 to 2012R2 Standard with Essentials Service and 365 | The-IT-Blog

Leave a Reply

Your email is never published nor shared.

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>