Composing a customized Fedora image using Image Builder

Image Builder is a tool that allows you to create custom Fedora OS images. You can use the command line or a Cockpit plugin to work with Image Builder.

Prerequisites

Image Builder Installation

Install Image Builder using below command

sudo dnf install -y osbuild-composer composer-cli cockpit-composer

Enable osbuild-composer.socket

sudo systemctl enable --now osbuild-composer.socket

To run the composer-cli commands as non-root, user must be in the weldr or root groups.

The newgrp command changes a user’s real group identification. When you run the command, the system places you in a new shell and changes the name of your real group to the group specified with the Group parameter

sudo usermod -a -G weldr $USER
newgrp weldr

Image Blueprint

The first step in using Image Builder is to create the blueprint of the image. The blueprint includes everything the image needs to run. Blueprint files are .toml files

 mkdir blueprints && cd blueprints

Create file hyrule-os.toml and add below contents

name = "hyrule-os"
description = ""
version = "1.0.0"
modules = []
groups = []
distro = ""

[[packages]]
name = "ansible-core"
version = "*"

[[packages]]
name = "podman"
version = "*"

[[packages]]
name = "skopeo"
version = "*"

[customizations]

[[customizations.user]]
name = "link"
password = "$6$st3tG34hIMT10Zrb$WzU/4OSYY6IqASjpnA0wGNIzemI13pYYqDleQPjLgILE1Gi2HS71fETX2wVkiOg8S.uFnRC9.tYkjCOd8O0a2."
groups = ["wheel"]

Password hash generation

python3 -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'

Push blueprint

composer-cli blueprints push hyrule-os.toml

Resolve dependencies in the blueprint

composer-cli blueprints depsolve hyrule-os

List blueprints

composer-cli blueprints list

Terminal output for reference

$ composer-cli blueprints list
hyrule-os

List the available image types

composer-cli compose types

Terminal output for reference

$ composer-cli compose types
ami
container
image-installer
iot-commit
iot-container
iot-installer
iot-raw-image
live-installer
minimal-raw
oci
openstack
ova
qcow2
vhd
vmdk
wsl

Start a compose. It may take several minutes to finish the compose process

composer-cli compose start BLUEPRINT COMPOSE-TYPE
$ composer-cli compose start hyrule-os qcow2
Compose 00d2ec3d-4086-45b6-838c-bd1b8f86f797 added to the queue

List all composes and their status

composer-cli compose status

Terminal output for reference

$ composer-cli compose status
ID                                     Status     Time                      Blueprint         Version   Type               Size
aa3d9568-4eba-43fc-b653-3c77b6be8e0a   FINISHED   Wed Aug 9 18:15:59 2023   hyrule-os         1.0.0     qcow2              5368709120

Create the image using below command

composer-cli compose image UUID

Terminal output for reference

$ composer-cli compose image aa3d9568-4eba-43fc-b653-3c77b6be8e0a 
aa3d9568-4eba-43fc-b653-3c77b6be8e0a-disk.qcow2

Test the image by running below command

sudo qemu-kvm --name hyrule-os -m 1024 -hda aa3d9568-4eba-43fc-b653-3c77b6be8e0a-disk.qcow2 

Fedora Workstation qemu kvm