How to create custom image using RHEL-ImageBuilder.

Mayank Jain
3 min readJun 16, 2023

--

Prerequisites:

You must be connected to a RHEL VM. The VM for image builder must be running and subscribed to Red Hat Subscription Manager (RHSM) or Red Hat Satellite.

Procedure:

Install the image builder and other necessary packages by running below commands:

osbuild-composer - supported from RHEL 8.3 onward composer-cli cockpit-composer bash-completion

Command:

# dnf install osbuild-composer composer-cli cockpit-composer bash-completion

Enable image builder to start after each reboot:

# systemctl enable --now osbuild-composer.socket systemctl enable --now cockpit.socket

Overriding a system repository

Prerequisites: You have a custom repository that is accessible from the host system.

Procedure: Create a directory where you want to store your repository overrides:

# sudo mkdir -p /etc/osbuild-composer/repositories

Copy the file for your distribution from /usr/share/osbuild-composer/ and modify its content.For RHEL 8.7, use /etc/osbuild-composer/repositories/rhel-87.json. Now restart the osbuild-composer.service

# sudo systemctl restart osbuild-composer.service

Setup to create Image using Image Builder is completed.

Create Image using command line

The workflow for the command-line interface can be summarized as follows:

Export (save) the blueprint definition to a plain text file Edit this file in a text editor Import (push) 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

Create file with extension .toml. In this repo case we created FIRSTIMAGE-BULEPRINT.toml Now Push (import) the blueprint:

# composer-cli blueprints push BLUEPRINT-NAME.toml

Verify that the blueprint has been pushed and exists:

# composer-cli blueprints list you will able to see your Buleprint.

Display the blueprint configuration you have just added:

# composer-cli blueprints show FIRSTIMAGE

Check whether the components and versions listed in the blueprint and their dependencies are valid:

# composer-cli blueprints depsolve FIRSTIMAGE

If image builder is unable to depsolve a package from your custom repositories, follow the steps:

Remove the osbuild-composer cache:

# sudo rm -rf /var/cache/osbuild-composer/*

# sudo systemctl restart osbuild-composer

Creating a system image with image builder in the command-line interface

Procedure: Start the compose

# composer-cli compose start BLUEPRINT-NAME IMAGE-TYPE

Composing images from blueprints

# composer-cli compose types

Currently this are the valid types availables :

Now run the below command to create iso image using our Blueprint

# composer-cli compose start FIRSTIMAGE image-installer output of above command: Compose c1e507cb-ffdf-4564-842a-89e3c2ade65d added to the queue where c1e507cb-ffdf-4564-842a-89e3c2ade65d is the unique UUID of the image creation

After running the command Compose added in the queue you can check the status by running below command.

# composer-cli compose status

To check Logs

# composer-cli compose log <build_id>

To download the created image

# composer-cli compose image COMPOSE-UUID

After downloading the image you can test the image by creating the virtual machine in oracle virtual box. The image which is created contains only limited required packages, if you want to add some custom packages you need to add it in blueprint while creating the image.

--

--

Mayank Jain

Skilled DevOps Engineer with 7.5+ years of hands-on experience supporting, automating, & optimizing mission critical deployments in cloud.