Chapter 3. Deploying a RHEL image as a compute instance on Azure
You can deploy a Red Hat Enterprise Linux (RHEL) image as an Azure Compute virtual machine (VM) by converting the image to an Azure-compatible format and then deploying it. Use the RHEL image builder or manually create a virtual hard drive (VHD) to customize and deploy your RHEL image to Azure.
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. |
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. Required system packages Copy linkLink copied to clipboard!
To create and configure a base image of RHEL, your host system must have the following packages installed.
| Package | Repository | Description |
|---|---|---|
| libvirt |
| Open source API, daemon, and management tool for managing platform virtualization |
| virt-install |
| A command-line utility for building VMs |
| libguestfs |
| A library for accessing and modifying VM file systems |
| guestfs-tools |
|
System administration tools for VMs; includes the |
After confirming installation of the mentioned system packages, follow the deployment steps in deploying a RHEL instance by using a custom base image
3.3. 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.
- You have prepared a Hyper-V cloud image of RHEL.
- You have enabled the required settings either during the initial VM creation or provisioning a VM image to the Azure cloud.
- You have checked the required list of system packages.
- 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.
-
Swap space - Do not create a dedicated
swapfile or partition during installation. Avoid creating theswappartition on the operating system disk or storage disk. Configure thecloud-initutility to automatically create aswappartition on an ephemeral disk of the VM. Ephemeral disks provide local VM storage. Resource disks provide mounted storage. Both storage types store data temporarily. - Network Interface Card (NIC) - Choose virtio for the primary virtual network adapter.
- Encryption - For custom images, use Network Bound Disk Encryption (NBDE) for full disk encryption on Azure.
- 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 registerInstall 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.
Next steps
- Install the Azure CLI to access Azure resources and services.
Verification
Verify that the VM is running:
# systemctl status cloud-init
3.4. Installing the Azure CLI Copy linkLink copied to clipboard!
To connect to Azure Cloud and manage Azure resources directly from terminal of your host system, you can use the Azure command-line interface (CLI).
Prerequisites
- You have created a Red Hat account.
- You have completed the deployment of a RHEL image on Azure.
- You have an account with Microsoft Azure.
- You have installed Python 3.x.
Procedure
Import the Microsoft repository key:
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.ascCreate a local Azure CLI repository entry:
$ sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'Update the
dnfpackage index:$ sudo dnf updateInstall the Azure CLI:
$ sudo dnf install -y azure-cliRun the Azure CLI:
$ az login
Verification
Verify that the Azure CLI is installed and running:
$ az --version
Next steps
- Install the Hyper-V device drivers to efficiently run VM on Azure.
3.5. Installing Hyper-V device drivers Copy linkLink copied to clipboard!
Before provisioning a virtual machine (VM) image as an Azure VM, you must install Hyper-V device drivers. Microsoft provides these network and storage device drivers in their Linux Integration Services (LIS) for Hyper-V package.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
- You have installed the Azure CLI.
Procedure
Verify if the system has Hyper-V device drivers:
# lsinitrd | grep hv drwxr-xr-x 2 root root 0 Aug 12 14:21 usr/lib/modules/3.10.0-932.el10.x86_64/kernel/drivers/hv -rw-r--r-- 1 root root 31272 Aug 11 08:45 usr/lib/modules/3.10.0-932.el10.x86_64/kernel/drivers/hv/hv_vmbus.ko.xz -rw-r--r-- 1 root root 25132 Aug 11 08:46 usr/lib/modules/3.10.0-932.el10.x86_64/kernel/drivers/net/hyperv/hv_netvsc.ko.xz -rw-r--r-- 1 root root 9796 Aug 11 08:45 usr/lib/modules/3.10.0-932.el10.x86_64/kernel/drivers/scsi/hv_storvsc.ko.xzIn case, all the drivers are not installed or even the
hv_vmbusdriver is listed, complete the remaining steps.Create the
hv.conffile in the/etc/dracut.conf.ddirectory and add the following driver parameters:# vi hv.conf add_drivers+=" hv_vmbus " add_drivers+=" hv_netvsc " add_drivers+=" hv_storvsc " add_drivers+=" nvme "Ensure that you have added spaces after and before the double quotes
add_drivers+=" hv_vmbus "to load unique drivers, in case other Hyper-V drivers already exist in the environment.Regenerate the
initramfsimage:# dracut -f -v --regenerate-all
Verification
- Reboot the machine.
Verify installation of drivers:
# lsinitrd | grep hv
Next steps
- Prepare your VM for deployment on Azure cloud.
3.6. Configuring swap space with cloud-init on Azure Copy linkLink copied to clipboard!
To use swap space for a Red Hat Enterprise Linux (RHEL) virtual machine (VM) on Microsoft Azure, create a swap partition on an ephemeral disk. Only use the ephemeral disk for creating the swap partition, not the operating system disk or data disk.
Prerequisites
- Both the ephemeral and resource disks offer only temporary data storage: deleting, moving, stopping, or experiencing a VM failure will result in the loss of data stored on these disks.
- You have understood that you should not use the ephemeral disk for persistent data. All contents, including the swap partition, are deleted when the VM is stopped or moved.
You have understood the difference between ephemeral and resource disks:
- The ephemeral disk is local storage attached directly to the VM.
- The resource disk is mounted storage on the VM itself.
- You have created a Red Hat account.
- You have a Microsoft Azure account.
-
You have installed the
cloud-initutility on the VM. You have disabled the swap configuration in the Windows Azure Linux Agent (WALA) by setting the parameters in the
/etc/waagent.conffile:ResourceDisk.Format=n ResourceDisk.EnableSwap=n ResourceDisk.SwapSizeMB=0- You have an ephemeral disk available on the VM.
Procedure
- Log in to the VM.
Create and edit the
/etc/cloud/cloud.cfg.d/00-azure-swap.cfgconfiguration file and add the followingcloud-initconfiguration to the file:# vi /etc/cloud/cloud.cfg.d/00-azure-swap.cfg#cloud-config disk_setup: ephemeral0: table_type: gpt layout: [66, [33,82]] overwrite: true fs_setup: - device: ephemeral0.1 filesystem: ext4 - device: ephemeral0.2 filesystem: swap mounts: - ["ephemeral0.1", "/mnt"] - ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service", "0", "0"]This configuration:
-
Partitions the ephemeral disk (
ephemeral0) with a GPT partition table. -
Creates two partitions: 66% for a file system (mounted at
/mnt) and 33% forswapspace. -
Formats the first partition as
ext4and the second partition asswap. Configures automatic mounting of both partitions at boot time.
NoteThe partition layout
[66, [33,82]]allocates 66% of the disk to the first partition and 33% to the second partition. The82in the second partition specification indicates a Linux swap partition type. You can adjust these percentages based on your requirements.
-
Partitions the ephemeral disk (
Verify the configuration file for any errors:
# cloud-init devel schema --config-file /etc/cloud/cloud.cfg.d/00-azure-swap.cfgIf the configuration is valid, the command returns no errors.
Verification
After rebooting the VM, check that the swap partition is configured and active by verifying the active swap space, swap usage, and the swap partition entry in the
/etc/fstabfile.Check active swap space:
$ swapon -sThe output should show the swap partition from
ephemeral0.2:Filename Type Size Used Priority /dev/ephemeral0.2 partition 8388604 0 2Check swap usage:
$ free -hThe output should show swap space in the
Swaprow:total used free shared buffered/cache available Mem: 7.8Gi 1.2Gi 5.8Gi 16MiB 800MiB 6.3Gi Swap: 8.0Gi 0B 8.0GiVerify the swap partition is present in the
/etc/fstabfile:$ grep swap /etc/fstabThe output should include an entry for the swap partition, for example:
/dev/ephemeral0.2 none swap sw,nofail,x-systemd.requires=cloud-init.service 0 0
3.7. Preparing a virtual machine for Azure deployment Copy linkLink copied to clipboard!
To ensure a virtual machine (VM) has compatibility and can operate in the Azure environment, perform configuration changes before deploying a custom base image in Azure.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
- You have installed the Hyper-V device drivers.
Procedure
Log in and register the VM to enable the Red Hat Enterprise Linux (RHEL) repository:
# subscription-manager registerInstall the
cloud-initandhyperv-daemonspackages:# dnf install cloud-init hyperv-daemons -yCreate the
cloud-initconfiguration files and edit them to offer integration with Azure services:To enable logging to the Hyper-V Data Exchange Service, also known as Key Value Pair (KVP), edit the
/etc/cloud/cloud.cfg.d/10-azure-kvp.cfgfile and append the following lines:reporting: logging: type: log telemetry: type: hypervTo add the Azure datasource, edit the
/etc/cloud/cloud.cfg.d/91-azure_datasource.cfgfile and append the following lines:datasource_list: [ Azure ] datasource: Azure: apply_network_config: FalseTo configure swap space on the ephemeral disk, create the
/etc/cloud/cloud.cfg.d/00-azure-swap.cfgconfiguration file and add the following lines to that file.ImportantThe ephemeral disk is temporary storage. Therefore, data stored on it, including swap space, is lost when the VM is deallocated or moved. Use the ephemeral disk only for temporary data such as swap space.
#cloud-config disk_setup: ephemeral0: table_type: gpt layout: [66, [33,82]] overwrite: true fs_setup: - device: ephemeral0.1 filesystem: ext4 - device: ephemeral0.2 filesystem: swap mounts: - ["ephemeral0.1", "/mnt"] - ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service", "0", "0"]
To block automatic loading of specific kernel modules, edit the
/etc/modprobe.d/blocklist.conffile and append the following lines:blacklist nouveau blacklist lbm-nouveau blacklist floppy blacklist amdgpu blacklist skx_edac blacklist intel_cstateModify
udevnetwork device rules:If present, remove the following persistent network device rules:
# rm -f /etc/udev/rules.d/70-persistent-net.rules# rm -f /etc/udev/rules.d/75-persistent-net-generator.rules# rm -f /etc/udev/rules.d/80-net-name-slot-rulesTo ensure working of accelerated networking on Azure, edit the
/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rulesnew network device rule and append:SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1"
Set the
sshdservice to start automatically:# systemctl enable --now sshdModify kernel boot parameters:
Update the
GRUB_TIMEOUTparameter value in the/etc/default/grubfile:GRUB_TIMEOUT=10Remove the following option from the end of the
GRUB_CMDLINE_LINUXline, if present:rhgb quietUpdate the
/etc/default/grubfile with the following configuration details:GRUB_CMDLINE_LINUX="loglevel=3 crashkernel=auto console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300" GRUB_TIMEOUT_STYLE=countdown GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"NoteBy adding the
elevator=noneoption to the end of theGRUB_CMDLINE_LINUXline. This instructs the I/O scheduler to process I/O requests in the order of execution, without optimizing disk performance.With
elevator=noneon:- Hard disk drive (HDD): Performance and throughput decreases, therefore not suitable for running workloads.
- Solid state drive (SSD): High performance and low latency, therefore suitable for running workloads.
Regenerate the
grub.cfgfile:On a BIOS-based machine:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdlineOn a UEFI-based machine:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdlineNoteThe path to rebuild
grub.cfgis same for both BIOS and UEFI based machines. Originalgrub.cfgis present at BIOS path only. The UEFI path has a stub file that must not be modified or recreated usinggrub2-mkconfigcommand.If your system uses a non-default location for
grub.cfg, change the command.
Configure the Windows Azure Linux Agent (
WALinuxAgent):Install and enable the
WALinuxAgentpackage:# dnf install WALinuxAgent -y# systemctl enable waagentTo disable swap configuration in
WALinuxAgent(required when using cloud-init to manage swap), edit the following lines in the/etc/waagent.conffile:Provisioning.DeleteRootPassword=y ResourceDisk.Format=n ResourceDisk.EnableSwap=n ResourceDisk.SwapSizeMB=0NoteBy disabling swap in
WALinuxAgent, you enablecloud-initto manage the swap configuration on the ephemeral disk.
Verification
Verify that the VM is registered to Red Hat Subscription Manager and can access RHEL repositories:
# subscription-manager statusThe output shows
Overall Status: Current.Verify that the required packages are installed:
# rpm -q cloud-init hyperv-daemons WALinuxAgentThe command lists a version for each package and does not report that a package is not installed.
Verify the
cloud-initconfiguration files:Validate
/etc/cloud/cloud.cfg.d/10-azure-kvp.cfg:# cloud-init devel schema --config-file /etc/cloud/cloud.cfg.d/10-azure-kvp.cfgValidate
/etc/cloud/cloud.cfg.d/91-azure-datasource.cfg:# cloud-init devel schema --config-file /etc/cloud/cloud.cfg.d/91-azure_datasource.cfgValidate
/etc/cloud/cloud.cfg.d/00-azure-swap.cfg:# cloud-init devel schema --config-file /etc/cloud/cloud.cfg.d/00-azure-swap.cfgIf a configuration file is valid, the command returns no errors.
Verify that persistent
udevnetwork rules are removed and the SR-IOV rule is present:# test ! -f /etc/udev/rules.d/70-persistent-net.rules && test ! -f /etc/udev/rules.d/75-persistent-net-generator.rules && test ! -f /etc/udev/rules.d/80-net-name-slot.rules && grep -q 'hv_pci' /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rulesThe command returns no output when the checks succeed.
Verify that the
sshdandwaagentservices are enabled to start at boot:# systemctl is-enabled sshd waagentThe command returns
enabledfor each service.Verify the kernel boot parameters in
/etc/default/grub:# grep '^GRUB_CMDLINE_LINUX=' /etc/default/grubThe output includes
console=ttyS0and does not includerhgborquiet.Verify that swap configuration is disabled in
/etc/waagent.conf:# grep -E '^ResourceDisk\.(Format|EnableSwap)=n$' /etc/waagent.confThe command returns:
ResourceDisk.Format=n ResourceDisk.EnableSwap=n
Next steps
Unregister the VM from Red Hat Subscription Manager:
# subscription-manager unregisterClean up the existing provisioning details:
# waagent -force -deprovisionNoteThis command generates warnings as Azure automatically handles the VM provisioning.
Clear the shell history and shut down the VM:
# export HISTSIZE=0 # poweroff- To upload the RHEL image to Azure cloud, convert it to Azure disk image format.
3.8. Converting a RHEL image to Azure disk image Copy linkLink copied to clipboard!
You can convert a Red Hat Enterprise Linux (RHEL) image from qcow2 to a fixed Azure disk image virtual hard drive (.vhd) format. Ensure the image file starts at a position that is a multiple of 1 MB before conversion.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
- You have completed the steps of preparing VM for Azure deployment.
-
You are using
qemu-imgversion 2.12.0.
Procedure
Convert the image from
qcow2torawformat.$ qemu-img convert -f qcow2 -O raw <example_image_name>.qcow2 <output_image_name>.rawEdit the
align.shshell script:$ vi align.sh#!/bin/bash MB=$((1024 * 1024)) size=$(qemu-img info -f raw --output json "$1" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}') rounded_size=$((($size/$MB + 1) * $MB)) if [ $(($size % $MB)) -eq 0 ] then echo "Your image is already aligned. You do not need to resize." exit 1 fi echo "rounded size = $rounded_size" export rounded_sizeRun the script:
$ sh align.sh <example_image_name>.rawIf the message displays as Your image is already aligned. You do not need to resize.:
Convert the file to a fixed
VHDformat:$ qemu-img convert -f raw -o subformat=fixed,force_size -O vpc <example_image_name>.raw <output_image_name>.vhdOnce converted, the
VHDfile is ready to upload to Azure.
If a value displays mean the
rawimage is not aligned:Resize the
rawfile by using the rounded value as displayed above:$ qemu-img resize -f raw <example_image_name>.raw +1GConvert the
rawimage file to aVHDformat.$ qemu-img convert -f raw -o subformat=fixed,force_size -O vpc <example_image_name>.raw <output_image_name>.vhdOnce converted, the
VHDfile is ready to upload to Azure.
Verification
Verify that the
VHDfile is ready to upload to Azure:$ qemu-img info <example_image_name>.vhdThe output shows the
VHDfile is ready to upload to Azure.
Next steps
- You can now configure Azure resources for your RHEL image.
3.9. Configuring the Azure resources for a RHEL image Copy linkLink copied to clipboard!
Before uploading the virtual hard drive (VHD) image file and creating the Azure image, configure Azure resources such as compute, network, and storage.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
- You have installed the Azure CLI. For details, see Installing the Azure CLI.
- You have completed the process of conversion of a RHEL image to Azure disk image.
Procedure
Authenticate your host with Azure credentials and log in:
$ az loginTo login from a browser, open the Azure sign-in page from the Azure CLI. For details, see sign in with a browser.
Create a resource group in an Azure region:
$ az group create --name <example_resource_group> \ --location <example_azure_region>Example:
[clouduser@localhost]$ az group create --name azrhelclirsgrp \ --location southcentralus{ "id": "/subscriptions//resourceGroups/azrhelclirsgrp", "location": "southcentralus", "managedBy": null, "name": "azrhelclirsgrp", "properties": { "provisioningState": "Succeeded" }, "tags": null }Create a storage account with a valid stock keeping units (SKU) types:
$ az storage account create -l <example_azure_region> \ --name <example_storage_account_name> \ --resource-group <example_resource_group> \ --sku <example_sku_type>Example:
$ az storage account create -l southcentralus \ --name azrhelclistact \ --resource-group azrhelclirsgrp \ --sku Standard_LRS{ "accessTier": null, "creationTime": "2017-04-05T19:10:29.855470+00:00", "customDomain": null, "encryption": null, "id": "/subscriptions//resourceGroups/azrhelclirsgrp/providers/Microsoft.Storage/storageAccounts/azrhelclistact", "kind": "StorageV2", "lastGeoFailoverTime": null, "location": "southcentralus", "name": "azrhelclistact", "primaryEndpoints": { "blob": "https://azrhelclistact.blob.core.windows.net/", "file": "https://azrhelclistact.file.core.windows.net/", "queue": "https://azrhelclistact.queue.core.windows.net/", "table": "https://azrhelclistact.table.core.windows.net/" }, "primaryLocation": "southcentralus", "provisioningState": "Succeeded", "resourceGroup": "azrhelclirsgrp", "secondaryEndpoints": null, "secondaryLocation": null, "sku": { "name": "Standard_LRS", "tier": "Standard" }, "statusOfPrimary": "available", "statusOfSecondary": null, "tags": {}, "type": "Microsoft.Storage/storageAccounts" }Display the storage account details:
$ az storage account show-connection-string \ -n <example_storage_account_name> \ --resource-group <example_resource_group>Example:
$ az storage account show-connection-string \ -n azrhelclistact \ --resource-group azrhelclirsgrp{ "connectionString": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=azrhelclistact;AccountKey=NreGk...==" }Set the environment variable by exporting the existing connection string to connect system to the storage account:
$ export AZURE_STORAGE_CONNECTION_STRING="<storage_connection_string>"Example:
$ export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=azrhelclistact;AccountKey=NreGk...=="Create a storage container:
$ az storage container create -n <example_container_name>Example:
$ az storage container create -n azrhelclistcont{ "created": true }Create a virtual network:
$ az network vnet create -g <example_resource_group> \ --name <example_vnet_name> \ --subnet-name <example_subnet_name>Example:
$ az network vnet create --resource-group azrhelclirsgrp \ --name azrhelclivnet1 \ --subnet-name azrhelclisubnet1{ "newVNet": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "dhcpOptions": { "dnsServers": [] }, "etag": "W/\"\"", "id": "/subscriptions//resourceGroups/azrhelclirsgrp/providers/Microsoft.Network/virtualNetworks/azrhelclivnet1", "location": "southcentralus", "name": "azrhelclivnet1", "provisioningState": "Succeeded", "resourceGroup": "azrhelclirsgrp", "resourceGuid": "0f25efee-e2a6-4abe-a4e9-817061ee1e79", "subnets": [ { "addressPrefix": "10.0.0.0/24", "etag": "W/\"\"", "id": "/subscriptions//resourceGroups/azrhelclirsgrp/providers/Microsoft.Network/virtualNetworks/azrhelclivnet1/subnets/azrhelclisubnet1", "ipConfigurations": null, "name": "azrhelclisubnet1", "networkSecurityGroup": null, "provisioningState": "Succeeded", "resourceGroup": "azrhelclirsgrp", "resourceNavigationLinks": null, "routeTable": null } ], "tags": {}, "type": "Microsoft.Network/virtualNetworks", "virtualNetworkPeerings": null } }
Verification
Verify that the virtual network is created:
$ az network vnet list --output tableName ResourceGroup Location AddressPrefix ---------------- --------------- ---------- ------------- azrhelclivnet1 azrhelclirsgrp southcentralus 10.0.0.0/16
Next steps
3.10. Uploading a VHD image to Azure Blob storage Copy linkLink copied to clipboard!
To create a custom Azure VM image, use Microsoft Azure Blob storage to upload and store your converted Red Hat Enterprise Linux (RHEL) virtual hard drive (VHD) image file.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
You have already configured Azure resources.
WarningThe exported storage connection string is active only for your current session. After reboot, re-export the connection string before running storage commands to obtain and export a connection string. See configuring the Azure resources for a RHEL image.
Procedure
Upload the VHD file to the storage container:
$ az storage blob upload \ --account-name <storage_account_name> \ --container-name <container_name> \ --type page \ --file <path_to_vhd> \ --name <image_name>.vhdExample:
$ az storage blob upload \ --account-name azrhelclistact \ --container-name azrhelclistcont \ --type page \ --file ~/Downloads/rhel-image-10.vhd \ --name rhel-10-image.vhdPercent complete: 100.0%List the storage containers:
To display in the tabular format, enter:
$ az storage container list --output tableTo display in the YAML format, enter:
$ az storage container list --output yaml
Use the URL for the uploaded VHD file from the 1st step:
$ az storage blob url \ -c <container_name> \ -n <image_name>.vhd \ <url_of_vhd_file>Example:
$ az storage blob url \ -c azrhelclistcont \ -n rhel-image-10.vhd 'https://azrhelclistact.blob.core.windows.net/azrhelclistcont/rhel-image-10.vhd'Create the Azure custom image:
$ az image create -n <image_name> \ -g <resource_group> \ -l <azure_region> \ --source <URL> \ --os-type linuxNoteBy default, Azure creates the VM with a Generation 1 hypervisor. If you want to use a Generation 2 VM, which provides UEFI-based boot architecture, add the
--hyper-v-generation V2option to the command.Example:
$ az image create -n rhel10 \ -g azrhelclirsgrp2 \ -l southcentralus \ --source https://azrhelclistact.blob.core.windows.net/azrhelclistcont/rhel-image-10.vhd \ --os-type linux
Verification
Verify that the Azure custom image is created:
$ az image list --output tableName ResourceGroup Location StorageProfile ---------------- --------------- ---------- ------------------ rhel10 azrhelclirsgrp2 southcentralus
Next steps
- You can launch and connect to an Azure VM.
Troubleshooting
-
If you see the error message
Only blobs formatted as VHDs can be imported, the image is not aligned to the nearest 1 MB boundary before being converted to VHD format. For details, see Converting a RHEL image to Azure disk image.
3.11. Launching and connecting to a RHEL VM in Azure Copy linkLink copied to clipboard!
You can create a managed disk Azure virtual machine (VM) from your uploaded RHEL image and connect to it by using SSH. A managed disk VM uses Azure-managed storage, which simplifies disk management and provides better reliability.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
- You have completed the uploading of Azure VHD image to Azure Blob storage.
Procedure
Create the VM:
$ az vm create \ --resource-group <resource_group> \ --location <azure_region> \ --name <vm_name> \ --vnet-name <vnet_name> \ --subnet <subnet_name> \ --size Standard_A2 \ --os-disk-name <simple_name> \ --admin-username <administrator_name> \ --generate-ssh-keys \ --image <path_to_image>Example:
$ az vm create \ --resource-group azrhelclirsgrp2 \ --location southcentralus \ --name rhel-azure-vm-1 \ --vnet-name azrhelclivnet1 \ --subnet azrhelclisubnet1 \ --size Standard_A2 \ --os-disk-name vm-1-osdisk \ --admin-username clouduser \ --generate-ssh-keys \ --image rhel10{ "fqdns": "", "id": "/subscriptions//resourceGroups/azrhelclirsgrp/providers/Microsoft.Compute/virtualMachines/rhel-azure-vm-1", "location": "southcentralus", "macAddress": "", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "__<public_ip_address>__", "resourceGroup": "azrhelclirsgrp2" }-
--generate-ssh-keysoption creates a private and public key pair files in the~/.sshdirectory. The public key is added to the
authorized_keysfile on the VM for the user specified by the--admin-usernameoption.For details, see Types of SSH authentication methods. Note the
publicIpAddress, which is required for logging in to the VM in the following step.
-
Start an SSH session and log in to the Azure VM:
[clouduser@localhost]$ ssh -i /home/clouduser/.ssh/id_rsa clouduser@<public_ip_address>The authenticity of host '__<public_ip_address>__' can't be established. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '__<public_ip_address>__' (ECDSA) to the list of known hosts.
Verification
- If you successfully connected to the VM, you see a user prompt.
- Use the Microsoft Azure portal to check the audit logs, assigned resources properties, and manage virtual machines. For details, see Tutorial: Create and manage Linux VMs with the Azure portal.
-
You can also use the Azure CLI if you are managing many VMs. For details, enter
az --helpin the CLI or see Azure CLI command reference.
3.12. Types of SSH authentication methods Copy linkLink copied to clipboard!
You can connect to an Azure virtual machine (VM) by using various SSH authentication methods, including password authentication or an existing public key file.
- Example 1
- Provision a new Azure VM with a password without generating a public key file.
$ az vm create \
-g <resource_group> -l <azure_region> -n <vm_name> \
-vnet-name <vnet_name> -subnet <subnet_name> -size Standard_A2 \
-os-disk-name <simple_name> -authentication-type password \
-admin-username <administrator_name> -admin-password <ssh_password> -image <path_to_image>
$ ssh <admin_username>@<public_ip_address>
- Example 2
- Provision a new Azure VM with an existing public key file.
$ az vm create \
-g <resource_group> -l <azure_region> -n <vm_name> \
-vnet-name <vnet_name> -subnet <subnet_name> -size Standard_A2 \
-os-disk-name <simple_name> -admin-username <administrator_name> \
-ssh-key-value <path_to_existing_ssh_key> -image <path_to_image>
$ ssh -i <path_to_existing_ssh_key> <admin_username>@<public_ip_address>
3.13. 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.14. Setting up automatic registration on Azure gold images Copy linkLink copied to clipboard!
You can deploy Red Hat Enterprise Linux (RHEL) virtual machines (VMs) more efficiently on Microsoft Azure 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 a Microsoft Azure account.
You have downloaded the latest RHEL gold image for Azure. For details, see Using gold images on Azure.
NoteAt a time, you can only attach an Azure account to a single Red Hat account. Therefore, ensure no other users require access to the Azure account before attaching it to your Red Hat account.
Procedure
Upload the gold image to Azure. For details, see Launching and connecting to a RHEL VM in Azure.
If your RHSM settings are correct, the VM will be automatically subscribed to RHSM.
Verification
In a RHEL VM created by using the above instructions, verify that RHSM connects to the system. On a successfully registered system, the
subscription-manager identitycommand displays the UUID of the system. For example:# subscription-manager identity system identity: fdc46662-c536-43fb-a18a-bbcb283102b7 name: 192.168.122.222 org name: 6340056 org ID: 6340056
3.15. Configuring kdump for Microsoft Azure virtual machines Copy linkLink copied to clipboard!
To generate crash dump (vmcore) files when a kernel crash occurs, configure the kdump service on Azure virtual machine (VM). Adjust the kdump reserved memory and the vmcore target as needed for your VM size and Red Hat Enterprise Linux (RHEL) version to ensure reliable crash diagnostics.
Prerequisites
- You have created a Red Hat account.
- You have a Microsoft Azure account.
You are using a VM from Microsoft Azure environment that supports
kdump:- Standard_DS2_v2
- Standard NV16as v4
- Standard M416-208s v2
- Standard M416ms v2
- You have the administrative privileges.
-
Your system meets the requirements for
kdumpconfigurations and targets.
Procedure
Install
kdumpand other necessary packages:# dnf install kexec-tools kdump-utils makedumpfileVerify that the default location for crash dump files is set in the
kdumpconfiguration file and that the/var/crashfile is available:# grep -v "#" /etc/kdump.confpath /var/crash core_collector makedumpfile -l --message-level 7 -d 31Based on the RHEL VM size and version, check if you need a
vmcoretarget with more free space, such as/mnt/crash:Expand Table 3.3. Virtual machine sizes that have been tested with GEN2 VM on Azure RHEL Version Standard DS1 v2 (1 vCPU, 3.5GiB) Standard NV16as v4 (16 vCPUs, 56 GiB) Standard M416-208s v2 (208 vCPUs, 5700 GiB) Standard M416ms v2 (416 vCPUs, 11400 GiB) RHEL 9.4 - RHEL 10
Default
Default
Target
Target
-
Default indicates that
kdumpworks as expected with the default memory and the defaultkdumptarget. The defaultkdumptarget is the/var/crashfile. -
Target indicates that
kdumpworks as expected with the default memory. However, you might need to assign a target with more free space.
-
Default indicates that
To assign a target with free space, such as
/mnt/crash, edit the/etc/kdump.conffile and replace the default path:$ sed s/"path /var/crash"/"path /mnt/crash"The option path
/mnt/crashrepresents the path to the file system wherekdumpsaves the crash dump file.For details, such as writing the crash dump file to a different partition, directly to a device or storing it to a remote machine, see Configuring the kdump target.
If required, increase the crash kernel size by adding a boot parameter to ensure
kdumpcan capture thevmcore:For example, for a Standard M416-208s v2 VM, the sufficient size is 512 MB, so the boot parameter would be
crashkernel=512M.Open the GRUB configuration file and add
crashkernel=512Mto the boot parameter line:# vi /etc/default/grubGRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300 crashkernel=512M"Update the GRUB configuration file:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline
- Reboot the VM to allocate separate kernel crash memory to the VM.
Verification
Ensure that
kdumpis active and running.# systemctl status kdump● kdump.service - Crash recovery kernel arming Loaded: loaded (/usr/lib/systemd/system/kdump.service; enabled; vendor prese> Active: active (exited) since Fri 2024-02-09 10:50:18 CET; 1h 20min ago Process: 1252 ExecStart=/usr/bin/kdumpctl start (code=exited, status=0/SUCCES> Main PID: 1252 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 16975) Memory: 512B CGroup: /system.slice/kdump.service