Feed abonnieren

In this post:

  • Get a brief explanation of Image Builder

  • Walk through an example of how to prepare an Azure account for an image upload, build a customized RHEL image, ship it to Azure, and start a VM.


Clouds deliver a flexible, dynamic platform for workloads of all sizes with incredible amounts of customization. Most clouds have an image marketplace where customers select different OS images for their workloads, but Red Hat Enterprise Linux (RHEL) offers a unique opportunity to build your own image with Image Builder.

Microsoft Azure is one of Red Hat’s certified cloud providers and they offer a wide array of cloud services in many countries throughout the world. Although you can use a pre-built RHEL image on Azure today, you also have the opportunity to build a customized image with Image Builder and ship it to Azure directly.

Image Builder empowers IT professionals with a simple image build process. Users provide image configuration via a simple TOML file on the command line or via the Cockpit web interface. Image Builder then builds the image in various formats, including raw, qcow2, and several others. In addition, it uploads the image into the cloud of your choice so you can start deploying in a flash!

This post explains how to prepare your Microsoft Azure account for an image build, how to build an image with Image Builder on RHEL 8, and how to launch that image in Azure.

Get your Azure account ready

Start by visiting the Azure Portal and authenticating your account. Azure provides resource groups as a way to keep resources organized. To create a resource group:

  1. Type resource groups into the search bar at the top and click on Resource groups in the list.

  2. Click Create and provide a name for the resource group on the next page.

  3. Click Review + Create and then Create.

Image Builder needs to upload a storage blob to a storage container, so we need a storage account and container first:

  1. Type storage account into the search bar and click Storage accounts in the list.

  2. Click Create and make sure your Resource group appears in the dropdown list.

  3. Enter a name for your storage account in Storage Account Name.

  4. Click Review + Create and Create.

  5. Wait a few moments for the deployment to finish and then click Go to resource.

  6. On the left side, click Containers and then click + Container at the top to add a container.

  7. Choose a name for the container on the far right, then click Create.

We now have a storage account and container that Image Builder can use to store our image. The last step is to get your storage access key since Image Builder uses it for authentication when it uploads:

  1. Click Access Keys on the left side.

  2. Click Show Keys at the top.

  3. In the key1 section, look for the box under Key and copy the contents (you will need this later).

Your Azure account is ready to go!

Getting started with Image Builder

Image Builder includes a few different components:

  • osbuild: completes all of the low level image build tasks.

  • osbuild-composer: offers a simple API for building and managing images.

  • composer-cli: provides a command line interface for building and managing images.

Start by installing some packages on RHEL 8.4 or later:

$ sudo dnf install osbuild-composer composer-cli

The osbuild-composer service starts via socket activation only when you need it. Start the socket:

$ sudo systemctl enable --now osbuild-composer.socket

Users must be in the weldr group to build images. Add your username to the weldr group:

$ sudo usermod -a -G weldr YOUR_USERNAME

Log out of your RHEL 8 system and log back in. You should now be able to talk to the osbuild-composer API:

$ composer-cli status show
API server status:
        Database version:   0
        Database supported: True
        Schema version: 0
        API version:    1
        Backend:        osbuild-composer
        Build:          devel
Image Builder needs some information about your Azure account for the upload. Create a file called azure.toml that contains the following information:
provider = "azure"
[settings]
storageAccount = "your storage account name"
storageAccessKey = "storage access key you copied in the Azure portal"
container = "your storage container name"

Now, we tell Image Builder how to build our image. As a fun experiment, let’s build a RHEL image that contains Image Builder so that you can build more images in an Azure VM! Image Builder calls these “blueprints.” Save this blueprint file as imagebuilder.toml:

name = "imagebuilder"
description = "An image with Image Builder already installed"
version = "0.0.1"

[[packages]]
name = "osbuild-composer"

[[packages]]
name = "composer-cli"

[customizations]
hostname = "imagebuilder.local"

[customizations.services]
enabled = ["osbuild-composer.socket"]

We can push our blueprint into the API and solve the package dependencies:

$ composer-cli blueprints push imagebuilder.toml
$ composer-cli blueprints depsolve imagebuilder

