The template format depends on the type of virtualization in the cluster:

  • KVM — an .xz archive with a RAW disk image of the OS;
  • LXD — a tar.gz archive with the contents of the file system and the metadata file.

Template requirements


Disk partitioning and OS installation

Use GPT disk partitioning. For the first disk partition, specify the BIOS boot type and a size of 2 MB. For the second disk partition, specify the Linux filesystem type and the minimum possible size (for example, 4 GB). Install the OS on the second partition in the minimum configuration.

It is recommended not to allocate a separate partition for swap space, but to create a 512 MB swap file.

Installing additional software

QEMU Guest Agent

QEMU Guest Agent software is required for the platform to interact with VMs. Installation steps:

  1. Install software packages:

    ОС CentOS, AlmaLinux

    yum -y install qemu-guest-agent
    CODE

    ОС Debian, Ubuntu

    apt -y install qemu-guest-agent
    CODE
  2. Add QEMU Guest Agent to the autostart:

    systemctl enable --now qemu-guest-agent
    CODE
  3. Check the status of QEMU Guest Agent:

    systemctl status qemu-guest-agent
    CODE
  4. Check the status of the SELinux service:

    sestatus
    CODE

    If the status is different from disable:

    1. Disable SELinux. Replace the below line in the /etc/selinux/config file

      SELINUX=enforcing
      CODE

      with

      SELINUX=disabled
      CODE
    2. Reboot the OS.
  5. If the file /etc/sysconfig/qemu-ga contains a line the below format

    BLACKLIST_RPC=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek,guest-file-flush,guest-exec,guest-exec-status
    CODE


    1. Mark this line as comment or delete it.
    2. Restart QEMU Guest Agent:

      systemctl restart qemu-guest-agent
      CODE

SPICE

If you need to connect to VMs created from the template via SPICE, install the spice-vdagent and spice-webdavd software packages:

Debian, Ubuntu

apt -y install spice-vdagent spice-webdavd
BASH

CentOS, AlmaLinux

yum -y install spice-vdagent
BASH

For the CentOS template, add the software launch to the autostart:

systemctl enable spice-vdagent
BASH

System utilities

Check for the available curl and vim utilities:

curl -V
BASH
vim --version
BASH

If any of the utilities are not installed, install them:

Debian, Ubuntu

apt -y install curl vim
BASH

CentOS, AlmaLinux

yum -y install curl vim
BASH

SSH configuration

Enable SSH connection with superuser account and password authentication. To do this, specify the parameters in the /etc/ssh/sshd_config file:

PermitRootLogin yes
PasswordAuthentication yes
CODE

Clear command history

After installing and configuring all software packages, clear the command history:

rm /root/.bash_history
BASH
history -c 
BASH

Template for KVM cluster


To prepare a template:

  1. Create a virtual machine (VM) with the required OS version.
  2. Configure the operating system and install the necessary software packets.

  3. Stop the VM.
  4. Determine the format in which the VM disk is saved:

    qemu-img info <disk_path> | grep "file format"
    BASH

    <disk_path> — path to the VM disk

  5. Copy the VM disk file to a separate directory. If the disk is not saved in RAW format, convert it to RAW format:

    qemu-img convert -f <disk_format> -O raw <disk_path> <image_path>
    BASH

    <disk_format> — original disk format

    <disk_path> — path to the VM disk

    <image_path> — path to save the image

  6. Optimize the image file with virt-sparsify utility:

    LIBGUESTFS_BACKEND=direct virt-sparsify --in-place <image_path>
    CODE

    <image_path> — path to the image file

  7. Clear the image of personal information with virt-sysprep utility:

    LIBGUESTFS_BACKEND=direct virt-sysprep --format=raw --operations <sysprep_ops> --add <image_path> --root-password random
    CODE

    <sysprep_ops> — information to be deleted. Recommended value: defaults,ca-certificates,kerberos-data,user-account. Read more in the utility documentation .

    <image_path> — path to the image file

    --root-password random — set a random password for the root user

  8. To make the VMs created from the template have a unique machine-id parameter, run the command: 

    LIBGUESTFS_BACKEND=direct virt-sysprep --format=raw --operations machine-id --add <image_path> --root-password random
    BASH

    <image_path> — path to the image file

    --root-password random — set a random password for the root user


  9. Create an archive with the image in .xz format:

    xz <image_path>
    CODE

    <image_path> — path to the image file

  10. Copy the archive to the repository directory.
  11. Add the template information to the metadata.json repository description file. Read more in OS templates repositories.

Template for KVM cluster


To prepare a template:

  1. Create a /rootfs directory and copy the contents of the file system there. You can use the debootstrap utility for a Debian-based OS template, or the yumbootstrap utility for a Red Hat Linux-based OS template.
  2. Make the necessary changes to the OS files.
  3. Create a metadata.yaml file with the required parameters:
    1. architecture — CPU architecture. For example, x86_64 or amd64;
    2. creation_date — template creation time in Unix time.

      Example of metadata.yaml file

      architecture: amd64
      creation_date: 1600761137
      CODE

      Read more about the file format in the official LXD documentation .

  4. Create a tar.gz archive with the /rootfs directory and the metadata.yaml file.

  5. Copy the archive to the repository directory.
  6. Add the template information to the metadata.json repository description file. Read more in OS templates repositories.

Useful tips

Related topics: