Building CentOS Stream images with Disk Image Builder for OPCP
Find out how to build custom CentOS Stream 8 and 9 OpenStack images with diskimage-builder (DiB) for On-Prem Cloud Platform
Objective
Disk Image Builder (DiB) is the OpenStack tool used to build custom operating system disk images. This guide shows how to build CentOS Stream 8 and CentOS Stream 9 images that are ready to be imported into OpenStack Glance and used on your On-Prem Cloud Platform (OPCP).
This guide explains how to install DiB, prepare custom elements that work around a known CentOS issue, and run the build for both CentOS Stream 8 and CentOS Stream 9.
For a different example using Debian and Ansible-based customization, see Building a custom Debian image for OPCP.
In this guide we use Debian 12 as the build host to produce CentOS images, but you can use another Linux distribution (adjustments may be required). You can also adapt the paths and commands shown here to match your needs.
Requirements
- Root permissions on the build host
- At least 10 GB of free disk space
- A Debian 12 (or compatible) Linux environment to run the build from
- Access to the internet to download packages and the upstream CentOS mirrors
Instructions
Step 1: Install the build requirements
Install the components required by DiB to build CentOS, Debian and Ubuntu based images:
git is needed to clone the DiB repository, qemu-utils provides the qemu-img tooling used to handle qcow2 images, qemu-system-x86 provides qemu-system-x86_64 used in Step 7 to test the result, and curl is used to download packages and mirror content during the build.
Step 2: Install Disk Image Builder
Create and activate a Python virtual environment:
Clone the DiB repository on a specific tag and install it. In this example we use version 3.42.0:
Check that disk-image-create is available:
Step 3: Create the folder tree
Create the working directories used by the build:
Step 4: Define the custom elements
CentOS builds require two custom elements that work around current limitations of the upstream DiB elements.
Custom element: block-device-efi-custom
The default block-device-efi element creates an ESP (EFI System Partition) that is larger than needed. Create a custom element based on it and resize the partition from 550 MiB to 512 MiB:
Custom element: centos-custom
The default centos element has an issue that is not fixed yet. Create a custom element based on it to apply the required hotfix:
Step 5: Build a CentOS Stream 8 image
For CentOS Stream 8, the default user created by cloud-init is centos.
Create the environment variables
Run the build
Unset any previously defined variable, source the environment file, then run the build:
Once the build completes, check the output files:
Step 6: Build a CentOS Stream 9 image
For CentOS Stream 9, the default user created by cloud-init is cloud-user.
Create the environment variables
Run the build
Once the build completes, check the output files:
Step 7 (optional): Test the image locally
Before uploading the image, you can boot it locally with QEMU to make sure it starts correctly:
Step 8: Upload the image to OpenStack
Import the generated qcow2 image into Glance:
You can now create a Bare Metal (Ironic) or Compute (Nova) instance from the newly created image.
Troubleshooting
The image does not boot (emergency mode) or the build fails on grub2-probe
Symptoms
The error can show up in two different places:
During the build, at the grub step:
When booting an instance, the boot does not complete and drops into "emergency" mode. journalctl shows filesystem errors:
Cause
The issue is related to the version of e2fsprogs, used by the mke2fs, e2fsck and grub2-probe commands.
disk-image-builder formats the root partition with the mkfs.ext4 of the build machine, not the one from the target image. If the build host runs a recent e2fsprogs (version above 1.47), some ext4 features are enabled by default when the filesystem is created:
metadata_csum_seedorphan_file
These features are too recent for the e2fsprogs/grub2 shipped with CentOS 8 or 9, which causes the errors described above.
Solution
Disable these features when the filesystem is created, using the --mkfs-options option of disk-image-create:
Go further
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts to assist you on the specific use case of your project.
Join our community of users.