Chapter 2. Managing images
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.
For KVM guest images:
-
The
root
account in the image is deactivated, butsudo
access is granted to a special user namedcloud-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).
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.
You must run all commands with the [root@host]#
on your host machine.
Procedure
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.
NoteIf the instance does not launch automatically, run the
virt-viewer
command to view the console:[root@host]# virt-viewer <rhel9>
Configure the instance:
- At the initial Installer boot menu, select Install Red Hat Enterprise Linux 9.
- Choose the appropriate Language and Keyboard options.
- When prompted about which type of devices your installation uses, select Auto-detected installation media.
- When prompted about which type of installation destination, select Local Standard Disks. For other storage options, select Automatically configure partitioning.
- Choose the Basic Server install, which installs an SSH server.
- For network and host name, select eth0 for network and choose a host name for your device. The default host name is localhost.localdomain.
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.
- After the installation is complete, reboot the instance and log in as the root user.
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
- Reboot the machine.
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
Update the system:
# dnf -y update
Install the
cloud-init
packages:# dnf install -y cloud-utils-growpart cloud-init
Edit the
/etc/cloud/cloud.cfg
configuration file and add the following content undercloud_init_modules
:- resolv-conf
The
resolv-conf
option automatically configures theresolv.conf
file when an instance boots for the first time. This file contains information related to the instance such asnameservers
,domain
, and other options.Add the following line to
/etc/sysconfig/network
to avoid issues when accessing the EC2 metadata service:NOZEROCONF=yes
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"
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
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
Power off the instance:
# poweroff
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>
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.NoteYou 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.
You must run all commands with the [root@host]#
on your host machine.
Procedure
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.
NoteIf the instance does not launch automatically, run the
virt-viewer
command to view the console:[root@host]# virt-viewer <rhel86-cloud-image>
Configure the instances:
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.
- Choose the appropriate Language and Keyboard options.
- When prompted about which type of devices your installation uses, select Basic Storage Devices.
-
Choose a host name for your device. The default host name is
localhost.localdomain
. -
Set the timezone and
root
password. - 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.
- Choose the Basic Server install, which installs an SSH server.
- The installation process completes and the Congratulations, your Red Hat Enterprise Linux installation is complete screen is displayed.
-
Reboot the instance and log in as the
root
user. 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
- Reboot the machine.
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
Update the system:
# dnf -y update
Install the
cloud-init
packages:# dnf install -y cloud-utils-growpart cloud-init
Edit the
/etc/cloud/cloud.cfg
configuration file and add the following content undercloud_init_modules
.- resolv-conf
The
resolv-conf
option automatically configures theresolv.conf
file when an instance boots for the first time. This file contains information related to the instance such asnameservers
,domain
, and other options.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 aseth1
instead ofeth0
and the IP address is not assigned.Add the following line to
/etc/sysconfig/network
to avoid issues when accessing the EC2 metadata service:NOZEROCONF=yes
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
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
Power off the instance:
# poweroff
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>
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.NoteYou 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.
You must run all commands with the [root@host]#
on your host machine.
Procedure
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.NoteThe
--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 setos_type=windows
in the image metadata before uploading the image to the Image service (glance).
-
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 namedwin8.qcow2
in the current working directory.TipIf 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.
-
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. 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.ImportantRed 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
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.
-
Replace
If the default machine type is not
q35
, then set the machine type toq35
:$ openstack image set --property hw_machine_type=q35 uefi_secure_boot_image
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 theproperty
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>
-
For a list of
glance image-create
command options, see Image service (glance) command options. - For a list of property keys, see Image configuration parameters.
-
For a list of
2.3. Updating an image
Update an image.
Procedure
Use the
glance image-update
command with theproperty
option to update an image.For example:
$ glance image-update IMG-UUID \ --property architecture=x86_64
-
For a list of
glance image-update
command options, see Image service (glance) command options. - For a list of property keys, see Image configuration parameters.
-
For a list of
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.
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.
-
Replace
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.
-
Replace
The Image service web download
method uses a two-stage process to perform the import:
-
The
web download
method creates an image record. -
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.
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.
NoteThe
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.
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
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
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
-
Log in to the undercloud host as the
stack
user. Source the undercloud credentials file:
$ source ~/stackrc
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
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.
-
Replace
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
, replaceNAME
with the name of the image; this is the name that will appear inglance image-list
. -
For
--uri
, replacehttp://server/image.qcow2
with the location and file name of the QCOW2 image.
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.