Chapter 2. Creating RHEL KVM or RHOSP-compatible images

To create images that you can manage in the Red Hat OpenStack Platform (RHOSP) Image service (glance), you can use Red Hat Enterprise Linux (RHEL) Kernel-based Virtual Machine (KVM) instance images, or you can manually create RHOSP-compatible images in the QCOW2 format by using RHEL ISO files or Windows ISO files.

2.1. Creating RHEL KVM images

Use Red Hat Enterprise Linux (RHEL) Kernel-based Virtual Machine (KVM) instance images to create images that you can manage in the Red Hat OpenStack Platform (RHOSP) Image service (glance).

2.1.1. Using a RHEL KVM instance image with Red Hat OpenStack Platform

You can use one of the following Red Hat Enterprise Linux (RHEL) Kernel-based Virtual Machine (KVM) instance images with Red Hat OpenStack Platform (RHOSP):

These QCOW2 images are configured with cloud-init and must have EC2-compatible metadata services for provisioning Secure Shell (SSH) keys to function correctly.

Ready Windows KVM instance images in QCOW2 format are not available.

Note

For KVM instance images:

  • The root account in the image is deactivated, but sudo access is granted to a special user named cloud-user.
  • There is no root password set for this image.

The root password is locked in /etc/shadow by placing !! in the second field.

For a RHOSP instance, generate an SSH keypair from the RHOSP dashboard or command line, and use that key combination to perform an SSH public authentication to the instance as root user.

When you launch the instance, this public key is injected to it. You can then authenticate by using the private key that you download when you create the keypair.

2.1.2. Creating a RHEL-based root partition image for bare-metal instances

To create a custom root partition image for bare-metal instances, download the base Red Hat Enterprise Linux KVM instance image, and then upload the image to the Image service (glance).

Procedure

  1. Download the base Red Hat Enterprise Linux KVM instance image from the Customer Portal.
  2. Define DIB_LOCAL_IMAGE as the downloaded image:

    $ export DIB_LOCAL_IMAGE=rhel-<ver>-x86_64-kvm.qcow2
    • Replace <ver> with the RHEL version number of the image.
  3. Set your registration information depending on your method of registration:

    • Red Hat Customer Portal:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_AUTO_ATTACH=true
      $ export REG_METHOD=portal
      $ export https_proxy='<IP_address:port>' (if applicable)
      $ export http_proxy='<IP_address:port>' (if applicable)
    • Red Hat Satellite:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_SAT_URL='<satellite-url>'
      $ export REG_ORG='<satellite-org>'
      $ export REG_ENV='<satellite-env>'
      $ export REG_METHOD=<method>
    • Replace values in angle brackets <> with the correct values for your Red Hat Customer Portal or Red Hat Satellite registration.
  4. Optional: If you have any offline repositories, you can define DIB_YUM_REPO_CONF as a local repository configuration:

    $ export DIB_YUM_REPO_CONF=<file-path>
    • Replace <file-path> with the path to your local repository configuration file.
  5. Use the diskimage-builder tool to extract the kernel as rhel-image.vmlinuz and the initial RAM disk as rhel-image.initrd:

    $ export DIB_RELEASE=<ver>
    $ disk-image-create rhel baremetal \
      -o rhel-image
  6. Upload the images to the Image service:

    $ KERNEL_ID=$(openstack image create \
      --file rhel-image.vmlinuz --public \
      --container-format aki --disk-format aki \
      -f value -c id rhel-image.vmlinuz)
    $ RAMDISK_ID=$(openstack image create \
      --file rhel-image.initrd --public \
      --container-format ari --disk-format ari \
      -f value -c id rhel-image.initrd)
    $ openstack image create \
      --file rhel-image.qcow2   --public \
      --container-format bare \
      --disk-format qcow2 \
      --property kernel_id=$KERNEL_ID \
      --property ramdisk_id=$RAMDISK_ID \
      rhel-root-partition-bare-metal-image

