Search

Chapter 2. Managing images

download PDF

The Image service (glance) provides discovery, registration, and delivery services for disk and server images. It provides the ability to copy or snapshot a server image, and immediately store it. You can use stored images as templates to commission new servers quickly and more consistently than installing a server operating system and individually configuring services.

2.1. Creating images

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

2.1.1. Use a KVM guest image with Red Hat OpenStack Platform

You can use one of the following ready Red Hat Enterprise Linux (RHEL) Kernel-based Virtual Machine (KVM) guest QCOW2 images:

These images are configured with cloud-init and must take advantage of EC2-compatible metadata services for provisioning SSH keys to function correctly.

Ready Windows KVM guest QCOW2 images are not available.

Note

For KVM guest 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 Red Hat OpenStack Platform (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. Create custom Red Hat Enterprise Linux or Windows images

To create custom Red Hat Enterprise Linux (RHEL) or Windows images, ensure that you have the following prerequistes in place.

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-8-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, disable iscsid.socket to avoid port conflicts with the tripleo_iscsid service on the undercloud:

$ sudo systemctl disable --now iscsid.socket

2.1.3. Creating a Red Hat Enterprise Linux 9 image

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

Note

You must run all commands with the [root@host]# on your host machine.

Procedure

  1. Start the installation by using virt-install:

    [root@host]# virt-install \
      --virt-type kvm \
      --name <rhel9> \
      --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>
  2. 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. 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.

      Result
      The installation process completes and the Complete! screen is displayed.
  3. After the installation is complete, reboot the instance and log in as the root user.
  4. 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
  5. Reboot the machine.
  6. Register the machine with the Content Delivery Network.

    # sudo subscription-manager register
    # sudo subscription-manager attach --pool=Valid-Pool-Number-123456
    # sudo subscription-manager repos --enable=rhel-9-server-rpms
  7. Update the system:

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

    # dnf install -y cloud-utils-growpart cloud-init
  9. 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.

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

    NOZEROCONF=yes
  11. 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"
  12. 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
  13. 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
  14. Power off the instance:

    # poweroff
  15. 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>
  16. Reduce the image size by converting any free space within the disk image back to free space within 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 an image.

2.1.4. Creating a Red Hat Enterprise Linux 8 image

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

Note

You must run all commands with the [root@host]# on your host machine.

Procedure

  1. 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 8 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>
  2. Configure the instances:

    1. At the initial Installer boot menu, select Install or upgrade an existing system and follow the installation prompts. Accept the defaults.

      The disk installer provides an option to test your installation media before installation. Select OK to run the test or Skip to proceed without testing.

    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. Based on the space on the disk, choose the type of installation you want from the options in the Which type of installation would you like? window.
    7. Choose the Basic Server install, which installs an SSH server.
    8. The installation process completes and the Congratulations, your Red Hat Enterprise Linux installation is complete screen is displayed.
  3. Reboot the instance and log in as the root user.
  4. 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
  5. Reboot the machine.
  6. Register the machine with the Content Delivery Network:

    # sudo subscription-manager register
    # sudo subscription-manager attach --pool=Valid-Pool-Number-123456
    # sudo subscription-manager repos --enable=rhel-8-server-rpms
  7. Update the system:

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

    # dnf install -y cloud-utils-growpart cloud-init
  9. 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.

  10. 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.

  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/grub.conf file:

    console=tty0 console=ttyS0,115200n8
  13. Deregister the virtual machine 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
  14. Power off the instance:

    # poweroff
  15. 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>
  16. Reduce the image size by using the virt-sparsify command. This command converts any free space within the disk image back to free space within 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 an image.

2.1.5. Creating a Windows image

Manually create a Red Hat OpenStack Platform (RHOSP) compatible image in the QCOW2 format by using a Windows ISO file.

Note

You must run all commands with the [root@host]# on your host machine.

Procedure

  1. Start the installation by using virt-install:

    [root@host]# virt-install \
        --name=<name> \
        --disk size=<size> \
        --cdrom=<path> \
        --os-type=windows \
        --network=bridge:virbr0 \
        --graphics spice \
        --ram=<ram>
    • Replace the following values of the virt-install parameters:

      • <name> — the name that the Windows instance has.
      • <size> — disk size in GB.
      • <path> — the path to the Windows installation ISO file.
      • <RAM> — the requested amount of RAM in MB.

        Note

        The --os-type=windows parameter ensures that the clock is configured correctly for the Windows guest, 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).

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

    --disk path=<filename>,size=<size>
    • Replace <filename> 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.

      Tip

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

      [root@host]# virt-viewer <name>

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

  3. To allow the newly installed Windows system to use the virtualized hardware, you might need to install VirtIO drivers. To do so, install the image by attaching it as a CD-ROM drive to the Windows instance. To install the virtio-win package, you must add the VirtIO ISO image to the instance, and install the VirtIO drivers. For more information, see Installing KVM paravirtualized drivers for Windows virtual machines in Configuring and managing virtualization.
  4. To complete the configuration, download and execute 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 guest 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 <name>.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 an image.

