Chapter 3. Deploying a RHEL image as an EC2 instance on AWS
To use a Red Hat Enterprise Linux (RHEL) image on Amazon Web Services (AWS), convert the RHEL image to an AWS-compatible format, Amazon Machine Image (AMI). Use RHEL image builder or manual configuration for customization. From an AMI, you can launch an Elastic Cloud Compute (EC2) instance.
3.1. Available RHEL image types for public cloud Copy linkLink copied to clipboard!
To deploy your Red Hat Enterprise Linux (RHEL) virtual machine (VM) on a certified cloud service provider (CCSP), you can use several 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 RHEL image builder. With RHEL 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 gold 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 gold image on the CCSP according to requirement. |
| 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. |
To convert an on-demand, license-included EC2 instance to a bring-your-own-license (BYOL) EC2 instance of RHEL.
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, do the following:
- Create a new custom RHEL instance, then migrate data from your on-demand instance.
- When you complete data migration, terminate the on-demand instance to avoid additional billing.
3.2. Deploying a RHEL instance by using a custom base image Copy linkLink copied to clipboard!
To manually configure a virtual machine (VM) on cloud platforms, create a base (starter) image, modify configuration settings, and add the packages to the VM. This VM is customizable, flexible, and lightweight. After uploading the image, you can change settings for these specific applications.
Prerequisites
- You have access to the command line interface (CLI) or the web console for creating and configuring VM. If you do not have access to the CLI or the web console, you can use the Red Hat Cloud Access portal to create and configure VM.
- Secure Shell (SSH) - Enable SSH to give remote access to your VM.
- Dynamic Host Configuration Protocol (DHCP) - Configure the primary virtual adapter to use DHCP.
- 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 (RHEL) VM. See the Additional resources section for details:
- To install from CLI, ensure that you set the default memory, network interfaces, and CPUs according to your requirement for the VM.
- You can also install RHEL from the web console.
When the installation starts:
-
Create a
rootpassword. - Create an administrative user account.
-
Create a
-
After the installation completes, reboot the VM and log in to the
rootaccount. -
After logging in as
root, you can configure the image. Register the VM and enable the RHEL repository:
# subscription-manager registerFor AMD64 or Intel 64 (x86_64) VMs, install the
nvme,xen-netfront, andxen-blkfrontdrivers:# dracut -f --add-drivers "nvme xen-netfront xen-blkfront"For ARM 64 (aarch64) VMs, install the
nvmedriver:# dracut -f --add-drivers "nvme"Including these drivers prevents a
dracuttime-out.Alternatively, you can add the drivers to
/etc/dracut.conf.d/and then enterdracut -fto overwrite the existinginitramfsfile.Install the
cloud-initpackage:# dnf install cloud-initEnable and start the
cloud-initservice:# systemctl enable --now cloud-init.service- Reboot the VM to apply the changes.
Verification
Verify that the VM is running:
# systemctl status cloud-init
3.3. Uploading a RHEL image to AWS by using the command line Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
You can use the Amazon Web Services (AWS) command line interface awscli2 utility to configure and manage Red Hat Enterprise Linux (RHEL) images and Red Hat high availability (HA) cluster on AWS.
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
- 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
Verification
Verify the installation:
$ aws --versionaws-cli/1.19.77 Python/3.6.15 Linux/5.14.16-201.fc34.x86_64 botocore/1.20.77Configure
awscli2for AWS credentials and settings:$ aws configureAWS Access Key ID [None]: AWS Secret Access Key [None]: Default region name [None]: Default output format [None]:
3.3.2. Converting and pushing an image to Amazon S3 Copy linkLink copied to clipboard!
You can convert a Red Hat Enterprise Linux (RHEL) image in the qcow2 image format to OVA, VHD, VHDX, VMDK, or raw by using the qemu-img utility, and then upload it to Amazon S3 storage.
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
- You have created an Amazon S3 bucket by using awscli2 to upload the RHEL image.
Procedure
Run
qemu-imgto convert.qcow2image to.rawimage format:# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.rawUpload the image to the Amazon S3 bucket:
$ aws s3 cp rhel-10.0-sample.raw s3://<example-s3-bucket-name>
Verification
- Check the AWS S3 Console to confirm successful upload.
3.3.3. Managing a RHEL VM on AWS by using the command line Copy linkLink copied to clipboard!
You can use the Amazon Web Services (AWS) command line interface awscli2 utility to manage a Red Hat Enterprise Linux (RHEL) Elastic Cloud Compute (EC2) VM on AWS through the command line. You can import a RHEL EC2 image snapshot, create an Amazon Machine Image (AMI), launch, and connect to a RHEL EC2 instance.
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
-
You have installed the
awscli2package and configured AWS credentials for your account.
Procedure
Use the
vmimportrole:$ aws iam create-role --role-name vmimport \ --assume-role-policy-document file://<example_vmimport_trust_policy_file>Embed an inline policy document by using the
vmimportrole policy file:$ aws iam put-role-policy --role-name vmimport \ --policy-name vmimport-access \ --policy-document file://<example_vmimport_role_policy_file>Also, you can grant VM Import/Export permissions by creating an IAM role (often named
vmimport) with a trust policy forvmie.amazonaws.comand attaching the JSON policy from the AWS guide.Import RHEL image as a snapshot:
$ aws ec2 import-snapshot --disk-container file://<example_containers_json_file>Confirm that the snapshot import finished successfully with the
completedstatus:$ aws ec2 describe-import-snapshot-tasks --import-task-ids <example_import_task_id>You can import a RHEL VM image from Amazon S3 as a snapshot to Amazon EC2. Prepare a
<example_containers_json_file>file that points to your S3 bucket and object key, then start the import and monitor the task ID that the command returns.Register a RHEL AMI from the completed snapshot:
$ aws ec2 register-image \ --name <example_rhel_custom_ami_name> \ --architecture x86_64 \ --virtualization-type hvm \ --root-device-name /dev/sda1 \ --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\": {\"SnapshotId\": \"<example_snapshot_id>\"}}]" \ --ena-supportCreate a key pair for the RHEL EC2 instance:
$ aws ec2 create-key-pair --key-name <example_key_pair_name> \ --query 'KeyMaterial' --output text > <example_key_file>.pemThis key pair is per region and save a
.pemfile.Restrict permissions on the key file:
$ chmod 400 <example_key>.pemLaunch a RHEL EC2 instance from the registered AMI:
$ aws ec2 run-instances \ --image-id <example_registered_ami_id> \ --instance-type <example_instance_type> \ --key-name <example_key_pair_name>Connect to the RHEL EC2 instance where the default user is
ec2-user:$ ssh -i <example_key>.pem ec2-user@<instance_public_dns_or_ip>
Verification
Verify that the snapshot import finished successfully with the
completedstatus:$ aws ec2 describe-import-snapshot-tasks --import-task-ids <example_import_task_id>Verify that the AMI is available with the
availablestate:$ aws ec2 describe-images --image-ids <example_registered_ami_id>Verify that the instance is running with the
runningstate:$ aws ec2 describe-instances --instance-ids <example_instance_id>The
State.Namevalue isrunningwhen the instance has finished starting.Verify that the SSH connection works:
$ ssh -i <example_key>.pem ec2-user@<instance_public_dns_or_ip> 'echo connected'
3.3.4. Attaching Red Hat subscriptions Copy linkLink copied to clipboard!
To register and attach your Red Hat subscription to a RHEL instance, you can use the subscription-manager command.
Prerequisites
- You have an active Red Hat account.
Procedure
Register your system:
# subscription-manager registerAttach your subscriptions:
- You can use an activation key to attach subscriptions. For details, see creating Red Hat Customer Portal Activation Keys.
- Otherwise, you can manually attach a subscription by using the subscription Pool ID attaching a host-based subscription by using Pool ID 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 Lightspeed.
# insights-client register --display-name <display_name_value>
Verification
Verify that the system is registered and attached to the correct subscriptions:
# subscription-manager list --consumed
3.3.5. Configuring automatic registration on AWS gold images Copy linkLink copied to clipboard!
You can deploy Red Hat Enterprise Linux (RHEL) virtual machines (VMs) more efficiently on Amazon Web Services (AWS) by using gold images of RHEL. This ensures that the VMs are automatically registered to the Red Hat Subscription Manager (RHSM).
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
You have downloaded the latest RHEL gold image for AWS. For details, see Additional resources.
NoteYou can only attach an AWS account to a single Red Hat account at a time. Therefore, ensure no other users require access to the AWS account before attaching it to your Red Hat one.
Procedure
Upload the gold image to AWS. For details, see one of the following:
- Create VMs by using the uploaded image. If your RHSM settings are correct, they will be automatically subscribed to RHSM.
Verification
In a RHEL VM created using the earlier instructions, verify the system is registered to RHSM by running the
subscription-manager identitycommand. On a successfully registered system, this displays the UUID of the system. For example:# subscription-manager identitysystem identity: fdc46662-c536-43fb-a18a-bbcb283102b7 name: 192.168.122.222 org name: 6340056 org ID: 6340056
3.4. Uploading a RHEL image to AWS by using the AWS console Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
You can convert a RHEL image in the qcow2 image format to OVA, VHD, VHDX, VMDK, or raw by using the qemu-img utility, and then upload it to Amazon S3 storage by using the AWS console.
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
- You have created an Amazon S3 bucket by using the Amazon S3 console to upload the RHEL image.
Procedure
Run
qemu-imgto convert.qcow2image to.rawimage format:# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 rhel-10.0-sample.raw- Upload the image to the S3 bucket by using Amazon S3 console
Verification
- Check the AWS S3 Console to confirm successful upload.
3.4.2. Managing a RHEL VM on AWS by using the AWS console Copy linkLink copied to clipboard!
You can manage RHEL Elastic Cloud Compute (EC2) virtual machines (VMs) on Amazon Web Services (AWS) by using the AWS console. You can create RHEL EC2 image snapshots, manage Amazon Machine Image (AMI), launch, and connect to a RHEL EC2 instance.
Prerequisites
- You have created a Red Hat account.
- You have signed up and configured an AWS account.
- You have pushed your RHEL image to the Amazon S3 bucket by using the AWS console.
Procedure
-
Open the AWS Management Console. Search for
IAM, open IAM, choose Roles, then choose Create role forvmimport. In the Trusted entity type field, choose Custom trust policy. Paste the
vmie.amazonaws.comtrust policy from the VM Import/Export documentation, then choose Next.Add permissions: skip managed policies if you add an inline VM Import/Export policy next; otherwise attach required policies, then Next.
Role name
vmimport, Create role.In case of adding permissions, open the role. Choose the Permissions tab, choose Add permissions, choose Create inline policy, then choose the JSON tab. Paste the
vmimportaccess policy with your S3 bucket ARNs, then choose Create policy.Open CloudShell from the toolbar or global search.
In the CloudShell pane, set the Region selector to the same Region as your S3 object.
At the CloudShell (where the shell accepts
awscommands, not the console Search field), enteraws ec2 import-snapshotwith your disk container file, thenaws ec2 describe-import-snapshot-tasksuntil the import status iscompleted.In the Amazon EC2 console, open Elastic Block Store, choose Snapshots, and confirm the snapshot ID.
On Snapshots, select the snapshot, open Actions, choose Create image from snapshot, then finish the wizard.
- Open Images, choose AMIs, select the AMI, choose Launch instance from AMI, then finish the wizard.
If you need a key pair, choose Network & Security, Key pairs, then Create key pair, and choose
.pem.Save
<example_key>.pemwith restrictive file permissions.- Choose Instances, select the instance, choose Connect, then open EC2 Instance Connect or SSH client.
- On the instance, register Red Hat subscriptions.
Verification
Verify that the snapshot import finished successfully with the
completedstatus:$ aws ec2 describe-import-snapshot-tasks --import-task-ids <example_import_task_id>Verify that the AMI is available with the
availablestate:$ aws ec2 describe-images --image-ids <example_registered_ami_id>Verify that the instance is running with the
runningstate:$ aws ec2 describe-instances --instance-ids <example_instance_id>The
State.Namevalue isrunningwhen the instance has finished starting.Verify that the SSH connection works:
$ ssh -i <example_key>.pem ec2-user@<instance_public_dns_or_ip> 'echo connected'