2.1.3. Creating a RHEL-based whole-disk user image for bare-metal instances

To create a whole-disk user image for bare-metal instances, download the base Red Hat Enterprise Linux KVM instance image, and then upload the image to the Image service (glance).

Procedure

  1. Download the base Red Hat Enterprise Linux KVM instance image from the Customer Portal.
  2. Define DIB_LOCAL_IMAGE as the downloaded image:

    $ export DIB_LOCAL_IMAGE=rhel-<ver>-x86_64-kvm.qcow2
    • Replace <ver> with the RHEL version number of the image.
  3. Set your registration information depending on your method of registration:

    • Red Hat Customer Portal:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_AUTO_ATTACH=true
      $ export REG_METHOD=portal
      $ export https_proxy='<IP_address:port>' (if applicable)
      $ export http_proxy='<IP_address:port>' (if applicable)
    • Red Hat Satellite:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_SAT_URL='<satellite-url>'
      $ export REG_ORG='<satellite-org>'
      $ export REG_ENV='<satellite-env>'
      $ export REG_METHOD=<method>
    • Replace values in angle brackets <> with the correct values for your Red Hat Customer Portal or Red Hat Satellite registration.
  4. Optional: If you have any offline repositories, you can define DIB_YUM_REPO_CONF as a local repository configuration:

    $ export DIB_YUM_REPO_CONF=<file-path>
    • Replace <file-path> with the path to your local repository configuration file.
  5. Upload the image to the Image service:

    $ openstack image create \
      --file rhel-image.qcow2 --public \
      --container-format bare \
      --disk-format qcow2 \
      rhel-whole-disk-bare-metal-image

2.2. Creating instance images with RHEL or Windows ISO files

You can create custom Red Hat Enterprise Linux (RHEL) or Windows images in QCOW2 format from ISO files, and upload these images to the Red Hat OpenStack Platform (RHOSP) Image service (glance) for use when creating instances.

2.2.1. Prerequisites

  • A Linux host machine to create an image. This can be any machine on which you can install and run the Linux packages, except for the undercloud or the overcloud.
  • The advanced-virt repository is enabled:

    $ sudo subscription-manager repos --enable=advanced-virt-for-rhel-<ver>-x86_64-rpms
  • The virt-manager application is installed to have all packages necessary to create a guest operating system:

    $ sudo dnf module install -y virt
  • The libguestfs-tools package is installed to have a set of tools to access and modify virtual machine images:

    $ sudo dnf install -y libguestfs-tools-c
  • A RHEL 9 or 8 ISO file or a Windows ISO file. For more information about RHEL ISO files, see RHEL 9.0 Binary DVD or RHEL 8.6 Binary DVD. If you do not have a Windows ISO file, see the Microsoft Evaluation Center to download an evaluation image.
  • A text editor, if you want to change the kickstart files (RHEL only).
Important

If you install the libguestfs-tools package on the undercloud, deactivate iscsid.socket to avoid port conflicts with the tripleo_iscsid service on the undercloud:

$ sudo systemctl disable --now iscsid.socket

When you have the prerequisites in place, you can proceed to create a RHEL or Windows image:

2.2.2. Creating a Red Hat Enterprise Linux 9 image

You can create a Red Hat OpenStack Platform (RHOSP) image in QCOW2 format by using a Red Hat Enterprise Linux (RHEL) 9 ISO file.

