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:
-
Install software packages:
ОС CentOS, AlmaLinuxyum -y install qemu-guest-agent
ОС Debian, Ubuntuapt -y install qemu-guest-agent
-
Add QEMU Guest Agent to the autostart:
systemctl enable --now qemu-guest-agent
-
Check the status of QEMU Guest Agent:
systemctl status qemu-guest-agent
-
Check the status of the SELinux service:
sestatus
If the status is different from disable:
-
Disable SELinux. Replace the below line in the /etc/selinux/config file
SELINUX=enforcing
with
SELINUX=disabled
- Reboot the OS.
-
-
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
- Mark this line as comment or delete it.
-
Restart QEMU Guest Agent:
systemctl restart qemu-guest-agent
SPICE
If you need to connect to VMs created from the template via SPICE, install the spice-vdagent and spice-webdavd software packages:
apt -y install spice-vdagent spice-webdavd
yum -y install spice-vdagent
For the CentOS template, add the software launch to the autostart:
systemctl enable spice-vdagent
System utilities
Check for the available curl and vim utilities:
curl -V
vim --version
If any of the utilities are not installed, install them:
apt -y install curl vim
yum -y install curl vim
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
Clear command history
After installing and configuring all software packages, clear the command history:
rm /root/.bash_history
history -c
Template for KVM cluster
To prepare a template:
- Create a virtual machine (VM) with the required OS version.
- Configure the operating system and install the necessary software packets.
- Stop the VM.
-
Determine the format in which the VM disk is saved:
qemu-img info <disk_path> | grep "file format"
Comments to the command -
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>
Comments to the command -
Optimize the image file with virt-sparsify utility:
LIBGUESTFS_BACKEND=direct virt-sparsify --in-place <image_path>
Comments to the command -
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
Comments to the command -
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
Comments to the command -
Create an archive with the image in .xz format:
xz <image_path>
Comments to the command - Copy the archive to the repository directory.
- 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:
- 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.
- Make the necessary changes to the OS files.
- Create a metadata.yaml file with the required parameters:
- architecture — CPU architecture. For example, x86_64 or amd64;
-
creation_date — template creation time in Unix time.
Example of metadata.yaml filearchitecture: amd64 creation_date: 1600761137
Read more about the file format in the official LXD documentation .
- Create a tar.gz archive with the /rootfs directory and the metadata.yaml file.
- Copy the archive to the repository directory.
- Add the template information to the metadata.json repository description file. Read more in OS templates repositories.