Image

 

A managed image is a copy of either a full VM (including any attached data disks) or just the OS disk, depending on how you create the image. When you create a VM from the image, a copy of the VHDs in the image are used to create the disks for the new VM. The managed image remains in storage and can be used over and over again to create new VMs.

DeanV IT Services - Azure Shared Image Gallery

 

To generalize your Windows VM, follow these steps:

  1. Sign in to your Windows VM.
  2. Open a Command Prompt window as an administrator.Change the directory to %windir%\system32\sysprep, and then run exe.
  3. In the System Preparation Tooldialog box, select Enter System Out-of-Box Experience (OOBE) and select the Generalize check box.
  4. For Shutdown Options, select Shutdown.
  5. Select OK.
  6. When Sysprep completes, it shuts down the VM.Do not restart the VM.

Create a managed image in the portal

  1. Go to the Azure portal.
  2. In the menu on the left, select Virtual machinesand then select the VM from the list.
  3. In the Virtual machinepage for the VM, on the upper menu, select Capture.

The Create image page appears.

  1. For Name, either accept the pre-populated name or enter a name that you would like to use for the image.
  2. For Resource group, either select Create newand enter a name, or select Use existing and select a resource group to use from the drop-down list.
  3. If you want to delete the source VM after the image has been created, select Automatically delete this virtual machine after creating the image.
  4. If you want the ability to use the image in any availability zone, select Onfor Zone resiliency.
  5. Select Createto create the image.
  6. After the image is created, you can find it as an Imageresource in the list of resources in the resource group.

 

Shared Image Galllery

Shared Image Gallery is a service that helps you build structure and organization around your custom managed VM images. Using a Shared Image Gallery you can share your images to different users, service principals, or AD groups within your organization. Shared images can be replicated to multiple regions, for quicker scaling of your deployments.

If you have a large number of managed images that you need to maintain and would like to make them available throughout your company, you can use a Shared Image Gallery as a repository that makes it easy to update and share your images.

ResourceDescription
Managed imageThis is a basic image that can be used alone or used to create an image version in an image gallery. Managed images are created from generalized VMs. A managed image is a special type of VHD that can be used to make multiple VMs and can now be used to create shared image versions.
Image galleryLike the Azure Marketplace, an image gallery is a repository for managing and sharing images, but you control who has access.
Image definitionImages are defined within a gallery and carry information about the image and requirements for using it internally. This includes whether the image is Windows or Linux, release notes, and minimum and maximum memory requirements. It is a definition of a type of image.
Image versionAn image version is what you use to create a VM when using a gallery. You can have multiple versions of an image as needed for your environment. Like a managed image, when you use an image version to create a VM, the image version is used to create new disks for the VM. Image versions can be used multiple times.

DeanV IT Services - Azure Shared Images Gallery

Create a Shared Image Gallery

 

CLI:

https://docs.microsoft.com/en-us/cli/azure/sig?view=azure-cli-latest

 

 

Use Azure CLI to create a new gallery,

Bash CLI:

az login

az account list -o table

az account set –subscription [subscriptionID]

az feature register –namespace Microsoft.Compute –name GalleryPreview

Once the feature ‘GalleryPreview’ is registered, invoking ‘az provider register -n Microsoft.Compute’ is required to get the change propagated

{

  “id”: “/subscriptions/8aa7c356-e459-4fcf-a7c9-6d31f2ab240b/providers/Microsoft.Features/providers/Microsoft.Compute/features/GalleryPreview”,

  “name”: “Microsoft.Compute/GalleryPreview”,

  “properties”: {

    “state”: “Registering”

  },

  “type”: “Microsoft.Features/providers/features”

}

az provider register –name Microsoft.Compute

 

To list all the Shared Image Gallery resources across subscriptions that you have permissions to,

az account list -otsv –query “[].id” | xargs -n 1 az sig list –subscription

 

Create an image gallery

An image gallery is the primary resource used for enabling image sharing. Gallery names must be unique within your subscription. Create an image gallery using az sig create. The following example creates a gallery named SwecoAzureCoreSIG in RG-Azure-Dev-Test-Gallery.

az group create –name RG-Azure-Core-SIG –location WestEurope

az sig create -g RG-Azure-Core-SIG –gallery-name SwecoAzureCoreSIG

 

Create with JSON:

{

“$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,

“contentVersion”: “1.0.0.0”,

“parameters”: {

“galleryName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Shared Image Gallery.”

}

}

},

“resources”: [

{

“type”: “Microsoft.Compute/galleries”,

“name”: “[parameters(‘galleryName’)]”,

“apiVersion”: “2018-06-01”,

“location”: “[resourceGroup().location]”,

“properties”: {

“description”: “SWECO Shared Image Gallery”

}

}

]

}

 

Create an image definition

Create an initial image definition in the gallery using az sig image-definition create.

az sig image-definition create