Procedure

  1. Log on to your host machine as the root user.
  2. Start the installation by using virt-install:

    [root@host]# virt-install \
      --virt-type kvm \
      --name <rhel9-cloud-image> \
      --ram <2048> \
      --cdrom </var/lib/libvirt/images/rhel-9.0-x86_64-dvd.iso> \
      --disk <rhel9.qcow2>,format=qcow2,size=<10> \
      --network=bridge:virbr0 \
      --graphics vnc,listen=127.0.0.1 \
      --noautoconsole \
      --os-variant=<rhel9.0>
    • Replace the values in angle brackets <> with the correct values for your RHEL 9 image.

      This command launches an instance and starts the installation process.

      Note

      If the instance does not launch automatically, run the virt-viewer command to view the console:

      [root@host]# virt-viewer <rhel9-cloud-image>
  3. Configure the instance:

    1. At the initial Installer boot menu, select Install Red Hat Enterprise Linux 9.
    2. Choose the appropriate Language and Keyboard options.
    3. When prompted about which type of devices your installation uses, select Auto-detected installation media.
    4. When prompted about which type of installation destination, select Local Standard Disks. For other storage options, select Automatically configure partitioning.
    5. In the Which type of installation would you like? window, choose the Basic Server install, which installs an SSH server.
    6. For network and host name, select eth0 for network and choose a host name for your device. The default host name is localhost.localdomain.
    7. Enter a password in the Root Password field and enter the same password again in the Confirm field.
  4. When the on-screen message confirms that the installation is complete, reboot the instance and log in as the root user.
  5. Update the /etc/sysconfig/network-scripts/ifcfg-eth0 file so that it contains only the following values:

    TYPE=Ethernet
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=dhcp
    NM_CONTROLLED=no
  6. Reboot the machine.
  7. Register the machine with the Content Delivery Network.

    # sudo subscription-manager register
    # sudo subscription-manager attach \
      --pool=<pool-id>
    # sudo subscription-manager repos \
      --enable rhel-9-for-x86_64-baseos-rpms \
      --enable rhel-9-for-x86_64-appstream-rpms
    • Replace pool-id with a valid pool ID. You can see a list of available pool IDs by running the subscription-manager list --available command.
  8. Update the system:

    # dnf -y update
  9. Install the cloud-init packages:

    # dnf install -y cloud-utils-growpart cloud-init
  10. Edit the /etc/cloud/cloud.cfg configuration file and add the following content under cloud_init_modules:

    - resolv-conf

    The resolv-conf option automatically configures the resolv.conf file when an instance boots for the first time. This file contains information related to the instance such as nameservers, domain, and other options.

  11. Add the following line to /etc/sysconfig/network to avoid issues when accessing the EC2 metadata service:

    NOZEROCONF=yes
  12. To ensure that the console messages appear in the Log tab on the dashboard and the nova console-log output, add the following boot option to the /etc/default/grub file:

    GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"
  13. Run the grub2-mkconfig command:

    # grub2-mkconfig -o /boot/grub2/grub.cfg

    The output is as follows:

    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-3.10.0-229.9.2.el9.x86_64
    Found initrd image: /boot/initramfs-3.10.0-229.9.2.el9.x86_64.img
    Found linux image: /boot/vmlinuz-3.10.0-121.el9.x86_64
    Found initrd image: /boot/initramfs-3.10.0-121.el9.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-b82a3044fb384a3f9aeacf883474428b
    Found initrd image: /boot/initramfs-0-rescue-b82a3044fb384a3f9aeacf883474428b.img
    done
  14. Deregister the instance so that the resulting image does not contain the subscription details for this instance:

    # subscription-manager repos --disable=*
    # subscription-manager unregister
    # dnf clean all
  15. Power off the instance:

    # poweroff
  16. Reset and clean the image by using the virt-sysprep command so that it can be used to create instances without issues:

    [root@host]# virt-sysprep -d <rhel9-cloud-image>
  17. Reduce the image size by converting any free space in the disk image back to free space in the host:

    [root@host]# virt-sparsify \
      --compress <rhel9.qcow2> <rhel9-cloud.qcow2>

    This command creates a new <rhel9-cloud.qcow2> file in the location from where the command is run.

    Note

    You must manually resize the partitions of instances based on the image in accordance with the disk space in the flavor that is applied to the instance.

The <rhel9-cloud.qcow2> image file is ready to be uploaded to the Image service. For more information about uploading this image to your RHOSP deployment, see Uploading images to the Image service.

