Edit

Share via


Prepare Ubuntu Azure Marketplace image for Azure Local VMs

This article explains how to prepare an Ubuntu Azure Marketplace image for use with Azure Local virtual machines (VMs). By following these steps, you ensure your VM has the latest security updates, support, and integration features.

Prerequisites

Sign in and set subscription

  1. Connect to a machine on your Azure Local.

  2. Sign in. Type:

    az login --use-device-code
    
  3. Set your subscription.

    az account set --subscription <Subscription ID>
    

Set up and prepare an Azure VM

To set up and prepare an Azure VM, follow these steps:

  1. Sign in to the Azure portal.

  2. In the left pane, select Virtual Machines, next select Create, and then select Virtual Machine.

  3. Browse the available images and choose your preferred Ubuntu version.

    Screenshot of the Azure portal image selection page.

  4. Enter the required details in the wizard and finish setting up the Azure VM.

    Note

    Avoid username conflicts by creating the Azure VM with a username you don't use on Azure Local. If you use the same username (for example, "usernameA") on both the Azure VM and Azure Local, and then reuse the VHD, the VM keeps the original login information. For the best results, set up Azure Local VMs with different credentials (such as "usernameB").

  5. After the VM is deployed, go to the VM overview page, select the Connect option, and then select Serial console.

    Screenshot of the Serial console sign in option in Azure portal.

  6. Connect to the VM with your credentials and run these commands:

    1. Sign in to the VM as the root user:

      sudo su
      
    2. Clean the cloud-init default configuration because it isn't relevant for Azure Local VMs.

      sudo cloud-init clean
      sudo rm -rf /var/lib/cloud/ /var/log/* /tmp/*
      
    3. Clean VM-specific SSH host keys.

      sudo rm -f /etc/ssh/ssh_host*
      

Change the data source of the VM image

To change the data source of the VM image, follow these steps:

  1. Change the directory to the following path and list the files to locate the data source file 90_dpkg.cfg.Run these commands:

    cd /etc/cloud/cloud.cfg.d/
    ls
    

    Example output:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ ls
    05_logging.cfg  10-azure-kvp.cfg  90-azure.cfg  90_dpkg.cfg
    
  2. Open the 90_dpkg.cfg file. Run this command:

    cat 90_dpkg.cfg
    

    Example output:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ cat 90_dpkg.cfg
    # to update this file, run dpkg-reconfigure cloud-init
    datasource_list: [ Azure ]
    
  3. Open and update the datasource_list from Azure to NoCloud. Run this command:

    sudo dpkg-reconfigure cloud-init
    

    Example output:

    Cloud-init supports searching different "Data Sources" for information that it uses to configure a cloud instance.
    
    Warning: Only select 'Ec2' if this system will be run on a system with the EC2 metadata service present. Doing so incorrectly will result in a substantial timeout on boot.
    
    Which data sources should be searched?
    
    [ ] NoCloud: Reads info from /var/lib/cloud/seed only  
    [ ] ConfigDrive: Reads data from Openstack Config Drive  
    [ ] OpenNebula: read from OpenNebula context disk  
    [ ] DigitalOcean: reads data from Droplet datasource  
    [*] Azure: read from MS Azure cdrom. Requires walinux-agent
    <Ok>
    
    1. Toggle the (*) by pressing spacebar to activate NoCloud and remove Azure.

    2. Save the file by pressing Enter.

    Example output:

    Cloud-init supports searching different "Data Sources" for information that it uses to configure a cloud instance.
    
    Warning: Only select 'Ec2' if this system will be run on a system with the EC2 metadata service present. Doing so incorrectly will result in a substantial timeout on boot.
    
    Which data sources should be searched?
    
    [*] NoCloud: Reads info from /var/lib/cloud/seed only  
    [ ] ConfigDrive: Reads data from Openstack Config Drive  
    [ ] OpenNebula: read from OpenNebula context disk  
    [ ] DigitalOcean: reads data from Droplet datasource  
    [ ] Azure: read from MS Azure cdrom. Requires walinux-agent
    <Ok>
    
  4. To check that the file was updated, run this command:

    cat 90_dpkg.cfg
    

    Example output:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ cat 90_dpkg.cfg
    # to update this file, run dpkg-reconfigure cloud-init
    datasource_list: [ NoCloud ]
    
  5. Remove the bash history. Run these commands:

    sudo rm -f ~/.bash_history
    export HISTSIZE=0
    exit
    
  6. Stop the Azure VM as the configuration changes are now complete.

Export an Azure VM OS disk to a VHD on the Azure Local cluster

To export an Azure VM OS disk to a VHD on the Azure Local cluster, follow these steps:

  1. In the Azure portal for your Azure Local resource, go to the VM overview. Under the Settings option, select Disks, and select the Disks name link.

    Screenshot of the OS disk details page.

  2. Under Settings, select Disk Export, and then select Generate URL to generate a secure URL for the disk.

    Screenshot of the disk export option with secure URL generation.

  3. Copy the generated secure URL link for the next step.

Create an Azure Local image

To create an Azure Local image using the SAS token, run this command:

$rg = "<resource-group>"
$cl = "/subscriptions/<sub>/resourcegroups/$rg/providers/microsoft.extendedlocation/customlocations/<customlocation-name>"
$sas = '"https://EXAMPLE.blob.storage.azure.net/EXAMPLE/abcd<sas-token>"'

az stack-hci-vm image create -g $rg --custom-___location $cl --name "<IMAGE-NAME>" --os-type "Linux" --image-path $sas

Create an Azure Local VM

To create an Azure Local VM using the Azure Local VM image you created, follow the steps in Create Azure Local virtual machines enabled by Azure Arc.