Chapter 4. Creating system images by using the RHEL image builder CLI
RHEL image builder is a tool for creating custom system images. To control RHEL image builder and create your custom system images, you can use the command line (CLI) or the web console interface.
4.1. Introducing the RHEL image builder command-line interface Copy linkLink copied to clipboard!
You can use the RHEL image builder command-line interface (CLI) to create blueprints, by running the image-builder command with the suitable options and subcommands.
By default, you must run the image-builder command as a root user.
The workflow for the command line can be summarized as follows:
- Create a blueprint or export an existing blueprint definition to a plain text file.
- Optional: Edit this file in a text editor.
- Import the blueprint text file back into image builder.
- Run a compose to build an image from the blueprint.
- Export the image file to download it.
Apart from the basic subcommands to create a blueprint, you can use the image-builder command with many subcommands to examine the state of configured blueprints and composes.
4.2. RHEL image builder blueprint format Copy linkLink copied to clipboard!
With RHEL image builder, you can use blueprints in both the .toml and .json formats.
A typical blueprint file includes the following elements:
- The blueprint metadata
name = "<blueprint_name>" description = "<long_form_description_text>" version = "<version>"The
<blueprint_name>and<long_form_description_text>fields are the name and description for your blueprint.The
<version>is a version number according to the Semantic Versioning scheme, and is present only once for the entire blueprint file.- Groups to include in the image
[[groups]] name = "<group_name>"The
<group_name>entry describes a group of packages to be installed into the image. Groups use the following package categories:- Mandatory
- Default
Optional
The
group-nameis the name of the group, for example, anaconda-tools, widget, wheel, or users. Blueprints install the mandatory and default packages. There is no mechanism for selecting optional packages.
- Packages to include in the image
[[packages]] name = "<package_name>" version = "<package_version>"package-nameis the name of the package, such ashttpd,gdb-doc, orcoreutils.package-versionis a version to use. In this field, you can specify dnfversion constraints as follows:-
For a specific version, use the exact version number, such as
8.7.0. -
For the latest available version, use the asterisk
*. For the latest minor version, use a format such as
8.*.Repeat this block for every package to include.
NoteThere are no differences between packages and modules in the RHEL image builder tool. RHEL image builder treatd both as RPM Package Manager (RPM) package dependencies.
-
For a specific version, use the exact version number, such as
4.3. Creating a blueprint by using the command line Copy linkLink copied to clipboard!
You can create a new blueprint by using the command line (CLI). The blueprint describes the final image and its customizations, such as packages and kernel customizations.
Prerequisites
-
You are logged in as the root user or a user who is a member of the
weldrgroup
Procedure
Create a plain text file with the following contents:
name = "<blueprint_name>" description = "<long_form_description>" version = "<0.0.1>" modules = [] groups = []Replace
<blueprint_name>and<long_form_description>with a name and description for your blueprint.Replace
<0.0.1>with a version number according to the Semantic Versioning scheme.For every package that you want to be included in the blueprint, add the following lines to the file:
[[packages]] name = "<package_name>" version = "<package_version>"Replace
<package_name>with the name of the package, such ashttpd,gdb-doc, orcoreutils.Optionally, replace
<package_version>with the version to use. This field supportsdnfversion specifications:-
For a specific version, use the exact version number such as
9.6.0. -
For the latest available version, use the asterisk
* -
For the latest minor version, use formats such as
9.*.
-
For a specific version, use the exact version number such as
Customize your blueprints to suit your needs. For example, disable Simultaneous Multi Threading (SMT), add the following lines to the blueprint file:
[customizations.kernel] append = "nosmt=force"For additional customizations available, see Supported image customizations.
Note that
[]and[[]]are different data structures expressed in TOML.-
The
[customizations.kernel]header represents a single table that defines collection of keys and their corresponding value pairs, for example:append = "nosmt=force". -
The
[[packages]]header represents an array of tables. The first instance defines the array and its first table element, such asname = "package-name"andversion = "package-version". Each subsequent instance adds a new element in the order that you define them.
-
The
-
Save the file, for example, as
<blueprint_name>.tomland close the text editor.
4.4. Creating a system image with RHEL image builder on the command line Copy linkLink copied to clipboard!
To build a customized RHEL image by using the RHEL image builder command-line interface, you must specify a blueprint and an image type. Optionally, you can also specify a distribution.
If you do not specify a distribution, it uses the same distribution and version as the host system. The architecture is also the same as the one on the host.
Prerequisites
- You have a blueprint prepared for the image.
Procedure
Optional: List the image formats you can create:
# image-builder listStart the compose:
# image-builder build <image_type> --blueprint <blueprint_name>-
Replace
<blueprint_name>with the name of the blueprint, and<image_type>with the type of the image. -
If you do not specify a distro,
image-builderuses the same distribution and version as the host system.
-
Replace
Result
The compose process takes some minutes to complete. You can follow the image building steps until the image is ready.
After the image building process finishes, the image is available for your use at the directory where you create it.
4.5. Basic RHEL image builder command-line commands Copy linkLink copied to clipboard!
Use the RHEL image builder command-line interface to run these basic image-builder commands.
- List all available images
# image-builder list- Filter images by name
# image-builder list-images --filter "rhel"- Filter by distribution and architecture
# image-builder list-images --filter "distro:rhel-10 arch:s390x"- Change output format
# image-builder list-images --filter "distro:rhel-10" --format=json | jq# image-builder list-images --filter "distro:rhel-10" --format=shell- Building images
# image-builder build <image-type><image-type> is the image type supported for RHEL image builder, such as
qcow2,wsl, and so on.- Specify a distribution
# image-builder build <image-type> --distro <distro>- Show the progress of the image creation and detailed steps
# image-builder build <image-type> --distro <distro> --with-buildlog- Cross-architecture build
# image-builder build <image-type> --arch=riscv64- Add a custom repository to the build
# image-builder build <image-type> --add-repo=<file:///path/to/my/repo>
4.6. Enabled services on custom images Copy linkLink copied to clipboard!
When you configure a custom image by using RHEL image builder to the RHEL version and image type determine the default services that the image uses.
For example, use the ami image type to enable the sshd, chronyd, and cloud-init services by default. If these services are not enabled, the custom image does not boot.
| Image type | Default enabled Services |
|---|---|
|
| sshd, cloud-init, cloud-init-local, cloud-config, cloud-final |
|
| sshd, cloud-init, cloud-init-local, cloud-config, cloud-final |
|
| cloud-init |
|
| Do not enable extra services by default |
|
| sshd, chronyd, waagent, cloud-init, cloud-init-local, cloud-config, cloud-final |
|
| sshd, chronyd, vmtoolsd, cloud-init |
You can customize which services to enable during the system boot. However, the customization does not override services enabled by default for the mentioned image types.