Prepare a CentOS Linux image for Azure Local virtual machines (preview)

Caution

This article references CentOS, a Linux distribution that's reached end-of-life (EOL). Consider your use of CentOS and plan accordingly. For more information, see CentOS end-of-life guidance.

Applies to: Azure Local, version 23H2

This article describes how to prepare a CentOS 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 that 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 ISO image on your Azure Local instance. Here, we downloaded the CentOS-7-x86_64-Everything-2207-02.iso file. You use this image to create a VM image.

Workflow

To prepare a CentOS image and create a VM image from that image:

  1. Create a CentOS VM
  2. Connect to a VM and install CentOS
  3. Configure the VM
  4. Clean up the residual configuration
  5. Create a CentOS VM image

The following sections provide detailed instructions for each step in the workflow.

Create a VM image from a CentOS 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 CentOS image if you intend to enable guest management on the VMs.

Follow these steps on your Azure Local to create a VM image by using the Azure CLI.

Step 1: Create a CentOS VM

To use the downloaded CentOS 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. Assign 4096 for Startup memory.

      Screenshot that shows the Assign Memory page.

    4. Select the virtual network switch that the VM uses for connection.

      Screenshot that shows 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 Connect Virtual Hard Disk page.

    6. Select Install operating system from a bootable image. Point to the ISO that you downloaded earlier.

      Screenshot that shows the New Virtual Machine Wizard on the Installation Options page.

    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 Secure Boot disabled for the VM on the Settings page.

  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 CentOS

After the VM is running, follow these steps:

  1. Select the VM from Hyper-V Manager. Right-click it, and on the menu that opens, select Connect.

  2. Select the Install CentOS 7 option from the boot menu.

  3. Select the language and then select Continue.

    Screenshot that shows selecting a language during CentOS installation.

  4. Select the installation destination and then select Done.

    Screenshot that shows the installation destination during CentOS installation.

  5. Select Network & Host Name.

    Screenshot that shows selecting the network and hostname during CentOS installation.

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

    Screenshot that shows enabling the network interface during CentOS installation.

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

    Screenshot that shows setting the root password during CentOS installation.

  8. Select Finish configuration.

    Screenshot that shows selecting Finish configuration during CentOS installation.

  9. Select Begin Installation. After the installation is complete, select Reboot to reboot the VM.

    Screenshot that shows selecting Reboot during CentOS installation.

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 CentOS installation.

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

    sudo yum list installed | grep cloud-init
    
  3. Install cloud-init and verify the version of the cloud-init installed.

    sudo yum install cloud-init
    cloud-init --version
    

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.

  1. Clean the cloud-init default configurations.

    sudo yum clean all
    sudo cloud-init clean
    
  2. Clean up the logs and cache.

    sudo rm -rf /var/lib/cloud/ /var/log/* /tmp/*
    
  3. Remove the bash history.

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

  5. Export a VHDX or copy the VHDX from your VM. You can use the following methods:

    • Copy the VHDX to 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 a 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:

  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 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 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 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' 
    
  6. Verify that the image is created.