2.2.3. Creating a Red Hat Enterprise Linux 8 image

You can create a Red Hat OpenStack Platform (RHOSP) image in QCOW2 format by using a Red Hat Enterprise Linux (RHEL) 8 ISO file.

Procedure

  1. Log on to your host machine as the root user.
  2. Start the installation by using virt-install:

    [root@host]# virt-install \
      --virt-type kvm \
      --name <rhel86-cloud-image> \
      --ram <2048> \
      --vcpus <2> \
      --disk <rhel86.qcow2>,format=qcow2,size=<10> \
      --location <rhel-8.6-x86_64-boot.iso> \
      --network=bridge:virbr0 \
      --graphics vnc,listen=127.0.0.1 \
      --noautoconsole \
      --os-variant <rhel8.6>
    • Replace the values in angle brackets <> with the correct values for your RHEL image.

      This command launches an instance and starts the installation process.

      Note

      If the instance does not launch automatically, run the virt-viewer command to view the console:

      [root@host]# virt-viewer <rhel86-cloud-image>
  3. Configure the instance:

    1. At the initial Installer boot menu, select Install Red Hat Enterprise Linux 8.
    2. Choose the appropriate Language and Keyboard options.
    3. When prompted about which type of devices your installation uses, select Basic Storage Devices.
    4. Choose a host name for your device. The default host name is localhost.localdomain.
    5. Set the timezone and root password.
    6. In the Which type of installation would you like? window, choose the Basic Server install, which installs an SSH server.
  4. When the on-screen message confirms that the installation is complete, reboot the instance and log in as the root user.
  5. Update the /etc/sysconfig/network-scripts/ifcfg-eth0 file so that it contains only the following values:

    TYPE=Ethernet
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=dhcp
    NM_CONTROLLED=no
  6. Reboot the machine.
  7. Register the machine with the Content Delivery Network:

    # sudo subscription-manager register
    # sudo subscription-manager attach \
      --pool=<pool-id>
    # sudo subscription-manager repos \
      --enable rhel-8-for-x86_64-baseos-rpms \
      --enable rhel-8-for-x86_64-appstream-rpms
    • Replace pool-id with a valid pool ID. You can see a list of available pool IDs by running the subscription-manager list --available command.
  8. Update the system:

    # dnf -y update
  9. Install the cloud-init packages:

    # dnf install -y cloud-utils-growpart cloud-init
  10. Edit the /etc/cloud/cloud.cfg configuration file and add the following content under cloud_init_modules.

    - resolv-conf

    The resolv-conf option automatically configures the resolv.conf file when an instance boots for the first time. This file contains information related to the instance such as nameservers, domain, and other options.

  11. To prevent network issues, create /etc/udev/rules.d/75-persistent-net-generator.rules:

    # echo "#" > /etc/udev/rules.d/75-persistent-net-generator.rules

    This prevents the /etc/udev/rules.d/70-persistent-net.rules file from being created. If the /etc/udev/rules.d/70-persistent-net.rules file is created, networking might not function correctly when you boot from snapshots because the network interface is created as eth1 instead of eth0 and the IP address is not assigned.

  12. Add the following line to /etc/sysconfig/network to avoid issues when accessing the EC2 metadata service:

    NOZEROCONF=yes
  13. To ensure that the console messages appear in the Log tab on the dashboard and the nova console-log output, add the following boot option to the /etc/grub.conf file:

    GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"
  14. Deregister the instance so that the resulting image does not contain the same subscription details for this instance:

    # subscription-manager repos --disable=*
    # subscription-manager unregister
    # dnf clean all
  15. Power off the instance:

    # poweroff
  16. Reset and clean the image by using the virt-sysprep command so that it can be used to create instances without issues:

    [root@host]# virt-sysprep -d <rhel86-cloud-image>
  17. Reduce the image size by converting any free space in the disk image back to free space in the host:

    [root@host]# virt-sparsify \
      --compress <rhel86.qcow2> <rhel86-cloud.qcow2>

    This command creates a new <rhel86-cloud.qcow2> file in the location from where the command is run.

    Note

    You must manually resize the partitions of instances based on the image in accordance with the disk space in the flavor that is applied to the instance.

