Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

Chapter 7. Templates

A template is a copy of a virtual machine that you can use to simplify the subsequent, repeated creation of similar virtual machines. Templates capture the configuration of software, configuration of hardware, and the software installed on the virtual machine on which the template is based. The virtual machine on which a template is based is known as the source virtual machine.
When you create a template based on a virtual machine, a read-only copy of the virtual machine's disk is created. This read-only disk becomes the base disk image of the new template, and of any virtual machines created based on the template. As such, the template cannot be deleted while any virtual machines created based on the template exist in the environment.
Virtual machines created based on a template use the same NIC type and driver as the original virtual machine, but are assigned separate, unique MAC addresses.
You can create a virtual machine directly from the Templates tab, as well as from the Virtual Machines tab. In the Templates tab, right-click the required template and select New VM. For more information on selecting the settings and controls for the new virtual machine see Section A.1.1, “Virtual Machine General Settings Explained”.

7.1. Sealing Virtual Machines in Preparation for Deployment as Templates

This section describes procedures for sealing Linux virtual machines and Windows virtual machines. Sealing is the process of removing all system-specific details from a virtual machine before creating a template based on that virtual machine. Sealing is necessary to prevent the same details from appearing on multiple virtual machines created based on the same template. It is also necessary to ensure the functionality of other features, such as predictable vNIC order.

7.1.1. Sealing a Linux Virtual Machine for Deployment as a Template

There are two main methods for sealing a Linux virtual machine in preparation for using that virtual machine to create a template: manually, or using the sys-unconfig command. Sealing a Linux virtual machine manually requires you to create a file on the virtual machine that acts as a flag for initiating various configuration tasks the next time you start that virtual machine. The sys-unconfig command allows you to automate this process. However, both of these methods also require you to manually delete files on the virtual machine that are specific to that virtual machine or might cause conflicts amongst virtual machines created based on the template you will create based on that virtual machine. As such, both are valid methods for sealing a Linux virtual machine and will achieve the same result.

7.1.1.1. Sealing a Linux Virtual Machine Manually for Deployment as a Template

You must generalize (seal) a Linux virtual machine before creating a template based on that virtual machine.

Procedure 7.1. Sealing a Linux Virtual Machine

This procedure describes the minimum steps required to seal a virtual machine for use as a template. Additional host and site-specific steps are available.
  1. Log in to the virtual machine.
  2. Flag the system for re-configuration:
    • For Red Hat Enterprise Linux (RHEL) 6:
      # touch /.unconfigured
    • For RHEL 7 or Red Hat Virtualization Host (RHVH) 4.0:
      # yum install initial-setup

      Note

      Your system must be registered to receive the inital-setup package.
  3. Remove the SSH host keys:
    # rm -rf /etc/ssh/ssh_host_*
  4. Change the host name to localhost.localdomain:
    • For RHEL 6, edit the HOSTNAME value in /etc/sysconfig/network:
      HOSTNAME=localhost.localdomain
    • For RHEL 7 or RHVH 4.0, use the hostnamectl command:
      # hostnamectl set-hostname localhost.localdomain
  5. Remove /etc/udev/rules.d/70-*:
    # rm -rf /etc/udev/rules.d/70-*
  6. Remove the HWADDR line and UUID line from /etc/sysconfig/network-scripts/ifcfg-eth*. Ensure that all static information, such as IP address, DNS, or gateway, is deleted from this file.
  7. Delete machine-id from /etc/machine-id:
    # cd /etc
    # chmod 777 machine-id
    # vi machine-id
    
    Delete the machine id.
    # chmod 444 machine-id
  8. For RHEL 7, enable the initial-setup service:
    # systemctl enable initial-setup.service
  9. Unregister the system:
    # subscription-manager unregister
    # subscription-manager remove --all
    # subscription-manager clean
  10. Optionally, delete all the logs from /var/log and build logs from /root.
  11. Shut down the virtual machine:
    # poweroff
The virtual machine is sealed and can be made into a template. You can deploy Linux virtual machines from this template without experiencing configuration file conflicts.

7.1.1.2. Sealing a Linux Virtual Machine for Deployment as a Template using sys-unconfig

You must generalize (seal) a Linux virtual machine before creating a template based on that virtual machine.