2.1.5.1. Metadata properties

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.

2.1.6. Create 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.2. Uploading an image

Upload an image to the Red Hat OpenStack Platform (RHOSP) Image service (glance).

Procedure

  • Use the glance image-create command with the property option to upload an image.

    For example:

    $ glance image-create --name <NAME> \
        --is-public true --disk-format qcow2 \
        --container-format bare \
        --file <IMAGE_FILE> \
        --property <IMAGE_METADATA>

2.3. Updating an image

Update an image.

Procedure

2.4. Importing an image

You can import images to the Image service (glance) by using one of the following two methods:

  • Use web-download to import an image from a URI.
  • Use glance-direct to import an image from a local file system.

The web-download method is enabled by default. The cloud administrator configures import methods. You can run the glance import-info command to list available import options.

2.4.1. Import an image from a remote URI

You can use the web-download method to copy an image from a remote URI.

  1. Create an image and specify the URI of the image to import:

    $ glance image-create-via-import \
        --container-format <CONTAINER FORMAT> \
        --disk-format <DISK-FORMAT> \
        --name <NAME> \
        --import-method web-download \
        --uri <URI>
    • Replace <CONTAINER FORMAT> with the container format that you are setting set for your image (None, ami, ari, aki, bare, ovf, ova, docker).
    • Replace <DISK-FORMAT> with the disk format that you are setting set for your image (None, ami, ari, aki, vhd, vhdx, vmdk, raw, qcow2, vdi, iso, ploop).
    • Replace <NAME> with a descriptive name for your image.
    • Replace <URI> with the URI of your image.
  2. You can check the availability of the image by using the glance image-show <IMAGE_ID> command.

    • Replace <IMAGE_ID> with the ID you provided during image creation.

The Image service web download method uses a two-stage process to perform the import:

  1. The web download method creates an image record.
  2. The web download method retrieves the image from the specified URI.

The URI is subject to optional denylist and allowlist filtering.

The Image Property Injection plugin may inject metadata properties to the image. These injected properties determine which compute nodes the image instances are launched on.

2.4.2. Import an image from a local volume

The glance-direct method creates an image record, which generates an image ID. After the image is uploaded to the Image service from a local volume, it is stored in a staging area and is made active after it passes any configured checks. The glance-direct method requires a shared staging area when used in a highly available (HA) configuration.

Note

Image uploads that use the glance-direct method can fail in a HA environment if a common staging area is not present. In a HA active-active environment, API calls are distributed to the Image service controllers. The download API call can be sent to a different controller than the API call to upload the image.

The glance-direct method uses three different calls to import an image:

  • glance image-create
  • glance image-stage
  • glance image-import

You can use the glance image-create-via-import command to perform all three of these calls in one command:

$ glance image-create-via-import \
    --container-format <CONTAINER FORMAT> \
    --disk-format <DISK-FORMAT> \
    --name <NAME> \
    --file </PATH/TO/IMAGE>
  • Replace <CONTAINER FORMAT>, <DISK-FORMAT>, <NAME>, and </PATH/TO/IMAGE> with the relevant values for your image.

After the image moves from the staging area to the back-end location, the image is listed. However, it might take some time for the image to become active.

You can check the availability of the image by using the glance image-show <IMAGE_ID> command.

  • Replace <IMAGE_ID with the ID you provided during image creation.

2.5. Deleting an image

