Skip to main content

How to create a custom Red Hat Enterprise Linux 9 machine image for AWS

No RHEL 9 AMI available for your needs? No worries! Learn how to generate a custom Amazon Machine Image for RHEL.
My worst sysadmin mistake

I was involved in a demo of Red Hat Enterprise Linux (RHEL) for Edge, and I experienced some problems with the network driver for Raspberry Pi 4 in RHEL 8. To solve this problem, I decided to create a custom image based on RHEL 9 instead, where the Ethernet network driver works.

(Note: At the time of this writing, there is no RHEL support for Raspberry Pi. RHEL for ARM is available only for larger 64-bit ARMv8 platforms. However, this is based on a demo, and if you need a supported Linux system, try Fedora on Raspberry Pi. Fedora 29 and later versions support the Raspberry Pi Model 2B and 3 series of devices, including the 3B, 3B+, 3A+, 3CM, and 3CM+.) 

There was no RHEL 9 Amazon Machine Image (AMI) in the AWS marketplace when I was working on these problems. AMIs are standard prepackaged images required to launch instances on AWS. Even if there is a RHEL 9 AMI by the time you're reading this article, it's worth understanding how to build a custom image.

Key technologies

There are three key technologies involved in this process:

  • Qcow2 is the most common (and the native) format of disk images used by QEMU. The AWS import-image tool cannot import qcow2 images directly (at the time of writing).
  • AWS CLI, the AWS command-line interface, is a unified tool to manage AWS services. It enables you to control multiple AWS services from the command line and automate them through scripts.
  • Red Hat Enterprise Linux for ARM 64 is designed to meet the needs of the hybrid cloud environment. It can be deployed on physical infrastructure, as a guest operating system on supported hypervisors, in public cloud environments, and in containers using the RHEL Unified Base Image (UBI).

I used RHEL 8 as my workstation and the RHEL 9.0 KVM Guest Image to create my custom image. If you do not have an active Red Hat Customer Portal account but you are interested in following this tutorial, you can use the no-cost RHEL for developers subscription. Here, you can download the ISO, boot or full (for offline or disconnected environments) version, and convert it to qcow2 thanks to qemu-img convert.

I'll assume you're familiar with routine AWS and Linux tasks, such as assigning the correct permissions to the AWS Simple Storage Service (S3) bucket, installing tools such as AWS CLI, and so on. If you're new to AWS and Linux, you can follow the steps in my Git repository.

[ Learn how to modernize your IT with managed cloud services. ]

Convert qcow2 to RAW

Use the qemu-img to convert the qcow2 image into the RAW format:

$ qemu-img convert rhel-baseos-9.0-beta-5-aarch64-kvm.qcow rhel-baseos-9.0-beta-5-aarch64-kvm.raw

Create an S3 bucket

Create the S3 bucket, copy the RAW image into it, and import the image:

$ aws s3api create-bucket \
--bucket my-rhel9-img \
--region eu-west-1 \
--create-bucket-configuration LocationConstraint=eu-west-1

$ aws s3 cp rhel-baseos-9.0-beta-5-aarch64-kvm.raw s3://my-rhel9-img

$ aws ec2 import-snapshot \
--description "Red Hat Enterprise Linux 9.0 Beta Update 5 KVM Guest Image" \
--disk-container "file://container.json"

[ Try Red Hat's interactive scenarios to learn Red Hat OpenShift at your own pace. ]

Register the image

Finally, register your image with AWS:

$ aws ec2 register-image \
--name RHEL9-baseos-arm64 --architecture arm64 \
--virtualization-type hvm --ena-support \
--root-device-name /dev/xvda \
--block-device-mappings DeviceName=/dev/xvda,Ebs={SnapshotId=snap-0d3e61728b16d7f48}

Run your image

Using the aws ec2 run-instances command, you can run EC2 instances of your custom golden image.

In my next article, I'll explain how to build MicroShift into your custom image. MicroShift is an exploratory project from Red Hat's edge computing team. It tailors Red Hat OpenShift for field-deployed devices, providing a consistent development and management experience across all footprints.

[ You might also be interested in reading How MicroShift and Kubernetes help manage edge devices at scale. ]

Check out these related articles on Enable Sysadmin

Typing on a laptop with headphones next to the computer
Red Hat Enterprise Linux 9 offers significant new features for hybrid cloud organizations. Here's how to install it so you can start testing.
Author’s photo

Jose Antonio Gonzalez Prada

Jose Antonio González Prada works for Red Hat as a Specialist Solution Architect, previously as a Senior Consultant, specializing in OpenShift and container-related technologies. More about me

Red Hat Summit 2022: On Demand

Get the latest on Ansible, Red Hat Enterprise Linux, OpenShift, and more from our virtual event on demand.

Related Content