Search

Chapter 9. Preparing and deploying a KVM Guest Image by using RHEL image builder

download PDF

Use RHEL image builder to create a .qcow2 purpose-built that you can deploy on a Kernel-based Virtual Machine (KVM) based hypervisor.

Creating a customized KVM guest image involves the following high-level steps:

  1. Create a blueprint for the .qcow2 image.
  2. Create a .qcow2 image by using RHEL image builder.
  3. Create a virtual machine from the KVM guest image.

9.1. Creating customized KVM guest images by using RHEL image builder

You can create a customized .qcow2 KVM guest image by using RHEL image builder. The following procedure shows the steps on the GUI, but you can also use the CLI.

Prerequisites

  • You must be in the root or weldr group to access the system.
  • The cockpit-composer package is installed.
  • On a RHEL system, you have opened the RHEL image builder dashboard of the web console.
  • You have created a blueprint. See Creating a blueprint in the web console interface.

Procedure

  1. Click the blueprint name you created.
  2. Select the tab Images.
  3. Click Create Image to create your customized image. The Create Image window opens.
  4. From the Type drop-down menu list, select QEMU Image(.qcow2).
  5. Set the size that you want the image to be when instantiated and click Create.
  6. A small pop-up on the upper right side of the window informs you that the image creation has been added to the queue. After the image creation process is complete, you can see the Image build complete status.

Verification

  • Click the breadcrumbs icon and select the Download option. RHEL image builder downloads the KVM guest image .qcow2 file at your default download location.

9.2. Creating a virtual machine from a KVM guest image

With RHEL image builder, you can build a .qcow2 image, and use a KVM guest image to create a VM. The KVM guest images created using RHEL image builder already have cloud-init installed and enabled.

Prerequisites

  • You created a .qcow2 image by using RHEL image builder. See Creating a blueprint in the web console interface.
  • You have the qemu-kvm package installed on your system. You can check if the /dev/kvm device is available on your system, and virtualization features are enabled in the BIOS.
  • You have the libvirt and virt-install packages installed on your system.
  • You have the genisoimage utility, that is provided by the xorriso package, installed on your system.

Procedure

  1. Move the .qcow2 image that you created by using RHEL image builder to the /var/lib/libvirt/images/ directory.
  2. Create a directory, for example, cloudinitiso and navigate to this newly created directory:

    $ mkdir cloudinitiso
    $ cd cloudinitiso
  3. Create a file named meta-data. Add the following information to this file:

    instance-id: citest
    local-hostname: vmname
  4. Create a file named user-data. Add the following information to the file:

    #cloud-config
    user: admin
    password: password
    chpasswd: {expire: False}
    ssh_pwauth: True
    ssh_authorized_keys:
      - ssh-rsa AAA...fhHQ== your.email@example.com

    ssh_authorized_keys is your SSH public key. You can find your SSH public key in ~/.ssh/<id_rsa.pub>\.

  5. Use the genisoimage utility to create an ISO image that includes the user-data and meta-data files.

    # genisoimage -output cloud-init.iso -volid cidata -joliet -rock user-data meta-data
    
    I: -input-charset not specified, using utf-8 (detected in locale settings)
    Total translation table size: 0
    Total rockridge attributes bytes: 331
    Total directory bytes: 0
    Path table size(bytes): 10
    Max brk space used 0
    183 extents written (0 MB)
  6. Create a new VM from the KVM Guest Image using the virt-install command. Include the ISO image you created on step 4 as an attachment to the VM image.

    # virt-install \
        --memory 4096 \
        --vcpus 4 \
        --name myvm \
        --disk rhel-8-x86_64-kvm.qcow2,device=disk,bus=virtio,format=qcow2 \
        --disk cloud-init.iso,device=cdrom \
        --os-variant rhel 8 \
        --virt-type kvm \
        --graphics none \
        --import
    • --graphics none - means it is a headless RHEL 8 VM.
    • --vcpus 4 - means that it uses 4 virtual CPUs.
    • --memory 4096 - means it uses 4096 MB RAM.
  7. The VM installation starts:

    Starting install...
    Connected to domain mytestcivm
    ...
    [  OK  ] Started Execute cloud user/final scripts.
    [  OK  ] Reached target Cloud-init target.
    
    Red Hat Enterprise Linux 8 (Ootpa)
    Kernel 4.18.0-221.el8.x86_64 on an x86_64

Verification

After the boot is complete, the VM shows a text login interface. To log in to the local console of the VM, use user the details from the user-data file:

  1. Enter admin as a username and press Enter.
  2. Enter password as password and press Enter.

    After the login authentication is complete, you have access to the VM using the CLI.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.