Preparing the OS Linux template
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.
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, AlmaLinux
yum -y install qemu-guest-agent
CODEОС Debian, Ubuntu
apt -y install qemu-guest-agent
CODEAdd QEMU Guest Agent to the autostart:
systemctl enable --now qemu-guest-agent
CODECheck the status of QEMU Guest Agent:
systemctl status qemu-guest-agent
CODECheck the status of the SELinux service:
sestatus
CODEIf the status is different from disable:
Disable SELinux. Replace the below line in the /etc/selinux/config file
SELINUX=enforcing
CODEwith
SELINUX=disabled
CODE- 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
CODE- Mark this line as comment or delete it.
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
CentOS, AlmaLinux
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:
Debian, Ubuntu
apt -y install curl vim
CentOS, AlmaLinux
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"
BASHComments to the command<disk_path> — path to the VM disk
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>
BASHComments to the command<disk_format> — original disk format
<disk_path> — path to the VM disk
<image_path> — path to save the image
Optimize the image file with virt-sparsify utility:
LIBGUESTFS_BACKEND=direct virt-sparsify --in-place <image_path>
CODEComments to the command<image_path> — path to the image file
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
CODEComments to the command<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
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
BASHComments to the command<image_path> — path to the image file
--root-password random — set a random password for the root user
Create an archive with the image in .xz format:
xz <image_path>
CODEComments to the command<image_path> — path to the image 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.
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 file
architecture: amd64 creation_date: 1600761137
CODERead 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.
Useful tips
Related topics: