Red Hat Training

A Red Hat training course is available for RHEL 8

Chapter 5. Preparing and deploying KVM guest images with Image Builder

Customers can manually create images from an ISO or have a purpose-built image created using Image Builder. This procedure describes steps to create a purpose-built image using Image Builder. This is limited to rhel-guest-image support to Red Hat Virtualization (RHV).

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

  1. Creating a KVM guest Image .qcow2 image using Image Builder.
  2. Creating a virtual machine from the KVM guest image.

5.1. Creating customized KVM guest images with Image Builder

This describes steps to create a .qcow2 KVM guest image using Image Builder.

Prerequisites

  • You must have root or wheel group user access to the system.
  • The cockpit-composer package is installed.
  • On a RHEL system, you have opened the Image Builder dashboard of Cockpit UI.

Procedure

  1. Click Create blueprint to create a blueprint. See Creating an Image Builder blueprint in the web console interface.
  2. Select the components and packages that you want as part of the KVM guest image you are creating.
  3. Click Commit to commit the changes you made to the blueprint. A small pop-up on the superior right side informs you of the saving progress and then the result of the changes you commited.
  4. Click the blueprint name link on the left banner.
  5. Select the tab Images.
  6. Click Create Image to create your customized image. A pop-up window opens.
  7. From the Type drop-down menu list, select the `QEMU Image(.qcow2)' image.
  8. Set the size that you want the image to be when instantiated and click Create.
  9. A small pop-up on the upper right side of the window informs you that the image creation has been added to the queue. Once the image creation process is complete, you can see the Image build complete status.

Verification steps

  1. Click the breadcrumbs icon and select the Download option. Image Builder downloads the KVM guest image .qcow2 file at your default download location.

5.2. Creating a virtual machine from a KVM guest image

To quickly create virtual machines with small footprint on the host, you can use a KVM guest image. This procedure uses a KVM guest image generated by Image Builder as a .qcow2 image format to create a Virtual Machine (VM). KVM guest images created using Image Builder already have cloud-init installed and enabled.

Prerequisites

  • You created a .qcow2 image using Image Builder. See Creating an Image Builder blueprint in the web console interface.
  • The qemu-kvm package is installed on your system. You can check the /dev/kvm folder is available on your system.
  • You have libvirt installed on your system.
  • You have virt-install installed on your system.
  • The genisoimage utility is installed on your system.

Procedure

  1. Move the KVM Guest Image you created using Image Builder to the /var/lib/libvirt/images directory and and rename the image name to rhel-8.4-x86_64-kvm.qcow2.
  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: citest-1
  4. Create a file named user-data. Add the following information to the file:

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

    Where,

    • ssh_authorized_keys is your SSH public key. You can find your SSH public key in ~/.ssh/id_rsa.pub.
  5. Use the genisoimage command to create an ISO image that includes the user-data and meta-data files.

    # genisoimage -output ciiso.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 mytestcivm \
        --disk /var/lib/libvirt/images/rhel-8.4-x86_64-kvm.qcow2,device=disk,bus=virtio,format=qcow2 \
        --disk /home/sample/cloudinitiso/ciiso.iso,device=cdrom \
        --os-variant rhel8.4 \
        --virt-type kvm \
        --graphics none \
        --import

    Where,

    • --graphics none - means it is a headless RHEL 8.4 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.4 Beta (Ootpa)
    Kernel 4.18.0-221.el8.x86_64 on an x86_64

Verification

  1. Log in to the created VM, using cloud-user as a username. Your password is cilogon.