Thursday, January 10, 2013

Quick Hyper-V VM Templates

Here's a quick guide on how to clone Server 2012 machines in Hyper-V:

Assumptions:  

  • You've decided on a standard for you VM folder structure. I won't go into detail in the steps, but if you haven't I'll make a recommendation here. This is how I do it: 
    • {Drive}:\VM\VMName\Virtual Hard Disks
    • {Drive}:\VM\VMName\Virtual Machines
  • You know the basics of VM creation, etc. Perhaps I'll cover that stuff in another article. :)
  • You're making a template server 2012, which comes with sysprep. If you're doing another MSFT OS, you should DL and leave sysprep on the image before you shut it down. If it's Linux don't worry about it.

Make the Template

Note: Do not take any snapshots of the template machine because our simple copy method won't work with snaps. If you must have them, you'll need to use the Hyper-V export functionality.
  1. Setup a new Hyper-V VM from scratch. The defaults on hardware allocation should be fine unless you're templating an older OS that uses a SMP or Uni processor kernel; in that case give it one or multiple CPUs as you desire. Set the boot disk size to your standard size now and keep it thin provisioned. (you can expand after building if needed) I recommend 60GB or more for newer versions of Windows server. After a couple years that SXS folder will get pretty big.  
  2. When naming the machine, pick something meaningful like "_Template_Server_Datacenter_2012_NoGUI" or "ZZZ_Template_CentOS_6_3" or "_Template_OS/2_3_0_Warp_with_emulated_MCA"
  3. After doing basic setup, patch the machine up as much as possible.
  4. If you want to install/configure anything else on this template so that it will be present on any machine, do so now.
  5. (Windows Only)Navigate to the sysprep folder. (c:\windows\system32\sysprep on 2012) and execute sysprep.exe
  6. (Windows Only)On the sysprep screen, select "Enter System Out-of-Box Experience (OOBE)" (that's a mouthful) and check "Generalize" then change the "Shutdown Options" to "Shutdown" and click "OK". Sysprep will do the work and then shut down the server.


  7. Document the admin password & shut it down. 

How to Use the Template

  1. Make a new folder for your VM per your standards.(named appropriately, etc.)
  2. Copy the vhdx (or vhd) to your new folder. 
  3. In the HyperV manager create a new VM (named the same as you did in step 1) and spec the hardware appropriately but stop when you get to the disk. 


  4. Specify the disk you just copied over from the template and finish the wizard.
  5. Fire up the new VM
  6. (Windows Only) Complete the "OOBE" including entering a product key and a new admin password.
You did it! Depending on how often you use the template it will eventually make sense to fire up the template as a vm, customize it, patch it, and re-sysprep it. Note that according to this, the SID is generated upon reboot, so this template should provide a unique SID every time. 

2 comments:

Unknown said...

Nice and clear Toby, many thanks.

Toby Meyer said...

Thanks Lee!