1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/virt-building-vm-containerdisk-image.adoc
2025-11-18 16:29:25 +01:00

170 lines
4.6 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt//support/monitoring/virt-running-cluster-checkups.adoc
:_mod-docs-content-type: PROCEDURE
[id="virt-building-vm-containerdisk-image_{context}"]
= Building a container disk image for {op-system-base} virtual machines
[role="_abstract"]
You can build a custom {op-system-base-full} 9 OS image in `qcow2` format and use it to create a container disk image.
You can store the container disk image in a registry that is accessible from your cluster and specify the image location in the `spec.param.vmContainerDiskImage` attribute of the DPDK checkup config map.
To build a container disk image, you must create an image builder virtual machine (VM). The _image builder VM_ is a {op-system-base} 9 VM that can be used to build custom {op-system-base} images.
.Prerequisites
* The image builder VM must run {op-system-base} 9.4 and must have a minimum of 2 CPU cores, 4 GiB RAM, and 20 GB of free space in the `/var` directory.
* You have installed the image builder tool and its CLI (`composer-cli`) on the VM. For more information, see "Additional resources".
* You have installed the `virt-customize` tool:
+
[source,terminal]
----
# dnf install guestfs-tools
----
* You have installed the Podman CLI tool (`podman`).
.Procedure
. Verify that you can build a {op-system-base} 9.4 image:
+
[source,terminal]
----
# composer-cli distros list
----
+
[NOTE]
====
To run the `composer-cli` commands as non-root, add your user to the `weldr` or `root` groups:
[source,terminal]
----
# usermod -a -G weldr <user>
----
[source,terminal]
----
$ newgrp weldr
----
====
. Enter the following command to create an image blueprint file in TOML format that contains the packages to be installed, kernel customizations, and the services to be disabled during boot time:
+
[source,terminal]
----
$ cat << EOF > dpdk-vm.toml
name = "dpdk_image"
description = "Image to use with the DPDK checkup"
version = "0.0.1"
distro = "rhel-9.4"
[[customizations.user]]
name = "root"
password = "redhat"
[[packages]]
name = "dpdk"
[[packages]]
name = "dpdk-tools"
[[packages]]
name = "driverctl"
[[packages]]
name = "tuned-profiles-cpu-partitioning"
[customizations.kernel]
append = "default_hugepagesz=1GB hugepagesz=1G hugepages=1"
[customizations.services]
disabled = ["NetworkManager-wait-online", "sshd"]
EOF
----
. Push the blueprint file to the image builder tool by running the following command:
+
[source,terminal]
----
# composer-cli blueprints push dpdk-vm.toml
----
. Generate the system image by specifying the blueprint name and output file format. The Universally Unique Identifier (UUID) of the image is displayed when you start the compose process.
+
[source,terminal]
----
# composer-cli compose start dpdk_image qcow2
----
. Wait for the compose process to complete. The compose status must show `FINISHED` before you can continue to the next step.
+
[source,terminal]
----
# composer-cli compose status
----
. Enter the following command to download the `qcow2` image file by specifying its UUID:
+
[source,terminal]
----
# composer-cli compose image <UUID>
----
. Create the customization scripts by running the following commands:
+
[source,terminal]
----
$ cat <<EOF >customize-vm
#!/bin/bash
# Setup hugepages mount
mkdir -p /mnt/huge
echo "hugetlbfs /mnt/huge hugetlbfs defaults,pagesize=1GB 0 0" >> /etc/fstab
# Create vfio-noiommu.conf
echo "options vfio enable_unsafe_noiommu_mode=1" > /etc/modprobe.d/vfio-noiommu.conf
# Enable guest-exec,guest-exec-status on the qemu-guest-agent configuration
sed -i 's/\(--allow-rpcs=[^"]*\)/\1,guest-exec-status,guest-exec/' /etc/sysconfig/qemu-ga
# Disable Bracketed-paste mode
echo "set enable-bracketed-paste off" >> /root/.inputrc
EOF
----
. Use the `virt-customize` tool to customize the image generated by the image builder tool:
+
[source,terminal]
----
$ virt-customize -a <UUID>-disk.qcow2 --run=customize-vm --selinux-relabel
----
. To create a Dockerfile that contains all the commands to build the container disk image, enter the following command:
+
[source,terminal]
----
$ cat << EOF > Dockerfile
FROM scratch
COPY --chown=107:107 <UUID>-disk.qcow2 /disk/
EOF
----
+
where:
<UUID>-disk.qcow2:: Specifies the name of the custom image in `qcow2` format.
. Build and tag the container by running the following command:
+
[source,terminal]
----
$ podman build . -t dpdk-rhel:latest
----
. Push the container disk image to a registry that is accessible from your cluster by running the following command:
+
[source,terminal]
----
$ podman push dpdk-rhel:latest
----
. Provide a link to the container disk image in the `spec.param.vmUnderTestContainerDiskImage` attribute in the DPDK checkup config map.