The <rhel86-cloud.qcow2> image file is ready to be uploaded to the Image service. For more information about uploading this image to your RHOSP deployment, see Uploading images to the Image service.

2.2.4. Creating a Windows image

You can create a Red Hat OpenStack Platform (RHOSP) image in QCOW2 format by using a Windows ISO file.

Procedure

  1. Log on to your host machine as the root user.
  2. Start the installation by using virt-install:

    [root@host]# virt-install \
        --name=<windows-image> \
        --disk size=<size> \
        --cdrom=<file-path-to-windows-iso-file> \
        --os-type=windows \
        --network=bridge:virbr0 \
        --graphics spice \
        --ram=<ram>
    • Replace the values in angle brackets <> withe the correct values for your Windows image.

      Note

      The --os-type=windows parameter ensures that the clock is configured correctly for the Windows instance and enables its Hyper-V enlightenment features. You must also set os_type=windows in the image metadata before uploading the image to the Image service (glance).

  3. The virt-install command saves the instance image as /var/lib/libvirt/images/<windows-image>.qcow2 by default. If you want to keep the instance image elsewhere, change the parameter of the --disk option:

    --disk path=<file-name>,size=<size>
    • Replace <file-name> with the name of the file that stores the instance image, and optionally its path. For example, path=win8.qcow2,size=8 creates an 8 GB file named win8.qcow2 in the current working directory.

      Note

      If the instance does not launch automatically, run the virt-viewer command to view the console:

      [root@host]# virt-viewer <windows-image>

      For more information about how to install Windows, see the Microsoft documentation.

  4. To allow the newly-installed Windows system to use the virtualized hardware, you might need to install VirtIO drivers. For more information, see Installing KVM paravirtualized drivers for Windows virtual machines in Configuring and managing virtualization.
  5. To complete the configuration, download and run Cloudbase-Init on the Windows system. At the end of the installation of Cloudbase-Init, select the Run Sysprep and Shutdown checkboxes. The Sysprep tool makes the instance unique by generating an OS ID, which is used by certain Microsoft services.

    Important

    Red Hat does not provide technical support for Cloudbase-Init. If you encounter an issue, see Contact Cloudbase Solutions.

    When the Windows system shuts down, the <windows-image.qcow2> image file is ready to be uploaded to the Image service. For more information about uploading this image to your RHOSP deployment, see Uploading images to the Image service.

2.3. Creating an image for UEFI Secure Boot

When the overcloud contains UEFI Secure Boot Compute nodes, you can create a Secure Boot instance image that cloud users can use to launch Secure Boot instances.

Procedure

  1. Create a new image for UEFI Secure Boot:

    $ openstack image create --file <base_image_file> uefi_secure_boot_image
    • Replace <base_image_file> with an image file that supports UEFI and the GUID Partition Table (GPT) standard, and includes an EFI system partition.
  2. If the default machine type is not q35, then set the machine type to q35:

    $ openstack image set --property hw_machine_type=q35 uefi_secure_boot_image
  3. Specify that the instance must be scheduled on a UEFI Secure Boot host:

    $ openstack image set \
     --property hw_firmware_type=uefi \
     --property os_secure_boot=required \
     uefi_secure_boot_image

2.4. Metadata properties for virtual hardware

The Compute service (nova) has deprecated support for using libosinfo data to set default device models. Instead, use the following image metadata properties to configure the optimal virtual hardware for an instance:

  • os_distro
  • os_version
  • hw_cdrom_bus
  • hw_disk_bus
  • hw_scsi_model
  • hw_vif_model
  • hw_video_model
  • hypervisor_type

For more information about these metadata properties, see Image configuration parameters.