Prepare a Red Hat Enterprise image for Azure Local virtual machines (preview)
Applies to: Azure Local, version 23H2
This article describes how to prepare a Red Hat Enterprise Linux image to create a virtual machine (VM) on your Azure Local. You use the Azure CLI for the VM image creation.
Prerequisites
Before you begin, meet the following prerequisites:
- Have access to an Azure Local instance. This system is deployed, registered, and connected to Azure Arc. Go to the Overview page in the Azure Local resource. On the Server tab on the right pane, Azure Arc should appear as Connected.
- Download the latest supported Red Hat Enterprise server image on your Azure Local instance. We support all Red Hat Enterprise Linux 7.x, 8.x, and 9.x versions. Here, we downloaded the rhel-9.4-x86_64-boot.iso file. You use this image to create a VM image.
Workflow
To prepare a Red Hat Enterprise image and create a VM image:
- Create a Red Hat Enterprise VM
- Connect to a VM and install the Red Hat OS
- Configure the VM
- Clean up the residual configuration
- Create a Red Hat VM image
The following sections provide detailed instructions for each step in the workflow.
Create a VM image from a Red Hat Enterprise image
Important
- Do not use an Azure Virtual Machine VHD disk to prepare the VM image for Azure Local.
- We recommend that you prepare a Red Hat Enterprise image if you intend to enable guest management on the VMs.
Follow these steps on your Azure Local system to create a VM image by using the Azure CLI.
Step 1: Create a Red Hat Enterprise VM
To use the downloaded Red Hat Enterprise image to provision a VM:
Use the downloaded image to create a VM with the following specifications:
Provide a friendly name for your VM.
Specify Generation 2 for your VM as you're working with a VHDX image here.
Select Assign Memory and then enter 4096 for Startup memory.
Select Configure Networking. From the dropdown list, select the virtual switch that the VM uses for the connection.
Accept the defaults on the Connect Virtual Hard Disk page.
Select Install Options and then select Install an operating system from a bootable image file. Point to the ISO that you downloaded earlier.
For step-by-step instructions, see Provision a VM by using Hyper-V Manager.
Use the UEFI certificate to secure boot the VM.
After the VM is created, it shows up in Hyper-V Manager. Select the VM, right-click it, and then select Settings.
On the left pane, select the Security tab. Then under Secure Boot, from the template dropdown list, select Microsoft UEFI Certificate Authority.
Select OK to save the changes.
Select the VM from Hyper-V Manager and then start the VM. The VM boots from the ISO image that you provided.
Step 2: Connect to a VM and install the Red Hat OS
After the VM is running, follow these steps:
Select the VM from Hyper-V Manager, right-click it to open the menu, and then select Connect.
Select Install Red Hat Enterprise Linux 9.4 from the boot menu.
Select the language and then select Continue.
On the Installation Summary page, you might see other actionable items.
Select Connect to Red Hat and create credentials. Select Register and then select Done.
Select Software Selection, keep the defaults, and select Done.
Select Installation Destination and then select Done.
Select Network & Host Name.
Enable the ON switch for the network interface and then select Done.
Select User setting and set the root password. Enter a password, confirm the password, and select Done.
Select Begin Installation.
After the installation is finished, select Reboot System to reboot the VM.
For step-by-step instructions, see Provision a VM by using Hyper-V Manager.
Step 3: Configure the VM
To configure the VM:
Connect and then sign in to the VM by using the root password that you created during the Red Hat Enterprise installation.
Make sure that
cloud-init
wasn't installed.Sudo yum list installed | grep cloud-init
Install the
cloud-init
tool and verify the version ofcloud-init
that was installed.Sudo yum install -y cloud-init cloud-init --version
Here's example output:
[hcitest@localhost ~]$ sudo yum install -y cloud-init Installed: cloud-init-23.4-7.el9_4.noarch dhcp-client-12:4.4.2-19.bl.el9.x86_64 dhcp-common-12:4.4.2-19.bl.el9.noarch geolite2-city-20191217-6.el9.noarch geolite2-country-20191217-6.el9.noarch ipcalc-l.0.0-5.el9.x86_64 python3-attrs-20.3.0-7.el9.noarch python3-babel-2.9.1-2.el9.noarch python3-configob j-5.0.6-25.el9.noarch python3-jinja2-2.11.3-5.el9.noarch python3-j sonpatch-1.21-16.el9.noarch python3-j sonpointer-2.0-4.el9.noarch python3-j sonschema-3.2.0-13.el9.noarch python3-markupsafe-l.1.1-12.el9.x86_64 python3-netifaces-0.10.6-15.el9.x86_64 python3-oauthlib-3.1.1-5.el9.noarch python3-prettytable-0.7.2-27.el9.noarch python3-pyrsistent-0.17.3-8.el9.x86_64 python3-pyserial-3.4-12.el9.noarch python3-pytz-2021.1-5.el9.noarch Complete! [hcitest@localhost ~]$ cloud-init —version /usr/bin/cloud-init 23.4-7.el9_4
Step 4: Clean up the residual configuration
Delete machine-specific files and data from your VM so that you can create a clean VM image without any history or default configurations. Follow these steps on your Azure Local to clean up the residual configuration.
Clean
cloud-init
default configurations.sudo yum clean all sudo cloud-init clean
Here's example output:
[hcitest@localhost ~]$ sudo yum clean all Updating Subscription Management repositories. 17 files removed [hcitest@localhost ~]$ sudo cloud-init clean
Clean up the logs and cache.
sudo rm -rf /var/lib/cloud/ /var/log/* /tmp/*
Unregister the VM.
sudo subscription-manager unregister sudo Subscription-manager clean
Here's example output:
[hcitest@localhost ~]$ sudo subscription-manager unregister Unregistering from: subscription.rhsm.redhat.com:443/subscription System has been unregistered. [hcitest@localhost ~]$ sudo subscription-manager clean All local data removed
Clean any host-specific details.
sudo rm -f /etc/sysconfig/network-scripts/* sudo rm -f /etc/ssh/ssh_host* sudo rm /etc/lvm/devices/system.devices
Remove the bash history.
sudo rm -f ~/.bash_history export HISTSIZE=0 exit
Shut down the VM. In Hyper-V Manager, go to Action > Shut Down.
Export a VHDX or copy the VHDX from your VM. You can use the following methods:
- Copy the VHDX to a user storage on the cluster shared volume on your Azure Local.
- Alternatively, copy the VHDX as a page blob to a container in an Azure Storage account.
Step 5: Create the VM image
Follow these steps on your Azure Local to create the VM image from the VHDX that you created earlier.
Use the Azure CLI to create the VM image:
Run PowerShell as an administrator.
Sign in. Run the following cmdlet:
az login
Set your subscription. Run the following cmdlet:
az account set --subscription <Subscription ID>
Set parameters for your subscription, resource group, custom location, location, OS type for the image, name of the image, and the path where the image is located. Replace the parameters in
< >
with the appropriate values.$Subscription = "<Subscription ID>" $Resource_Group = "<Resource group>" $CustomLocation = "<Custom location>" $Location = "<Location for your Azure Local>" $OsType = "<OS of source image>"
Parameters are described in the following table.
Parameter Description Subscription
Subscription associated with your Azure Local instance. Resource_Group
Resource group for the Azure Local instance that you associate with this image. Location
Location for your Azure Local instance. For example, the location could be eastus
orwestreurope
.OsType
Operating system associated with the source image. This system can be Windows or Linux. Use the VHDX of the VM to create a gallery image. Use this VM image to create Azure Arc virtual machines on Azure Local.
Make sure to copy the VHDX in user storage in the cluster shared volume of Azure Local. For example, the path could look like
C:\ClusterStorage\UserStorage_1\linuxvhdx
.$ImagePath = "Path to user storage in CSV" $ImageName = "mylinuxvmimg" az stack-hci-vm image create --subscription $subscription -g $resource_group --custom-location $CustomLocation --location $location --image-path $ImagePath --name $ImageName --debug --os-type 'Linux'
Verify that the image is created.
Related content
- Create Azure Arc VMs on your Azure Local instance.