Mastering Windows Server 2016 Hyper-V

(Romina) #1

Creating and Using Hyper-V Templates


In the previous section, a virtual machine was manually created, and all of the
attributes such as memory, CPU, network, and storage had to be configured. Then the
operating system had to be manually installed. Although PowerShell can help
automate this process, a much better option is to use a template, which is a virtual
machine configuration and virtual hard disk with a duplication-ready operating
system installed. This template can be easily deployed just by copying the VHDX file
and assigning it to a new virtual machine that is created from a template VM
configuration.


The first step is to create the VHDX file containing the operating system that is
suitable for duplication. Any readers who have ever deployed desktops will be used to
the idea of building out one “gold” desktop and then preparing it for duplication so
that it could be captured and deployed to many desktops quickly. Windows has been
using this method since Windows 2008, when the WIM format was introduced as the
method of installing Windows. Inside the WIM file is a deployed operating system
that has been prepared for duplication. All Windows installation does is to deploy the
content of the WIM file, which is why installation got faster between Windows 2003
and Windows 2008. When Windows is installed, various specializations are
performed, such as creating the security ID, creating the globally unique ID, and other
items. Many problems arise if different systems have the same SID, GUID, and other
items. For this reason, sysprep is a utility built into the operating system that removes
this unique information (the process is known as generalization), and once it is
removed, the operating system can be duplicated and started on the target. When that
happens, a specialization phase creates the required unique values and runs certain
critical processes to ready the copied operating system for usage. Once you have
deployed the operating system to a virtual machine and tailored it, run the command
at the end of this paragraph. This will generalize the operating system and shut it
down. You can then copy the VHDX file to a template area and use that template for
new virtual machines, essentially just copying the template to a new location for each
new virtual machine that should run the same operating system. It’s also possible to
launch sysprep.exe, and a dialog box will allow you to select the same options.
However, when you are using the full command line, the /mode:VM parameter can be
specified (covered in detail in Chapter 11, “Remote Desktop Services”), but it enables
sysprep to run in a mode that is optimized for virtualized hardware.


Sysprep.exe /generalize /oobe /shutdown /mode:VM


When a new virtual machine starts from a copy of your template, it will go through a
basic out-of-box experience that asks minimal questions regarding country, language,
keyboard layout, accepting the EULA (End User License Agreement), and a new local
administrator password. Those questions can be answered through the use of an
unattended installation answer file, which is how SCVMM automates deployments.

Free download pdf