Let’s build and ship our image! The following command builds a 10GB image called image-builder-azure using our imagebuilder blueprint and uploading to Azure with the configuration in our azure.toml file:

$ composer-cli compose start --size 10240 imagebuilder vhd image-builder-azure azure.toml
Compose c1fde40f-2f10-4a52-92d3-c00b62c32f17 added to the queue
$ composer-cli compose status
c1fde40f-2f10-4a52-92d3-c00b62c32f17 RUNNING  Fri Nov  5 09:46:38 2021 imagebuilder 0.0.1 vhd

On most systems, the image build takes about 5-10 minutes, but the upload portion depends heavily on your internet connection speeds for uploading files. You can follow along with the progress by watching the system journal:

$ sudo journalctl -af -u osbuild-worker@1.service
osbuild-worker[26576]: Running 'osbuild' job c1fde40f-2f10-4a52-92d3-c00b62c32f17
--- SNIP ---
osbuild-worker[26576]: 2021/11/05 09:56:14 Job c1fde40f-2f10-4a52-92d3-c00b62c32f17 finished
osbuild-worker[26576]: Waiting for a new job...

Launching a VM in Azure

The fun part has arrived! Let’s go back to the Azure portal to verify that our image uploaded properly:

  1. Type storage account into the search bar and click Storage accounts in the list.

  2. Find the storage account you created earlier and click it.

  3. Click Containers on the left and click your container on the right side.

  4. You should see a vhd file in the list (mine is image-builder-azure.vhd from the command line).

  5. Check the size and ensure it matches the size you specified on the command line.

Our next step involves creating the virtual machine image so we can launch a VM:

  1. Type images into the search bar at the top and click Images from the list.

  2. Click + Create.

  3. Choose the resource group you used earlier from the dropdown list.

  4. Enter a name for the image.

  5. Select Linux for the OS type.

  6. Select Gen 2 for the VM generation.

  7. Under Storage Blob, click Browse and click through the storage account and container until you reach your VHD file.

  8. Click Select at the bottom of the screen.

  9. Choose an Account Type (Standard SSD works fine for this example).

  10. Click Review + Create and then Create.

  11. Wait a few moments for the image creation and then click Go to resource.

Let’s launch the VM:

  1. Click + Create VM at the top.

  2. Choose a name for your virtual machine.

  3. Complete the Size and Administrator account sections.

  4. Click Review + Create and then Create.

Your VM is on the way! The next screen shows your deployment progress. Once it finishes, click on the virtual machine name to retrieve the public IP address of the instance to connect via ssh:

$ ssh username@IP_ADDRESS
[username@imagebuilder ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)
[username@imagebuilder ~]$ sudo composer-cli status show
API server status:
        Database version:   0
        Database supported: True
        Schema version: 0
        API version:    1
        Backend:        osbuild-composer
        Build:          devel

Wrapping up

In this example, we prepared an Azure account for an image upload, built a customized RHEL image, shipped it to Azure, and started a VM. This is only a fraction of what you can build with Image Builder. It can also pull RPMs from your own custom repositories and allow you to stack your code and configuration on top of a stable RHEL base. This makes Image Builder a great part of any continuous integration/continuous delivery (CI/CD) pipeline.

Take a look at the Image Builder documentation for RHEL 8 to learn more about customizations and capabilities. You can also learn more about the upstream project, OSBuild, and join the upstream community.


Über den Autor

Major Hayden is a Principal Software Engineer at Red Hat with a focus on making it easier to deploy Red Hat Enterprise Linux wherever a customer needs it. He is also an amateur radio operator (W5WUT), and he maintains a technical blog at major.io.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

Nach Thema durchsuchen

automation icon

Automatisierung

Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen

AI icon

Künstliche Intelligenz

Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen

open hybrid cloud icon

Open Hybrid Cloud

Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.

security icon

Sicherheit

Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren

edge icon

Edge Computing

Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen

Infrastructure icon

Infrastruktur

Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen

application development icon

Anwendungen

Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen

Original series icon

Original Shows

Interessantes von den Experten, die die Technologien in Unternehmen mitgestalten