Chapter 3. Deploying a RHEL image as an EC2 instance on AWS
To use RHEL image on an Amazon Web Services (AWS), convert the RHEL image to the AWS-compatible format and deploy a VM from the RHEL image to run as an Elastic Cloud Compute (EC2) instance. To create, customize, and deploy a RHEL Amazon Machine Image (AMI), you can use one of the following methods:
- Use the Red Hat Image Builder. For instructions, see Preparing and uploading AMI images to AWS
- Manually create and configure an AMI. This is a more complicated process but offers more granular customization options. For instructions, see the following sections.
Prerequisites
- You have created a Red Hat account.
- You have signed up and set up an AWS account.
3.1. Available RHEL image types for public cloud
To deploy your RHEL virtual machine VM on a certified cloud service provider (CCSP), you can use a number of options. The following table lists the available image types, subscriptions, considerations, and sample scenarios for the image types.
To deploy customized ISO images, you can use Red Hat Image Builder. With Image Builder, you can create, upload, and deploy these custom images specific to your chosen CCSP.
Image types | Subscriptions | Considerations | Sample scenario |
---|---|---|---|
Deploy a Red Hat Golden Image | Use your existing Red Hat subscriptions | The subscriptions include the Red Hat product cost and support for Cloud Access images, while you pay the CCSP for all other instance costs | Select a Red Hat Golden Image on the CCSP. For details on Golden Images and how to access them on the CCSP, see the Red Hat Cloud Access Reference Guide |
Deploy a custom image that you move to the CCSP | Use your existing Red Hat subscriptions | The subscriptions includes the Red Hat product cost and support for custom RHEL image, while you pay the CCSP for all other instance costs | Upload your custom image and attach your subscriptions |
Deploy an existing RHEL based custom machine image | The custom machine images include a RHEL image | You pay the CCSP on an hourly basis based on a pay-as-you-go model. For this model, on-demand images are available on the CCSP marketplace. The CCSP provides support for these images, while Red Hat handles updates. The CCSP provides updates through the Red Hat Update Infrastructure (RHUI) | Select a RHEL image when you launch an instance on the CCSP cloud management console, or choose an image from the CCSP marketplace. |
You cannot convert an on-demand instance to a custom RHEL instance. For migrating from an on-demand image to a custom RHEL bring your own subscription (BYOS) image:
- Create a new custom RHEL instance, then migrate data from your on-demand instance.
- When your data migration is completed, terminate the on-demand instance to avoid additional billing.
3.2. Deploying a RHEL instance by using a custom base image
To manually configure a virtual machine (VM), first create a base (starter) image. Then, you can modify configuration settings and add the packages the VM requires to operate on the cloud. You can also make additional configuration changes for your specific application after you upload the image.
Creating a VM from a base image has the following advantages:
- Fully customizable
- High flexibility for any use case
- Lightweight - includes only the operating system and the required runtime libraries
To create a custom base image of RHEL from an ISO image, you can use the command line interface (CLI) or the web console for creating and configuring VM.
Vertify the following VM configurations.
- ssh - ssh must be enabled to provide remote access to your VMs
- dhcp - the primary virtual adapter should be configured for dhcp.
Prerequisites
- You have enabled virtualization on the host machine.
For web console, ensure the following options:
- You have not checked the Immediately Start VM option.
- You have already changed the Memory size to your preferred settings.
- You have changed the Model option under Virtual Network Interface Settings to virtio and vCPUs to the capacity settings for the VM.
Procedure
Configure the Red Hat Enterprise Linux VM:
- To install from the command line (CLI), ensure that you set the default memory, network interfaces, and CPUs as per your requirement for the VM. For details, see Creating virtual machines by using the command line
- To install from the web console, see Creating virtual machines by using the web console
When the installation starts:
-
Create a
root
password. - Create an administrative user account.
-
Create a
-
After the installation completes, reboot the VM and log in to the
root
account. -
After logging in as
root
, you can configure the image. Register the VM and enable the RHEL repository:
subscription-manager register --auto-attach
# subscription-manager register --auto-attach
Copy to Clipboard Copied! For AMD64 or Intel 64 (x86_64) VMs, install the
nvme
,xen-netfront
, andxen-blkfront
drivers:dracut -f --add-drivers "nvme xen-netfront xen-blkfront"
# dracut -f --add-drivers "nvme xen-netfront xen-blkfront"
Copy to Clipboard Copied! For ARM 64 (aarch64) VMs, install the
nvme
driver:dracut -f --add-drivers "nvme"
# dracut -f --add-drivers "nvme"
Copy to Clipboard Copied! Including these drivers prevents a
dracut
time-out.Alternatively, you can add the drivers to
/etc/dracut.conf.d/
and then enterdracut -f
to overwrite the existinginitramfs
file.
Verification
Verify that the
cloud-init
package is installed and enabled:dnf install cloud-init systemctl enable --now cloud-init.service
# dnf install cloud-init # systemctl enable --now cloud-init.service
Copy to Clipboard Copied! - Power down the VM.
3.3. Uploading a RHEL image to AWS by using the command line
To run a RHEL instance on Amazon Web Services (AWS), you must first upload a RHEL image to AWS. To configure and manage a RHEL EC2 instance on AWS, use the awscli2
utility.
3.3.1. Installing AWSCLI2
You can use the AWS command line interface awscli2
utility to configure and manage RHEL images and Red Hat high availability (HA) cluster on AWS.
Prerequisites
- You have access to an AWS Access Key ID and an AWS Secret Access Key. For details, see manage access keys.
Procedure
Install
awscli2
:dnf install awscli2
# dnf install awscli2
Copy to Clipboard Copied!
Verification
Verify the installation:
aws --version
$ aws --version aws-cli/1.19.77 Python/3.6.15 Linux/5.14.16-201.fc34.x86_64 botocore/1.20.77
Copy to Clipboard Copied! Configure
awscli2
for AWS credentials and settings:aws configure
$ aws configure AWS Access Key ID [None]: AWS Secret Access Key [None]: Default region name [None]: Default output format [None]:
Copy to Clipboard Copied!
3.3.2. Converting and pushing an image to Amazon S3
You can convert a RHEL image in the qcow2
image format to OVA
, VHD
, VHDX
, VMDK
, and raw
by using the qemu-img
utility, and then upload to the Amazon S3 storage. For details, see supported image formats by AWS.
Prerequisites
- You have created an Amazon S3 bucket by using awscli2 to upload the RHEL image.
Procedure
Run
qemu-img
to convert.qcow2
image to.raw
image format:qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.raw
# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.raw
Copy to Clipboard Copied! Upload the image to the Amazon S3 bucket:
aws s3 cp rhel-10.0-sample.raw s3://<example-s3-bucket-name>
$ aws s3 cp rhel-10.0-sample.raw s3://<example-s3-bucket-name>
Copy to Clipboard Copied!
Verification
- Monitor the AWS S3 Console to confirm successful upload.
3.3.3. Managing a RHEL VM on AWS by using the command line
By using the awscli2
utility, you can manage a RHEL EC2 VM on AWS through command line. In this case, you can use the vmimport
role for managing RHEL EC2 image snapshot. With awscli2
, you can also import a RHEL EC2 image snapshot, create an AMI, launch, and connect to a RHEL EC2 instance.
-
Use the
vmimport
role: An alternate to import the RHEL image to the Amazon S3 bucket is by using thevimport
role. See Required permissions for VM Import/Export. - Import RHEL image as a snapshot: You can import RHEL VM image from Amazon S3 as a snapshot to Amazon EC2. For details, see Start an import snapshot task and Monitor an import snapshot task.
- Create and launch a RHEL EC2 instance: You can create a RHEL Amazon Machine Image (AMI) from existing snapshot and launch a RHEL EC2 instance. For details, see create an AMI from snapshot by using awscli2 and launching, listing, and deleting RHEL instance by using awscli2.
-
Configure the private key and connect to the RHEL EC2 instance: You can configure your
<example-key>.pem
file and connect to an RHEL EC2 instance. For details, see Create a key pair using Amazon EC2 and Connect using the AWS CLI.
3.3.4. Attaching Red Hat subscriptions
Using the subscription-manager
command, you can register and attach your Red Hat subscription to a RHEL instance.
Prerequisites
- You have an active Red Hat account.
Procedure
Register your system:
subscription-manager register --auto-attach
# subscription-manager register --auto-attach
Copy to Clipboard Copied! Attach your subscriptions:
- You can use an activation key to attach subscriptions. See Creating Red Hat Customer Portal Activation Keys for more information.
- Alternatively, you can manually attach a subscription by using the ID of the subscription pool (Pool ID). See Attaching a host-based subscription to hypervisors.
Optional: To collect various system metrics about the instance in the Red Hat Hybrid Cloud Console, you can register the instance with Red Hat Insights.
insights-client register --display-name <display-name-value>
# insights-client register --display-name <display-name-value>
Copy to Clipboard Copied! For information on further configuration of Red Hat Insights, see Client Configuration Guide for Red Hat Insights.
3.4. Uploading a RHEL image to AWS by using the AWS console
To run a RHEL instance on Amazon Web Services (AWS), you must first upload the RHEL image to AWS. To configure and manage the RHEL EC2 instance on AWS, use the awscli2
utility.
3.4.1. Converting and pushing an image to S3 by using the AWS console
You can convert a RHEL image in the qcow2
image format to OVA
, VHD
, VHDX
, VMDK
, or raw
, and upload it to an Amazon Elastic Cloud Computing (EC2) by using the qemu-img
utility. For details, see supported image formats by AWS.
Prerequisites
- You have created an Amazon S3 bucket by using the Amazon S3 console to upload the RHEL image.
Procedure
Run
qemu-img
to convert.qcow2
image to.raw
image format:qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.raw
# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.raw
Copy to Clipboard Copied! - Upload the image to the S3 bucket by using Amazon S3 console
Verification
- Monitor the AWS S3 Console to confirm successful upload.
3.4.2. Managing a RHEL VM on AWS by using the AWS console
You can manage a RHEL EC2 VM on AWS by using the AWS console. You can create RHEL EC2 image snapshot, manage Amazon Machine Image (AMI), launch, and connect to a RHEL EC2 instance.
Procedure
-
Use the
vmimport
role: An alternate way to import the RHEL image to the Amazon S3 bucket is by using thevmimport
role. See Import your VM as an image. - Import a RHEL image as a snapshot: You can import a RHEL VM image from Amazon S3 as a snapshot to Amazon EC2. For details, see Importing a disk as a snapshot using VM Import/Export and Monitor an import snapshot task.
- Create and launch a RHEL EC2 instance: You can create a RHEL Amazon Machine Image (AMI) from an existing snapshot and launch a RHEL EC2 instance. For details, see Create an AMI from a snapshot and Launch an instance using defined parameters.
-
Configure the private key and connect to the RHEL EC2 instance: You can configure your
<example-key>.pem
file and connect to an RHEL EC2 instance. For details, see Create a key pair using Amazon EC2 and Connect using the Amazon EC2 console. - For Red Hat susbscriptions, see Attaching Red Hat subscriptions