Procedure

  • Use the glance image-delete command to delete one or more images:

    $ glance image-delete <IMAGE_ID> [<IMAGE_ID> ...]
    • Replace <IMAGE_ID> with the ID of the image you want to delete.

      Note

      The glance image-delete command permanently deletes the image and all copies of the image, as well as the image instance and metadata.

2.6. Hiding or unhiding an image

You can hide public images from normal listings presented to users. For instance, you can hide obsolete CentOS 7 images and show only the latest version to simplify the user experience. Users can discover and use hidden images.

To hide an image:

glance image-update <image_id> --hidden 'true'

To create a hidden image, add the --hidden argument to the glance image-create command.

To unhide an image:

glance image-update <image_id> --hidden 'false'

Show hidden images

To list hidden images:

glance image-list --hidden 'true'

2.7. Enabling image conversion

You can upload a QCOW2 image to the Image service (glance) by enabling the GlanceImageImportPlugins parameter. You can then convert the QCOW2 image to RAW format.

Note

Image conversion is automatically enabled when you use Red Hat Ceph Storage RADOS Block Device (RBD) to store images and boot Nova instances.

To enable image conversion, create an environment file that contains the following parameter value. Include the new environment file with the -e option in the openstack overcloud deploy command:

parameter_defaults:
  GlanceImageImportPlugins:'image_conversion'

Use the Image service command-line client for image management.

2.7.1. Converting an image to RAW format

Red Hat Ceph Storage can store, but does not support using, QCOW2 images to host virtual machine (VM) disks.

When you upload a QCOW2 image and create a VM from it, the compute node downloads the image, converts the image to RAW, and uploads it back into Ceph, which can then use it. This process affects the time it takes to create VMs, especially during parallel VM creation.

For example, when you create multiple VMs simultaneously, uploading the converted image to the Ceph cluster might impact already running workloads. The upload process can starve those workloads of IOPS and impede storage responsiveness.

To boot VMs in Ceph more efficiently (ephemeral back end or boot from volume), the glance image format must be RAW.

Procedure

  1. Converting an image to RAW might yield an image that is larger in size than the original QCOW2 image file. Run the following command before the conversion to determine the final RAW image size:

    qemu-img info <image>.qcow2
  2. Convert an image from QCOW2 to RAW format:

    qemu-img convert -p -f qcow2 -O raw <original qcow2 image>.qcow2 <new raw image>.raw

2.7.1.1. Configuring disk formats in the Image service (glance)

You can the configure the Image service (glance) to enable or reject disk formats by using the GlanceDiskFormats parameter.

Procedure

  1. Log in to the undercloud host as the stack user.
  2. Source the undercloud credentials file:

    $ source ~/stackrc
  3. Include the GlanceDiskFormats parameter in an environment file, for example, glance_disk_formats.yaml:

    parameter_defaults:
      GlanceDiskFormats:
        - <disk_format>
    • For example, use the following configuration to enable only RAW and ISO disk formats:

      parameter_defaults:
        GlanceDiskFormats:
        - raw
        - iso
    • Use the following example configuration to reject QCOW2 disk images:

      parameter_defaults:
        GlanceDiskFormats:
        - raw
        - iso
        - aki
        - ari
        - ami
  4. Include the environment file that contains your new configuration in the openstack overcloud deploy command with any other environment files that are relevant to your environment:

    $ openstack overcloud deploy --templates \
      -e <overcloud_environment_files> \
      -e <new_environment_file> \
      …
    • Replace <overcloud_environment_files> with the list of environment files that are part of your deployment.
    • Replace <new_environment_file> with the environment file that contains your new configuration.

For more information about the disk formats available in RHOSP, see Image configuration parameters.

2.7.2. Storing an image in RAW format

With the GlanceImageImportPlugins parameter enabled, run the following command to store a previously created image in RAW format:

$ glance image-create-via-import \
    --disk-format qcow2 \
    --container-format bare \
    --name NAME \
    --visibility public \
    --import-method web-download \
    --uri http://server/image.qcow2
  • For --name, replace NAME with the name of the image; this is the name that will appear in glance image-list.
  • For --uri, replace http://server/image.qcow2 with the location and file name of the QCOW2 image.
Note

This command example creates the image record and imports it by using the web-download method. The glance-api downloads the image from the --uri location during the import process. If web-download is not available, glanceclient cannot automatically download the image data. Run the glance import-info command to list the available image import methods.

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.