This article is to show you how you can create a basic customized image using the Azure VM Image Builder, and distribute to VHD.
To use this Quick Quickstarts, this can all be done using the Azure Cloudshell from the Portal. Simply copy and paste the code from here, at a miniumum, just update the subscriptionID variable below.
Happy Image Building!!!
az feature register --namespace Microsoft.VirtualMachineImages --name VirtualMachineTemplatePreview
az feature show --namespace Microsoft.VirtualMachineImages --name VirtualMachineTemplatePreview | grep state
# wait until it says registered
# check you are registered for the providers
az provider show -n Microsoft.VirtualMachineImages | grep registrationState
az provider show -n Microsoft.Storage | grep registrationState
If they do not saw registered, run the commented out code below.
## az provider register -n Microsoft.VirtualMachineImages
## az provider register -n Microsoft.Storage
# set your environment variables here!!!!
# destination image resource group
imageResourceGroup=aibvhd
# location (see possible locations in main docs)
location=WestUS2
# your subscription
# get the current subID : 'az account show | grep id'
subscriptionID=<INSERT YOUR SUBSCRIPTION ID HERE>
# Image Template Name
imageTemplateName=helloImageTemplateVHD01
# image distribution metadata reference name
runOutputName=aibCustomVhd01ro
# create resource group
az group create -n $imageResourceGroup -l $location
# assign permissions for that resource group
az role assignment create \
--assignee cf32a0cc-373c-47c9-9156-0db11f6a6dfc \
--role Contributor \
--scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup
# download the example and configure it with your vars
curl https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/4_Creating_a_Custom_Linux_Image_to_VHD/helloImageTemplateVHD.json -o helloImageTemplateVHD.json
sed -i -e "s/<subscriptionID>/$subscriptionID/g" helloImageTemplateVHD.json
sed -i -e "s/<rgName>/$imageResourceGroup/g" helloImageTemplateVHD.json
sed -i -e "s/<region>/$location/g" helloImageTemplateVHD.json
sed -i -e "s/<runOutputName>/$runOutputName/g" helloImageTemplateVHD.json
# submit the image confiuration to the VM Image Builder Service
az resource create \
--resource-group $imageResourceGroup \
--properties @helloImageTemplateVHD.json \
--is-full-object \
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
-n helloImageTemplateVHD01
# start the image build
az resource invoke-action \
--resource-group $imageResourceGroup \
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
-n helloImageTemplateVHD01 \
--action Run
# wait approx 15mins
az resource show \
--ids "/subscriptions/$subscriptionID/resourcegroups/$imageResourceGroup/providers/Microsoft.VirtualMachineImages/imageTemplates/$imageTemplateName/runOutputs/$runOutputName" \
--api-version=2019-05-01-preview | grep artifactUri
Note!! Once the VHD has been created, copy it to an alternative location, as soon as possible. The VHD is stored in a storage account in the temporary Resource Group created when the Image Template is submitted to the AIB service. If you delete the Image Template, then you will loose this VHD.
az resource delete \
--resource-group $imageResourceGroup \
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
-n helloImageTemplate01
az group delete -n $imageResourceGroup
-
Want to learn more???
- Explore the documentation in the MS Teams channel (Files).
- Look at the composition of the Image Builder Template, look in the 'Properties' you will see the source image, customization script it runs, and where it distributes it.
cat helloImageTemplateVHD.json
-
Want to try more???
-
Image Builder does support deployment through Azure Resource Manager, see here in the repo for examples, you will also see how you can use a RHEL ISO source too, and manu other capabilities.