Image mode for Red Hat Enterprise Linux (RHEL) combines the benefits and methodologies of container technologies with the ability to operate within traditional virtual machine environments. By enabling a familiar container image assembly process that supports several popular output types, end users have the flexibility to choose where and how they want to operate.
One of the supported output formats is a Virtual Machine Disk (VMDK), which is commonly used within VMware’s supported virtualization platforms, like vSphere, but support is also available elsewhere, including VirtualBox. Bridging the gap between traditional operating environments and cloud-native technologies is one of the benefits that image mode provides.
Over the course of this series, we will describe the process for creating image mode for RHEL-based bootc images for use within VMware environments, that, when included within reusable templates, will enable a consistent method for delivering virtual environments. Plus, several different methods will also be provided that illustrate how the generation of the various assets can be automated to create a repeatable factory for delivering bootc images to meet the demands of today and tomorrow.
Read more about image mode for RHEL.
Creating a RHEL bootc image
While there is a lot of ground that will be covered throughout this series, this article will focus specifically on the creation of a bootc image that both provides the necessary primitives needed to operate within the desired target environment, and can either be used as-is, or act as the baseline for an entire lineage of downstream content. Once this bootc image has been created, we will then showcase how a VMDK disk can be created.
Producing a bootc image is no different than developing a standard container image. A Dockerfile or Containerfile describes the composition -- from the base image providing the foundation for the desired components that should be included, such as system packages, applications, and configurations.
Start off by creating a new directory called rhel-bootc-vmdk
and underneath the newly created directory, create two folders: image
and output
, and change into the rhel-bootc-vmdk
directory.
mkdir -p rhel-bootc-vmdk/{image,output}
cd rhel-bootc-vmdk
Create a new file within the image directory called Containerfile (image/Containerfile
) with the following content:
FROM registry.redhat.io/rhel9/rhel-bootc:9.4
RUN dnf -y install cloud-init open-vm-tools && \
ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \
rm -rf /var/{cache,log} /var/lib/{dnf,rhsm} && \
systemctl enable vmtoolsd.service
While somewhat simple in nature, this RHEL 9 bootc image includes several additional RPM packages that provide flexibility to operate as virtual machines within the target environment. We will cover the significance of these packages in a subsequent article.
Prior to creating a bootc image, ensure that your local machine has completed the following steps:
- Installed a container runtime
- Authenticated to the Red Hat Registry.
If not, use the steps below:
- Install Podman
dnf install -y podman
- Authenticate to the Red Hat Registry
podman login registry.redhat.io
Enter your Red Hat credentials when prompted for your username and password.
With the necessary prerequisites complete, create a new Image Mode for RHEL image with the tag localhost/rhel-bootc-vmdk
with the Containerfile created previously:
podman build -f image/Containerfile -t localhost/rhel-bootc-vmdk image
Once the build process has finished, feel free to explore the contents of the produced image by using the podman run
command. The options available for running a bootc image locally can be found within the documentation.
Now that the desired image has been created, let’s shift our attention to what it takes to produce a VMDK disk file.
Producing a VMDK disk
A VMDK disk is just one of the supported output types that image mode for RHEL supports. Other formats include ISO, QCOW2, AMI, and VMI. Disk images can be deployed within a variety of environments, such as various public and private cloud platforms and edge servers which exemplifies the versatility that image mode for RHEL provides.
Disk images based on bootc images are produced using the bootc-image-builder containerized build tool. Similar to the base rhel-bootc image, it is also available from the Red Hat Registry for use on your local machine.
Execute the following command to retrieve the image:
podman pull registry.redhat.io/rhel9/bootc-image-builder:9.4
Once the image has been retrieved, the set of options that can be used to tailor the disk creation process can be found by running the image and exploring the choices available from the embedded bootc-image-builder
CLI:
podman run -it --rm registry.redhat.io/rhel9/bootc-image-builder:9.4 --help
Options, such as the type of disk format can be specified using the --type
argument, and the destination of the resulting disk image using the --output
argument. Additional options are also available for specific types of output formats. In particular, the AMI format supports automating the upload of the resulting AMI image to Amazon Web Services (AWS).
Generate a VMDK file from the previously created bootc image and target the output directory to store the produced disk image.
sudo podman run --rm -it --privileged -v /var/lib/containers/storage:/var/lib/containers/storage -v ./output:/output --security-opt label=type:unconfined_t --pull newer registry.redhat.io/rhel9/bootc-image-builder:9.4 --local --type vmdk localhost/rhel-bootc-vmdk:latest
Notice the use of the --local
argument within the command above. This option will leverage the local container storage to source the originating image to produce the VMDK instead of a remote repository. In most cases, you will want to publish a bootc image so that it can be consumed by others. However, in this case, since there was no requirement that the produced image was needed by another individual, this step was not necessary.
Once complete, a VMDK disk file for the bootc image is stored in the output/vmdk
directory, which is then usable on platforms supporting the VMDK file type. Keep in mind that additional output formats can be specified from the same bootc image enabling a single source of truth that can be deployed to a variety of environments and platforms.
Summary
In this article, we described how to use the rhel-bootc base image to create bootc image and then take the resulting image and produce a VMDK file using the bootc-image-builder
utility. With a VMDK file now available, we have the base primitives to support our overarching goal of using it at scale within a VMware vSphere environment. In the next article, we will discuss the steps to take the VMDK file, load it within a vSphere environment, and use it in a virtual machine.
In the next post in this series, we will describe how the previously created VMDK disk can be used as the basis for a virtual machine hosted in a VMware vSphere environment.
Last updated: August 5, 2024