Chapter 7. Templates

Templates are model virtual machines that are used as a convenient and efficient way to create new virtual machines of the same type and content. Templates provide a shortcut that reduces the time required to build virtual machines. A template can contain an operating system only, or can contain all applications required by a particular department. You can also control the use of templates by defining permissions to use and administer templates.

7.1. Creating Templates from Existing Virtual Machines

A template can be created from an existing virtual machine that has been configured to meet the needs of several individuals in the organization, and has been sealed with Sysprep (Windows machines only) or a similar tool.
Before selecting an existing virtual machine as the source for a template, ensure that the virtual machine is general enough for this purpose. A virtual machine that is too specific to a particular user or group may require a lot of changes, and is therefore not practical to use as a template.

To create a template from an existing virtual machine:

  1. Click the Virtual Machines tab.
    The Virtual Machines tab displays a list of all virtual machines in the system.
  2. Select the virtual machine that you want to use as a basis for the template definition. Ensure that the virtual machine is powered down and has a status of Down.

    Note

    Take a snapshot of the Virtual Machine at this stage if you wish to use the virtual machine (as a virtual machine) after it is used to create a template.
  3. Click Make Template.
    The New Virtual Machine Template displays, with the details of the selected Virtual Machine.
  4. Enter, accept or change the following information. Name and Description are typically the only fields in which new information is to be entered. The rest of the fields are taken directly from the existing virtual machine.
  5. Define the Host Cluster and Storage Domain for the virtual machines that will be created with this template. By default, these are the same as the source virtual machine, but you can select from the list, if there are multiple clusters and domains in the data center. The template is a copy of the virtual machine, hence the requirement for the Host Cluster and Storage Domain.
  6. Optionally, select the Make Private option to restrict access to the template. Templates marked as private are only available to their creator, and users with the Super User role.
  7. Click OK. The virtual machine displays a status of Image Locked while the template is being created. The template is created and added to the Templates tab. Depending on the virtual machine disk image size, this may take a long time. During this time, the action buttons for the template remain disabled. Once created, the action buttons are enabled and the template is ready for use. For example, the newly created template displays in the list of templates in the Template field on the New Virtual Machine dialog box.

Note

Before a Windows template is ready for application, you must first run Sysprep (or a similar tool) to generalize the Virtual Machine and remove "specific" personalization. Failure to do so will cause conflicts when multiple virtual machines from an un-generalized Windows templates are run. In general, templates of Linux virtual machines do not require sealing.

7.1.1. Sealing a Windows Template with Sysprep

Templates that have been created for Windows virtual machines must be generalized (sealed) before use, by means of a tool such as Sysprep. This section describes how to use Sysprep to seal a template before use. This ensures that machine-specific settings are not propagated through the template.

Important

Do not reboot the virtual machine during this process.
Before beginning the Sysprep process to prepare a virtual machine to be used as a template, ensure that the following settings have been configured:
  • The Windows Sysprep parameters have been correctly defined. If not, click Edit VM and enter the required information in the Operating System and Domain fields.
  • The correct Product Key has been entered in the Configuration Tool, rhevm-config. If not, as the root user on the Manager, run the Configuration Tool and enter the required information. The configuration keys that you need to set are ProductKey and SysPrepPath. For example, for Windows 7, the configuration value is ProductKeyWindow7, and SysPrepWindows7Path. The command to set the value is:
      # rhevm-config --set ProductKeyWindow7=<validproductkey> --cver=general
    For the exact syntax for getting and setting configuration values, see Red Hat Enterprise Virtualization 3.0 Installation Guide

Procedure 7.1. To seal a Windows XP template

  1. Download sysprep to the virtual machine to be used as a template.
    The Windows XP Sysprep tool is available at: http://www.microsoft.com/download/en/details.aspx?id=11282
  2. Create a new folder c:\sysprep.
  3. Open the deploy.cab file and put its contents in c:\sysprep.
  4. Execute sysprep.exe from within the folder. Click OK on the welcome message.
  5. The Sysprep tool displays.
    Select the following check boxes:
    • Don't reset grace period for activation
    • Use Mini-Setup
    Ensure that the Shutdown mode is set to Shut down before clicking Reseal
  6. Acknowledge the pop-up window. The virtual desktop will go through the sealing process and then shut down automatically.
You can also use the procedure above to seal a Windows 2003 template. The Windows 2003 Sysprep tool is available at http://www.microsoft.com/download/en/details.aspx?id=14830.

Procedure 7.2. To seal a Windows 7 or Windows 2008 template

  1. In the virtual machine to be used as a template, open a command line terminal and type regedit.
  2. The Registry Editor window displays. On the left pane, expand HKEY_LOCAL_MACHINESYSTEMSETUP.
  3. On the main window, right click to add a new string value using NewString Value.
  4. Right click on the file and select Modify. When the Edit String dialog box displays, enter the following information in the provided text boxes:
    • Value name: UnattendFile
    • Value data: a:\sysprep.inf
  5. Launch Sysprep from C:\Windows\System32\sysprep\sysprep.exe
    • Under System Cleanup Action, select Enter System Out-of-Box-Experience (OOBE).
    • Tick the Generalize check box if you need to change the computer's system identification number (SID).
    • Under Shutdown Options, select Shutdown.
    Click OK.
  6. The virtual machine will now go through the sealing process and shut down automatically.
The Windows virtual machine has now been sealed, and can be used as a template for Windows virtual machines.

7.1.2. Sealing a Linux Template

Templates that have been created for Linux virtual machines must be generalized (sealed) before use. This section describes how to seal a template before use. This ensures that machine-specific settings are not propagated through the template.
  1. Login to the virtual machine to be used as a template and flag the system for re-configuration by running the following command as root:
    # touch /.unconfigured
  2. Remove ssh host keys. Run:
    # rm -rf /etc/ssh/ssh_host_*
  3. Shut down the virtual machine. Run:
    # poweroff
The Linux virtual machine has now been sealed, and can be used as a template for Linux virtual machines.