Chapter 9. Creating and uploading a customized RHEL VMDK system image to VSphere
You can create customized RHEL system images by using Red Hat Image Builder and upload those images to the VMware vSphere client.
9.1. Creating a customized RHEL vmdk system image using Image Builder
You can create customized system images using Red Hat Image Builder and upload those images to VMware vSphere client.
Procedure
Access Red Hat Image Builder on the browser.
The Red Hat Image Builder dashboard appears.
Click Create image.
The Create image dialog wizard opens.
On the Image output page, complete the following steps:
- From the Release list, select the Release that you want to use: for example, choose Red Hat Enterprise Linux (RHEL).
From the Select target environments option, select
VMWare
.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 .vmdk in the Instance column.
The .vmdk image is saved to your system and is ready for deployment.
NoteThe
.vmdk
images are available for 6 hours and expire after that. Ensure to download the image to avoid losing it.
9.2. Uploading and deploying a VMDK image to VMware vSphere
Upload a .vmdk
image to VMware vSphere via HTTP.
Prerequisites
-
You created an
.vmdk
image by using Image Builder. - You have access to VMware vSphere.
Procedure
In the vCenter, click Upload Files .
After you upload the image to vCenter, you can deploy it into a virtual machine (VM).
- Use your preferred method for VM creation in VMWare to create a virtual machine.
In the New Virtual Machine wizard, complete the steps to create a new VM. The following is required for your
.vmdk
image to function correctly:For the Customize hardware step: When you create a VM, on the Device Configuration button on the upper right, delete the default New Hard Disk and use the drop-down to select an Existing Hard Disk disk image.
NoteYou must use an IDE device as the Virtual Device Node for the disk you create. The default SCSI value results in an unbootable virtual machine.
For the Ready to complete step: Review the details and click Finish to create the image.
The new VM is created and available in vSphere Client.
9.3. Creating a user for the VMDK image with cloud-init
To be able to login into your VM, you must create a user account. For that, follow the steps on the CLI.
The GUI wizard does not support cloud-init
.
Prerequisites
You configured the
govc
VMware CLI tool client.To use the
govc
VMware CLI tool client, you must set the following values in the environment:GOVC_URL GOVC_DATACENTER GOVC_FOLDER GOVC_DATASTORE GOVC_RESOURCE_POOL GOVC_NETWORK
Procedure
-
Access the directory where you downloaded your
.vmdk
image. Create a file named
metadata.yaml
. Add the following information to this file:instance-id: cloud-vm local-hostname: vmname
Create a file named
userdata.yaml
. Add the following information to the file:#cloud-config users - name: admin sudo: "ALL=(ALL) NOPASSWD:ALL" 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
.
-
Export the
metadata.yaml
anduserdata.yaml
files to the environment, compressed withgzip
, encoded inbase64
as follows. They will be used in further steps.export METADATA=$(gzip -c9 <metadata.yaml | { base64 -w0 2>/dev/null || base64; }) \ USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })
Launch the image on vSphere with the
metadata.yaml
anduserdata.yaml
files:Import the
.vmdk
image in to vSphere:$ govc import.vmdk ./composer-api.vmdk foldername
Create the VM in VSphere without powering it on:
govc vm.create \ -net.adapter=vmxnet3 \ -m=4096 -c=2 -g=rhel8_64Guest \ -firmware=bios -disk=”foldername/composer-api.vmdk” \ -disk.controller=ide -on=false \ vmname
Change the VM to add
ExtraConfig
variables, thecloud-init
config:govc vm.change -vm vmname \ -e guestinfo.metadata="${METADATA}" \ -e guestinfo.metadata.encoding="gzip+base64" \ -e guestinfo.userdata="${USERDATA}" \ -e guestinfo.userdata.encoding="gzip+base64"
Power-on the VM:
govc vm.power -on vmname
Retrieve the VM IP address:
HOST=$(govc vm.ip vmname)
Use SSH to log in to the VM, using the user-data specified in
cloud-init
file configuration:$ ssh admin@HOST
Additional resources
- The govc documentation
- The VMware - cloud init 22.2 documentation