Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Build and deploy image mode for RHEL on OpenShift Virtualization

November 11, 2024
Alessandro Rossi
Related topics:
ContainersDeveloper toolsEdge computingVirtualization
Related products:
Image mode for Red Hat Enterprise LinuxRed Hat Enterprise LinuxRed Hat OpenShiftRed Hat OpenShift Virtualization

    Image mode for Red Hat Enterprise Linux (RHEL), introduced as a tech preview in RHEL 9.4, offers a streamlined way to build, deploy, and maintain your operating system using container images. In this article, we will explore how to create and deploy a RHEL image mode web server on Red Hat OpenShift Virtualization.

    Build your web server

    First, we will build the RHEL image to provide access to an Apache httpd webserver based on a Containerfile that contains the following customizations:

    • A bootc-user with password redhat
    • The Apache httpd package installed
    • The Apache httpd service enabled
    • A custom index.html file serving our home page

    The final Containerfile is as follows:

    FROM registry.redhat.io/rhel9/rhel-bootc:9.4
    RUN dnf -y update && dnf -y install tmux mkpasswd
    RUN pass=$(mkpasswd --method=SHA-512 --rounds=4096 redhat) && useradd -m -G wheel bootc-user -p $pass
    RUN echo "%wheel        ALL=(ALL)       NOPASSWD: ALL" > /etc/sudoers.d/wheel-sudo
    RUN dnf -y install httpd && \
        systemctl enable httpd && \
        mv /var/www /usr/share/www && \
        sed -ie 's,/var/www,/usr/share/www,' /etc/httpd/conf/httpd.conf
    RUN echo "Welcome to the bootc-http instance!" > /usr/share/www/html/index.html
    EXPOSE 80

    All you need to do now is to log in to your registry; you can use a self-hosted registry or a public registry like quay.io:

    podman login $REGISTRY_URL

    You can now build and push the image using Podman:

    podman build -t $REGISTRY_URL/$USERNAME/awesome-webserver:v1.0
    podman push $REGISTRY_URL/$USERNAME/awesome-webserver:v1.0

    Once the image is ready, you can proceed to the next step, converting the image to the KVM QCOW2 format using bootc-image-builder.

    Convert your container image to QCOW2

    Red Hat OpenShift Virtualization can use QCOW2 images as a disk image source to deploy a virtual machine; hence, we will convert the previously built image to the required format.

    We can leverage the official Red Hat bootc-image-builder image to perform this task.

    First, create a folder named output where the final image will be stored:

    mkdir -p output

    Then run (as a privileged container) the image conversion:

    sudo podman run \
       --rm \
       -it \
       --privileged \
       --pull=newer \
       --security-opt label=type:unconfined_t \
       -v $(pwd)/output:/output \
       -v /var/lib/containers/storage:/var/lib/containers/storage \
       registry.redhat.io/rhel9/bootc-image-builder:latest \
       --type qcow2 \
       $REGISTRY_URL/$USERNAME/awesome-webserver:v1.0

    It will take some time to generate the final image, but after the process, we will have our image at this path: output/qcow2/disk.qcow2

    Create the necessary resources for the VM

    OpenShift Virtualization supports using a container image as a source for importing QCOW2 disks and converting them to bootable disks for the VMs. In this step, we will take the output of the previous process and embed it into a new container image, which will then be imported into OpenShift Virtualization to use for creating our brand new VM.

    FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS builder
    ADD --chown=107:107 output/qcow2/disk.qcow2 /disk/
    RUN chmod 0440 /disk/*
    FROM scratch
    COPY --from=builder /disk/* /disk/

    As you can see, all this Containerfile does is to place the QCOW2 image into the default disk/path where OpenShift Virtualization expects the disk image to be for importing.

    As usual, we will build and push the image, this time with a dedicated tag:

    podman build -t $REGISTRY_URL/$USERNAME/awesome-webserver:v1.0-ocpv
    podman push $REGISTRY_URL/$USERNAME/awesome-webserver:v1.0-ocpv

    The next step is where the magic happens. We will create a volume resource (Figure 1) that will take care of configuring the necessary jobs to fetch the image and create a bootable source for the VM we will create.

    The OpenShift Virtualization Catalog tab details, with the Volumes project drop-down menu at the top and the Add volume button highlighted in the top right corner.
    Figure 1: In the OpenShift dashboard, click Add volume to create the volume resource.

    Configure the input as follows (see Figure 2):

    • Registry URL: Replace REGISTRY_URL and YOURUSERNAME with the registry you are using and your username
    • Volume name: awesome-webserver
    • Cron: */2 * * * *
    • Preference: rhel.9
    • InstanceType: u1.small
    The Add volume details modal with the fields described in the preceding list, including a sample registry URL.
    Figure 2: Configure the volume source and destination details.

    We can verify that after a couple of minutes, the volume resource will appear in the OpenShift Virtualization catalog (Figure 3).

    The Create new VirtualMachine tab lists the example volume resource that was just added.
    Figure 3: The new volume resource has been added to the OpenShift Virtualization catalog.

    You can select the new boot volume, an instance type u1 Small, and proceed to the creation of the VM.

    After a few seconds, the VM will be up and running! Figure 4 shows the result.

    Under the VirtualMachines tab, the example virtual machine is listed with the status Running.
    Figure 4: The virtual machine displays the Running status upon successful creation.

    Expose and test the web server

    Now that our VM is running, let's access our web server and verify that it is serving our index page.

    To do so, we need to first create a service for the VM. In the Networking → Services tab, click Create Service (Figure 5) and paste the following YAML definition to ensure that the service is selecting the VM pod and exposing the port 80, where our server is listening:

    kind: Service
    apiVersion: v1
    metadata:
      name: http-server
      namespace: awesome-webserver
    spec:
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80
      selector:
        vm.kubevirt.io/name: my-awesome-webserver-vm
    Under Create Service, a block of YAML code is shown with a blue Create button beneath.
    Figure 5: Enter the YAML definition to set up the service for the VM.

    Once the service is in place, we can go into Networking → Routes to create an HTTP route to connect to our web server, as shown in Figure 6.

    Under Routes, the user can configure the HTTP route by completing the Name, Hostname, Path name, Service, and Target port fields.
    Figure 6: Create an HTTP route to connect to the web server.

    In your browser, navigate to the URL that was provided when you created the route to verify that the server is properly running. You should see a welcome message as illustrated in Figure 7.

    The message "Welcome to the bootc-http instance!" is shown in the browser.
    Figure 7: Navigate to the route URL to verify the web server is running.

    Wrap up

    In this article, we demonstrated how easy it is to build a RHEL image mode container and use Red Hat OpenShift Virtualization to deploy it in a few minutes without any additional tools or modifications. You can also automate this to enable deployment at scale for multiple instances and different hypervisors, cloud providers, or bare metal instances.

    Get started with image mode for Red Hat Enterprise Linux and learn more about bringing your virtual machines to OpenShift Virtualization.

    Related Posts

    • Announcing image mode for Red Hat Enterprise Linux

    • Image mode for Red Hat Enterprise Linux quick start: AI inference

    • Introducing image mode for RHEL and bootable containers in Podman Desktop

    • Creating a VMDK using image mode for Red Hat Enterprise Linux

    • How to back up and restore virtual machines with OpenShift

    • OpenShift Virtualization for vSphere admins: A change in the traditional storage paradigm

    Recent Posts

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    • Control multicluster costs with right-sizing in Red Hat Advanced Cluster Management 5

    • Lightbits is now certified for Red Hat OpenStack Services on OpenShift

    What’s up next?

    Learn how to utilize GitOps in OpenShift to manage your virtual machines in this hands-on learning path.

    Start learning
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI