Chapter 10. Creating a customized RHEL Guest image using Red Hat Image Builder
You can create customized RHEL guest system images using Red Hat Image Builder. You can then download these images to create virtual machines from these guest images as per your requirements.
10.1. Creating a customized RHEL Guest system image using Image Builder
Follow the steps to create customized RHEL guest .qcow2 images using Red Hat Image Builder.
Procedure
Access Red Hat Image Builder on the browser.
You are redirected to the Red Hat Image Builder dashboard.
Click Create image.
The Create image wizard opens.
On the Image output page, complete the following steps:
- From the Releases list, select the release of Red Hat Enterprise Linux (RHEL) that you want to use to create the image.
From the Select target environments options, select Virtualization - Guest image.
Click Next.
On the Registration page, select the type of registration that you want to use. You can select from these options:
- Register images with Red Hat - Register and connect image instances, subscriptions and insights with Red Hat. For details on how to embed an activation key and register systems on first boot, see Chapter 3, Creating a customized system image with an embed subscription using Red Hat Image Builder.
- Register image instances only - Register and connect only image instances and subscriptions with Red Hat.
Register later - Register the system after the image creation.
Click Next.
- Optional: On the Packages page, add packages to your image. See Chapter 4, Adding packages during image creation by Using Red Hat Image Builder.
- On the Name image page, enter a name for your image and click Next. If you do not enter a name, you can find the image you created by its UUID.
On the Review page, review the details about the image creation and click Create image.
After you complete the steps in the Create image wizard, the Image Builder dashboard is displayed.
When the new image displays a Ready status in the Status column, click Download .qcow2 image in the Instance column.
The .qcow2 image is saved to your system and is ready for deployment.
NoteThe
.qcow2
images are available for 6 hours and expire after that. Ensure to download the image to avoid losing it.
10.2. Creating a Virtual Machine from the customized RHEL Guest system image
You can create a Virtual Machine (VM) from the qcow2 image that you created using Red Hat Image Builder.
Prerequisites
- You created and downloaded a .qcow2 image using Image Builder.
Procedure
- Access the directory where you downloaded your .qcow2 image.
Create a file named
meta-data
. Add the following information to this file:instance-id: nocloud local-hostname: vmname
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
.
-
Use the
genisoimage
command to create an ISO image that includes theuser-data
andmeta-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)
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 composer-api.qcow2,device=disk,bus=virtio,format=qcow2 \ --disk cloud-init.iso,device=cdrom \ --os-variant rhel8.5 \ --virt-type kvm \ --graphics none \ --import
Where,
- --graphics none - indicates that it is a headless RHEL Virtual Machine.
- --vcpus 4 - indicates that it uses 4 virtual CPUs.
- --memory 4096 - indicates that it uses 4096 MB RAM.
The VM installation starts:
Starting install... Connected to domain myvm ... [ OK ] Started Execute cloud user/final scripts. [ OK ] Reached target Cloud-init target. Red Hat Enterprise Linux 8.5 (Ootpa) Kernel 4.18.0-221.el8.x86_64 on an x86_64
Additional resources