Procedure 7.2. Sealing a Linux Virtual Machine using sys-unconfig

  1. Log in to the virtual machine.
  2. Remove SSH host keys:
    # rm -rf /etc/ssh/ssh_host_*
  3. Change the host name to localhost.localdomain.
    • For Red Hat Enterprise Linux 6, edit the HOSTNAME value in /etc/sysconfig/network:
      HOSTNAME=localhost.localdomain
    • For Red Hat Enterprise Linux 7, use the hostnamectl command:
      # hostnamectl set-hostname localhost.localdomain
  4. Remove the HWADDR line and UUID line from /etc/sysconfig/network-scripts/ifcfg-eth*.
  5. Optionally, delete all the logs from /var/log and build logs from /root.
  6. Run the following command:
    # sys-unconfig
The virtual machine shuts down; it is now sealed and can be made into a template. You can deploy Linux virtual machines from this template without experiencing configuration file conflicts.

7.1.2. Sealing a Windows Virtual Machine for Deployment as a Template

A template created for Windows virtual machines must be generalized (sealed) before being used to deploy virtual machines. This ensures that machine-specific settings are not reproduced in the template.
Sysprep is used to seal Windows templates before use. Sysprep generates a complete unattended installation answer file. Default values for several Windows operating systems are available in the /usr/share/ovirt-engine/conf/sysprep/ directory. These files act as templates for Sysprep. The fields in these files can be copied, pasted, and altered as required. This definition will override any values entered into the Initial Run fields of the Edit Virtual Machine window.
The Sysprep file can be edited to affect various aspects of the Windows virtual machines created from the template that the Sysprep file is attached to. These include the provisioning of Windows, setting up the required domain membership, configuring the hostname, and setting the security policy.
Replacement strings can be used to substitute values provided in the default files in the /usr/share/ovirt-engine/conf/sysprep/ directory. For example, "<Domain><![CDATA[$JoinDomain$]]></Domain>" can be used to indicate the domain to join.

7.1.2.1. Prerequisites for Sealing a Windows Virtual Machine

Important

Do not reboot the virtual machine while Sysprep is running.
Before starting Sysprep, verify that the following settings are configured:
  • The Windows virtual machine parameters have been correctly defined.
    • If not, click Edit the Virtual Machines tab and enter the required information in the Operating System and Cluster fields.
  • The correct product key has been defined in an override file on the Manager.
    The override file must be created under /etc/ovirt-engine/osinfo.conf.d/, have a filename that puts it after /etc/ovirt-engine/osinfo.conf.d/00-defaults.properties, and ends in .properties. For example, /etc/ovirt-engine/osinfo.conf.d/10-productkeys.properties. The last file will have precedence and override any other previous file.
    If not, copy the default values for your Windows operating system from /etc/ovirt-engine/osinfo.conf.d/00-defaults.properties into the override file, and input your values in the productKey.value and sysprepPath.value fields.

    Example 7.1. Windows 7 Default Configuration Values

    # Windows7(11, OsType.Windows, false),false
    os.windows_7.id.value = 11
    os.windows_7.name.value = Windows 7
    os.windows_7.derivedFrom.value = windows_xp
    os.windows_7.sysprepPath.value = ${ENGINE_USR}/conf/sysprep/sysprep.w7
    os.windows_7.productKey.value =
    os.windows_7.devices.audio.value = ich6
    os.windows_7.devices.diskInterfaces.value.3.3 = IDE, VirtIO_SCSI, VirtIO
    os.windows_7.devices.diskInterfaces.value.3.4 = IDE, VirtIO_SCSI, VirtIO
    os.windows_7.devices.diskInterfaces.value.3.5 = IDE, VirtIO_SCSI, VirtIO
    os.windows_7.isTimezoneTypeInteger.value = false
    

7.1.2.2. Sealing a Windows 7, Windows 2008, or Windows 2012 Template

Seal a Windows 7, Windows 2008, or Windows 2012 template before using the template to deploy virtual machines.

Procedure 7.3. Sealing a Windows 7, Windows 2008, or Windows 2012 Template

  1. Launch Sysprep from C:\Windows\System32\sysprep\sysprep.exe.
  2. Enter the following information into Sysprep:
    • Under System Cleanup Action, select Enter System Out-of-Box-Experience (OOBE).
    • Select the Generalize check box if you need to change the computer's system identification number (SID).
    • Under Shutdown Options, select Shutdown.
  3. Click OK to complete the sealing process; the virtual machine shuts down automatically upon completion.
The Windows 7, Windows 2008, or Windows 2012 template is sealed and ready for deploying virtual machines.