Prepare a Red Hat Enterprise image for Azure Stack HCI virtual machines (preview)

Applies to: Azure Stack HCI, version 23H2

This article describes how to prepare a Red Hat Enterprise Linux image to create a virtual machine (VM) on your Azure Stack HCI cluster. You use the Azure CLI for the VM image creation.

Prerequisites

Before you begin, meet the following prerequisites:

  • Have access to an Azure Stack HCI cluster. This cluster is deployed, registered, and connected to Azure Arc. Go to the Overview page in the Azure Stack HCI cluster 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 Stack HCI cluster. 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:

  1. Create a Red Hat Enterprise VM
  2. Connect to a VM and install the Red Hat OS
  3. Configure the VM
  4. Clean up the residual configuration
  5. 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 Stack HCI.
  • 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 Stack HCI cluster 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:

  1. Use the downloaded image to create a VM with the following specifications:

    1. Provide a friendly name for your VM.

      Screenshot that shows the New Virtual Machine Wizard on the Specify Name and Location page.

    2. Specify Generation 2 for your VM as you're working with a VHDX image here.

      Screenshot that shows the New Virtual Machine Wizard on the Specify Generation page.

    3. Select Assign Memory and then enter 4096 for Startup memory.

      Screenshot that shows the New Virtual Machine Wizard on the Assign Memory page.

    4. Select Configure Networking. From the dropdown list, select the virtual switch that the VM uses for the connection.

      Screenshot that shows the New Virtual Machine Wizard on the Configure Networking page.

    5. Accept the defaults on the Connect Virtual Hard Disk page.

      Screenshot that shows the New Virtual Machine Wizard on the Virtual Hard Disk page.

    6. Select Install Options and then select Install an operating system from a bootable image file. Point to the ISO that you downloaded earlier.

      Screenshot that shows the OS Installation Options screen.

    For step-by-step instructions, see Provision a VM by using Hyper-V Manager.

  2. Use the UEFI certificate to secure boot the VM.

    1. After the VM is created, it shows up in Hyper-V Manager. Select the VM, right-click it, and then select Settings.

    2. On the left pane, select the Security tab. Then under Secure Boot, from the template dropdown list, select Microsoft UEFI Certificate Authority.

    3. Select OK to save the changes.

    Screenshot that shows the UEFI Secure Boot enabled screen.

  3. 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:

  1. Select the VM from Hyper-V Manager, right-click it to open the menu, and then select Connect.

  2. Select Install Red Hat Enterprise Linux 9.4 from the boot menu.

  3. Select the language and then select Continue.

    Screenshot that shows the Language select screen.

  4. On the Installation Summary page, you might see other actionable items.

    Screenshot that shows the Installation Summary with actionable items.

  5. Select Connect to Red Hat and create credentials. Select Register and then select Done.

    Screenshot that shows the Connect to Red Hat page.

  6. Select Software Selection, keep the defaults, and select Done.

    Screenshot that shows the Software Selection page.

  7. Select Installation Destination and then select Done.

    Screenshot that shows the Installation Destination page.

  8. Select Network & Host Name.

    Screenshot that shows the completed Installation Summary page.

  9. Enable the ON switch for the network interface and then select Done.

    Screenshot that shows the Network & Host Name page.

  10. Select User setting and set the root password. Enter a password, confirm the password, and select Done.

    Screenshot that shows the credentials page.

  11. Select Begin Installation.

    Screenshot that shows the Begin Installation button.

  12. After the installation is finished, select Reboot System to reboot the VM.

    Screenshot that shows the Reboot System button after installation.

For step-by-step instructions, see Provision a VM by using Hyper-V Manager.

Step 3: Configure the VM

To configure the VM:

  1. Connect and then sign in to the VM by using the root password that you created during the Red Hat Enterprise installation.

  2. Make sure that cloud-init wasn't installed.

    Sudo yum list installed | grep cloud-init
    
  3. Install the cloud-init tool and verify the version of cloud-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 Stack HCI cluster to clean up the residual configuration.

  1. 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
    
  2. Clean up the logs and cache.

    sudo rm -rf /var/lib/cloud/ /var/log/* /tmp/*
    
  3. 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
    
  4. 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
    
  5. Remove the bash history.

    sudo rm -f ~/.bash_history 
    export HISTSIZE=0
    exit
    
  6. Shut down the VM. In Hyper-V Manager, go to Action > Shut Down.

  7. 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 Stack HCI.
    • Alternatively, copy the VHDX as a page blob to a container in an Azure Storage account.

    Screenshot that shows exporting a virtual machine VHDX.

Step 5: Create the VM image

Follow these steps on your Azure Stack HCI cluster to create the VM image from the VHDX that you created earlier.

Use the Azure CLI to create the VM image:

  1. Run PowerShell as an administrator.

  2. Sign in. Run the following cmdlet:

    az login
    
  3. Set your subscription. Run the following cmdlet:

    az account set --subscription <Subscription ID>
    
  4. 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 Stack HCI cluster>"
    $OsType = "<OS of source image>"
    

    Parameters are described in the following table.

    Parameter Description
    Subscription Subscription associated with your Azure Stack HCI cluster.
    Resource_Group Resource group for Azure Stack HCI cluster that you associate with this image.
    Location Location for your Azure Stack HCI cluster. For example, the location could be eastus or westreurope.
    OsType Operating system associated with the source image. This system can be Windows or Linux.
  5. Use the VHDX of the VM to create a gallery image. Use this VM image to create Azure Arc virtual machines on your Azure Stack HCI.

    Make sure to copy the VHDX in user storage in the cluster shared volume of your Azure Stack HCI. 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' 
    
  6. Verify that the image is created.