Skip to content

Create KVM Templates

Depending on the template generation, the creation process will be different for generation 1 and generation 2. There are also additional considerations for creating Windows KVM templates.

From version 1.13.00 the script named /scripts/kvmtemplate is supplied on all slave servers to aid you in creating KVM templates.

Create Generation 1 KVM Templates

Generation 1 templates are fixed-size byte by byte images. Generation 1 templates should be used if you need to create a special template that either includes obscure partitions or filesystems that cannot be manipulated from the host node. These include, but are not limited to, FreeBSD (Unix) or logical partitions. Generation 1 templates can have networking set up by SolusVM, however, any filesystem resizing should be scripted inside the template.

  1. When creating G1 templates you need to make sure the source virtual server is as small as possible. However, if you are creating a fixed size template, this requirement can be ignored. 

  2. When the virtual server is ready to be packaged, issue a shutdown command, and make a note of the virtual server's kvmID (i.e kvm101). 

  3. On the powered on slave the virtual server runs the following script:

    /scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=1
    

  4. Once the script has finished running, you will be given a location and filename for the template. For example:
    Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
    
  5. The next step is to rename the template, for example:

    • In case of a Linux template:

      cd /home/solusvm/kvm/template/ 
      mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz linux-centos-5.8-x86_64-custom-gen1-v1.gz
      

    • In case of a Windows template:

      cd /home/solusvm/kvm/template/ 
      mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz windows-2008-server-r2-custom-x86_64-gen1-v1.gz
      

    Create Generation 2 KVM Templates

Generation 2 templates are far more flexible than generation 1 templates in respect to filesystem resizing and configuration. Generation 2 templates should be used if the template operating system will be Linux or Windows and will use standard filesystems (ntfs, ext3 or ext4). Generation 2 templates do not currently support logical volumes or extended partitions, you would need to use G1 for that.

For Debian 9/Ubuntu 18 templates make sure that ext3 file system is selected for the data partition. Otherwise, some features will be not available on CentOS 6 host node.

  1. The first step when creating a generation 1 template is to learn the partition number of the partition that you want to resize on the creation of a virtual server. You can run the following command for the specified kvmID:
    /scripts/kvmtemplate --mode=prescan --vmid=kvm101 --generation=2
    
    Example Output:
    Name Type VFS Label MBR Size Parent UUID
    /dev/sda1 filesystem ext4 - - 20G -
    23261380-2181-4fee-bf1a-b7235d2b9ad9
    /dev/sda2 filesystem swap - - 99M -
    d0bc2596-74ae-45b2-b2d4-d59f06b54d07
    /dev/sda1 partition - - 83 20G /dev/sda -
    /dev/sda2 partition - - 82 99M /dev/sda -
    /dev/sda device - - - 20G - -
    
  2. From that output you can decipher that partition 1 (/dev/sda1) is the partition to resize. 
  3. Now you can run a prepare on the source virtual server to remove any ssh keys, mac addresses, and udev rules. 

    Warning

    Please note that this procedure is not foolproof. You should prepare the virtual server manually to make sure all history is removed and configuration files are clean. You may also need to make sure /etc/fstab is correct and any  UUIDS are removed if this is a Linux virtual server. Use vda for virtio and sda for ide.

    Note

    You do NOT need to run prepare for windows virtual servers. For more information, refer to Additional considerations for creating Windows KVM templates.

    /scripts/kvmtemplate --mode=prepare --vmid=kvm101 --generation=2
    
    4. Once the source virtual server is ready to be packaged run the package scripts, for example:
    /scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=2
    
    By default /tmp directory is used for the template creation process to store temporary files. If there is not enough disk space on /tmp - use option "tmpdir":
    /scripts/kvmtemplate --mode=package --vmid=kvm101 --generation=2 --tmpdir=/home/
    
    5. Once the script has finished running, you will be given a location and filename for the template. For example:
    Template: /home/solusvm/kvm/template/template-149fee41d5801f96368c959a00dd6092a56ba031.gz
    

  4. The next step is to rename the template, for example:

    • In case of a Linux template:

      cd /home/solusvm/kvm/template/ 
      mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz linux-centos-5.8-x86_64-custom-gen2-v1.gz
      

      Note

      The template name format is kernel-os-os_version-arch-custom_name-gen-version.gz

    • In case of a Windows template:

      cd /home/solusvm/kvm/template/ 
      mv template-149fee41d5801f96368c959a00dd6092a56ba031.gz windows-2008-server-r2-custom-x86_64-gen2-v1.gz
      

      Note

      The template name format is os-os_year-custom_name-arch-gen-version.gz

Make sure that when adding the template to SolusVM you specify the correct generation and the partition to resize.

Note also that the template name is essential and has to have the exact structure as in the example above. 

Additional considerations for creating Windows KVM templates

Creating Windows templates for KVM is a straightforward process. All versions of Windows can be resized by SolusVM if you are using the generation 2 templating system. Keep in mind the following considerations when creating Windows KVM templates:

Partitions

  • The most recent versions of Windows usually create a RESERVED partition when installed. This partition does need to be removed as it does for Xen HVM templates. We suggest a single C: partition to make the template creation process easy. 

  • If you opt to install Windows as default, the partition to resize will usually be 2, however, for Windows XP and Server 2003 no RESERVED partition is created so the partition to resize would be 1. 

Administrator Password

  • Most versions of Windows Server require an administrator password to be set on the first login. This can make it difficult for you to create a template that contains a datacenter license key because you have to log in first. We suggest you set a default administrator password and specify it in the Default root/admin password box when adding the template to SolusVM. 

  • There are also other tools described on the Internet to prepare a Windows installation for cloning. For more information, you can search for "Windows sysprep". 

Back to top