Azure Citadel
  • Blogs

  • ARM
  • Azure Arc
    • Overview
    • Azure Arc-enabled Servers
      • Prereqs
      • Scenario
      • Hack Overview
      • Azure Landing Zone
      • Arc Pilot resource group
      • Azure Monitoring Agent
      • Additional policy assignments
      • Access your on prem VMs
      • Create onboarding scripts
      • Onboarding using scripts
      • Inventory
      • Monitoring
      • SSH
      • Windows Admin Center
      • Governance
      • Custom Script Extension
      • Key Vault Extension
      • Managed Identity
    • Azure Arc-enabled Kubernetes
      • Prereqs
      • Background
      • Deploy Cluster
      • Connect to Arc
      • Enable GitOps
      • Deploy Application
      • Enable Azure AD
      • Enforce Policy
      • Enable Monitoring
      • Enable Azure Defender
      • Enable Data Services
      • Enable Application Delivery
    • Useful Links
  • Azure CLI
    • Install
    • Get started
    • JMESPATH queries
    • Integrate with Bash
  • Azure Landing Zones
    • Prereqs
    • Day 1
      • Azure Baristas
      • Day 1 Challenge
    • Day 2
      • Example
      • Day 2 Challenge
    • Day 3
      • Day 3 Challenge
    • Useful Links
  • Azure Policy
    • Azure Policy Basics
      • Policy Basics in the Azure Portal
      • Creating Policy via the CLI
      • Deploy If Not Exists
      • Management Groups and Initiatives
    • Creating Custom Policies
      • Customer scenario
      • Policy Aliases
      • Determine the logic
      • Create the custom policy
      • Define, assign and test
  • Azure Stack HCI
    • Overview
    • Useful Links
    • Updates from Microsoft Ignite 2022
  • Marketplace
    • Introduction
      • Terminology
      • Offer Types
    • Partner Center
    • Offer Type
    • Publish a VM Offer HOL
      • Getting Started
      • Create VM Image
      • Test VM Image
      • VM Offer with SIG
      • VM Offer with SAS
      • Publish Offer
    • Other VM Resources
    • Publish a Solution Template HOL
      • Getting Started
      • Create ARM Template
      • Validate ARM Template
      • Create UI Definition
      • Package Assets
      • Publish Offer
    • Publish a Managed App HOL
      • Getting Started
      • Create ARM Template
      • Validate ARM Template
      • Create UI Definition
      • Package Assets
      • Publish Offer
    • Managed Apps with AKS HOL
    • Other Managed App Resources
    • SaaS Offer HOLs
    • SaaS Offer Video Series
      • Video 1 - SaaS Offer Overview
      • Video 2 - Purchasing a SaaS Offer
      • Video 3 - Purchasing a Private SaaS Plan
      • Video 4 - Publishing a SaaS Offer
      • Video 5 - Publishing a Private SaaS Plan
      • Video 6 - SaaS Offer Technical Overview
      • Video 7 - Azure AD Application Registrations
      • Video 8 - Using the SaaS Offer REST Fulfillment API
      • Video 9 - The SaaS Client Library for .NET
      • Video 10 - Building a Simple SaaS Landing Page in .NET
      • Video 11 - Building a Simple SaaS Publisher Portal in .NET
      • Video 12 - SaaS Webhook Overview
      • Video 13 - Implementing a Simple SaaS Webhook in .NET
      • Video 14 - Securing a Simple SaaS Webhook in .NET
      • Video 15 - SaaS Metered Billing Overview
      • Video 16 - The SaaS Metered Billing API with REST
  • Microsoft Fabric
    • Theory
    • Prereqs
    • Fabric Capacity
    • Set up a Remote State
    • Create a repo from a GitHub template
    • Configure an app reg for development
    • Initial Terraform workflow
    • Expanding your config
    • Configure a workload identity
    • GitHub Actions for Microsoft Fabric
    • GitLab pipeline for Microsoft Fabric
  • Packer & Ansible
    • Packer
    • Ansible
    • Dynamic Inventories
    • Playbooks & Roles
    • Custom Roles
    • Shared Image Gallery
  • Partner
    • Lighthouse and Partner Admin Link
      • Microsoft Cloud Partner Program
      • Combining Lighthouse and PAL
      • Minimal Lighthouse definition
      • Using service principals
      • Privileged Identity Management
    • Useful Links
  • REST API
    • REST API theory
    • Using az rest
  • Setup
  • Terraform
    • Fundamentals
      • Initialise
      • Format
      • Validate
      • Plan
      • Apply
      • Adding resources
      • Locals and outputs
      • Managing state
      • Importing resources
      • Destroy
    • Working Environments for Terraform
      • Cloud Shell
      • macOS
      • Windows with PowerShell
      • Windows with Ubuntu in WSL2
    • Using AzAPI
      • Using the REST API
      • azapi_resource
      • Removing azapi_resource
      • azapi_update_resource
      • Data sources and outputs
      • Removing azapi_update_resource
  • Virtual Machines
    • Azure Bastion with native tools & AAD
    • Managed Identities

  • About
  • Archive
  1. Home
  2. Marketplace
  3. Publish a VM Offer HOL
  4. Create VM Image