–gallery-image-definition Sweco-Server-Image-Win2016-1.0.1 \

–gallery-name SwecoAzureCoreSIG \

–resource-group RG-Azure-Core-SIG\

–publisher Dennis_Vredeveldt \

–offer Windows-Server \

–sku 2016-Datacenter \

–os-type Windows \

–description Sweco-default-Image-Windows-Server-2016-1.0.1

 

#Create new Image-definition – Rename / Choose a different publisher, offer, sku combination.

az sig image-definition create –gallery-image-definition Sweco-Server-Image-Win2019 –gallery-name SwecoAzureCoreSIG –resource-group RG-Azure-Core-SIG –publisher Dennis_Vredeveldt –offer Windows-Server –sku 2019-Datacenter –os-type Windows –description Sweco-default-Image-Windows-Server-2019

 

Other examples that can be added to image definition,

[–disallowed-disk-types]

[–end-of-life-date]

[–eula]

[–location]

[–maximum-cpu-core]

[–maximum-memory]

[–minimum-cpu-core]

 

[–minimum-memory]

[–plan-name]

[–plan-product]

[–plan-publisher]

[–privacy-statement-uri]

[–release-note-uri]

[–subscription]

[–tags]

Create with JSON:

 

{

“$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,

“contentVersion”: “1.0.0.0”,

“parameters”: {

“galleryName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Shared Image Gallery.”

}

},

“galleryImageDefinitionName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Image Definition.”

}

}

},

“resources”: [

{

“type”: “Microsoft.Compute/galleries/images”,

“name”: “[concat(parameters(‘galleryName’), ‘/’, parameters(‘galleryImageDefinitionName’))]”,

“apiVersion”: “2018-06-01”,

“location”: “[resourceGroup().location]”,

“properties”: {

“description”: “Sweco-default-Image-Windows-Server-2016-with-McAfee-agent”,

“osType”: “windows”,

“osState”: “Generalized”,

“endOfLifeDate”: “2020-01-01”,

“identifier”: {

“offer”: “Windows-Server”,

“publisher”: “Dennis Vredeveldt”,

“sku”: “2016-Datacenter”

},

“recommended”: {

“vCPUs”: {

“min”: “2”,

“max”: “4”

},

“memory”: {

“min”: “2048”,

“max”: “4096”

}

}

}

}

]

}

 

 

Create Image Version

Create versions of the image as needed using az image gallery create-image-version. You will need to pass in the ID of the managed image to use as a baseline for creating the image version. You can use az image list to get information about images that are in a resource group.

 

az sig image-version create \

–gallery-name SwecoSzureCoreSIG \

–resource-group RG-Azure-Core-SIG \

–gallery-image-definition Sweco-Server-Image-Win2016 \

–gallery-image-version 1.0.1 \

–managed-image “/subscriptions/<subscription ID>/resourceGroups/ RG-Azure-Core-SIG/providers/Microsoft.Compute/images/myImage”

–target-regions “WestEurope” “NorthEurope” \

 

#Create new Image Version

az sig image-version create –gallery-name SwecoAzureCoreSIG –resource-group RG-Azure-Core-SIG –gallery-image-definition Sweco-Server-Image-Win2016-1.0.1 –gallery-image-version 1.0.1 –managed-image “/subscriptions/3a3210dc-a860-4d96-8673-f058289e22ac/resourceGroups/RG-Azure-Core-Template/providers/Microsoft.Compute/images/Sweco-Server-Image-Win2016-1.0.1” –target-regions “WestEurope”

 

Other examples that can be added to image-version,

[–end-of-life-date]

[–exclude-from-latest {false, true}]

[–location]

[–no-wait]

[–replica-count]

[–subscription]

[–tags]

[–target-regions]

 

Create with JSON:

{

“$schema”: “https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,

“contentVersion”: “1.0.0.0”,

“parameters”: {

“sourceManagedImageResourceId”:   {

“type”:       “string”,

“metadata”: {

“description”: “Resource ID of the source managed image.”

}

},

“galleryName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Shared Image Gallery.”

}

},

“galleryImageDefinitionName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Image Definition.”

}

},

“galleryImageVersionName”: {

“type”: “string”,

“metadata”: {

“description”: “Name of the Image Version – should follow <MajorVersion>.<MinorVersion>.<Patch>.”

}

}

},

“resources”: [

{

“type”: “Microsoft.Compute/galleries/images/versions”,

“name”: “[concat(parameters(‘galleryName’), ‘/’, parameters(‘galleryImageDefinitionName’), ‘/’, parameters(‘galleryImageVersionName’))]”,

“apiVersion”: “2018-06-01”,

“location”: “[resourceGroup().location]”,

“properties”: {

“publishingProfile”: {

“replicaCount”:1,

“targetRegions”: [

{“name”: “westeurope”}

],

“source”: {

“managedImage”: {

“id”: “[parameters(‘sourceManagedImageResourceId’)]”

}