Table of Contents

  • Introduction
  • How to make the VM available for upload to Partner Center
  • Create a VM using the Azure CLI
    • Create VM using Shared Image Gallery approach (RECOMMENDED)
    • Create VM using SAS URI approach (ALTERNATIVE)
  • Ensure the VM has latest updates applied
  • Perform additional security checks
  • Apply custom configuration and scheduled tasks as required
  • Generalise the image
  • Resources

Create VM Image

Create and customise a VM image for publishing to Marketplace.

Introduction

We will create a VM using an approved base image. However it is also possible to create and deploy your own VM image. Starting from an approved base image simplifies the process.

There are numerous way we could create the VHD. In this lab we will use the Azure CLI. Packer is a useful tool for helping to automate the process.

How to make the VM available for upload to Partner Center

Until recently, the only option was to create an unmanaged VHD and generate a SAS URI to grant access to the VHD to Partner Center. This SAS URI is provided as part of the technical requirements of the offer listing in Partner Center.

The preferred option now is to use a Shared Image Gallery to make the VM image available. Again the Image details are entered as part of the technical requirements of the offer listing in Partner Center.

Most of the process for creating the VM is the same - expand the relevant section.

Note: Unless there is a specific reason to use the SAS URI approach, the Shared Image Gallery is recommended.

Create a VM using the Azure CLI

  1. Create a new resource group using the Azure CLI:

    az group create --name 'marketplace-vm-offer' --location 'westeurope'
    

    Example output

       {
          "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/marketplace-vm-offer",
          "location": "westeurope",
          "managedBy": null,
          "name": "marketplace-vm-offer",
          "properties": {
             "provisioningState": "Succeeded"
          },
          "tags": null,
          "type": "Microsoft.Resources/resourceGroups"
       }
    
  2. Create the VM

    We will create an Ubuntu VM using a small machine size to minimise costs. Generating ssh keys gives us a simple, secure way to connect to the VM.

    Create VM using Shared Image Gallery approach (RECOMMENDED)

    az vm create \
       --resource-group 'marketplace-vm-offer' \
       --name 'marketplacevm' \
       --image 'Canonical:UbuntuServer:18.04-LTS:latest' \
       --admin-username 'azureuser' \
       --generate-ssh-keys \
       --size 'Standard_B1s' \
    

    Create VM using SAS URI approach (ALTERNATIVE)

    It is important to create a VM using unmanaged disks as the base. This gives us direct access to the VHD which we will need to copy at a later stage.

    az vm create \
       --resource-group 'marketplace-vm-offer' \
       --name 'marketplacevm' \
       --image 'Canonical:UbuntuServer:18.04-LTS:latest' \
       --admin-username 'azureuser' \
       --generate-ssh-keys \
       --size 'Standard_B1s' \
       --use-unmanaged-disk
    

    Example output

       {
          "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/marketplace-vm-offer/providers/Microsoft.Compute/virtualMachines/marketplacevm",
          "location": "westeurope",
          "macAddress": "00-0D-3A-20-E4-73",
          "powerState": "VM running",
          "privateIpAddress": "10.0.0.4",
          "publicIpAddress": "13.93.33.158",
          "resourceGroup": "marketplace-vm-offer",
          "zones": ""
       }
    

Ensure the VM has latest updates applied

Before publishing VM offer you must ensure you have updated the OS and all installed services with the latest security and maintenance patches.

  1. Firstly we have to connect to the VM using ssh.

    Use the publicIpAddress returned in the output above. This will use the private key file id_rsa stored in ~/.ssh to authenticate:

    ssh azureuser@13.93.44.158
    
  2. Run the following commands on the VM to install the latest updates:

    sudo apt-get update && sudo apt-get upgrade -y
    

Perform additional security checks

When you publish a VM offer to the Azure Marketplace, you are required to maintain a high-level of security. Before publishing an offer you should follow the guidance in Security Recommendations for Azure Marketplace Images

As we are only publishing a test and will not put this “live” into the marketplace we will skip these additional checks for the purposes of this lab.

Apply custom configuration and scheduled tasks as required

To simulate a real workload, we will add a web server and a startup task to our VM offer.

  1. To install the NGINX web server, run the following command in the VM:

    sudo apt-get -y install nginx
    
  2. We will also add a scheduled job to run whenever the VM reboots. Edit the root crontab file as follows:

    sudo crontab -e
    
  3. Add the following line at the end of the file:

    @reboot less /etc/passwd > /tmp/users.txt
    
  4. Save and exit the file.

    This will illustrate the use of a scheduled job by dumping the names of all user accounts to a file in the /tmp directory each time the VM reboots.

    When we test our VM we will be able to confirm the webserver displays a default page and there is a file called users.txt in the /tmp directory containing the names of all users including the admin username we specified on creation.

Generalise the image

To create a reusable image, the operating system disk must be generalised. For Linux VMs this involves removing the Azure Linux agent and stopping the VM.

  1. Remove the Azure Linux agent by entering the following command

    sudo waagent -verbose -deprovision+user
    
  2. Confirm the removal

  3. Exit the SSH session in the VM by typing exit

  4. Stop and de-allocate the VM. Run the following command.

    az vm deallocate \
       --resource-group 'marketplace-vm-offer' \
       --name 'marketplacevm'
    

We now have a generalised OS VHD for our Ubuntu-based VM offer with a web server installed and a scheduled job on reboot. We can use this to create new (specialised) VMs and to submit our VM base to Partner Center as a VM Offer.

Resources

  • How to create a virtual machine using an approved base

Getting Started Create VM Image Test VM Image