You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Create a Linux VM with Azure Image Builder (preview)
3
-
description: Create a Linux VM with the Azure Image Builder.
2
+
title: Use Azure Image Builder with an image gallery for Linux VMs (preview)
3
+
description: Create Linux VM images with Azure Image Builder and Shared Image Gallery.
4
4
author: cynthn
5
5
ms.author: cynthn
6
-
ms.date: 05/02/2019
6
+
ms.date: 05/05/2019
7
7
ms.topic: how-to
8
8
ms.service: virtual-machines-linux
9
9
ms.subservice: imaging
10
-
10
+
ms.reviewer: danis
11
11
---
12
-
# Preview: Create a Linux VM with Azure Image Builder
12
+
# Preview: Create a Linux image and distribute it to a Shared Image Gallery
13
13
14
-
This article shows you how you can create a customized Linux image using the Azure Image Builder and the Azure CLI. The example in this article uses three different [customizers](image-builder-json.md#properties-customize) for customizing the image:
14
+
This article shows you how you can use the Azure Image Builder, and the Azure CLI, to create an image version in a [Shared Image Gallery](https://docs.microsoft.com/azure/virtual-machines/windows/shared-image-galleries), then distribute the image globally. You can also do this using [Azure PowerShell](../windows/image-builder-gallery.md).
15
15
16
-
- Shell (ScriptUri) - downloads and runs a [shell script](https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/customizeScript.sh).
17
-
- Shell (inline) - runs specific commands. In this example, the inline commands include creating a directory and updating the OS.
18
-
- File - copies a [file from GitHub](https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/exampleArtifacts/buildArtifacts/index.html) into a directory on the VM.
19
16
20
-
You can also specify a `buildTimeoutInMinutes`. The default is 240 minutes, and you can increase a build time to allow for longer running builds.
17
+
We will be using a sample .json template to configure the image. The .json file we are using is here: [helloImageTemplateforSIG.json](https://github.com/danielsollondon/azvmimagebuilder/blob/master/quickquickstarts/1_Creating_a_Custom_Linux_Shared_Image_Gallery_Image/helloImageTemplateforSIG.json).
21
18
22
-
We will be using a sample .json template to configure the image. The .json file we are using is here: [helloImageTemplateLinux.json](https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/quickquickstarts/0_Creating_a_Custom_Linux_Managed_Image/helloImageTemplateLinux.json).
19
+
To distribute the image to a Shared Image Gallery, the template uses [sharedImage](image-builder-json.md#distribute-sharedimage) as the value for the `distribute` section of the template.
23
20
24
21
> [!IMPORTANT]
25
22
> Azure Image Builder is currently in public preview.
@@ -43,194 +40,257 @@ Check your registration.
43
40
44
41
```azurecli-interactive
45
42
az provider show -n Microsoft.VirtualMachineImages | grep registrationState
46
-
43
+
az provider show -n Microsoft.KeyVault | grep registrationState
44
+
az provider show -n Microsoft.Compute | grep registrationState
47
45
az provider show -n Microsoft.Storage | grep registrationState
48
46
```
49
47
50
48
If they do not say registered, run the following:
51
49
52
50
```azurecli-interactive
53
51
az provider register -n Microsoft.VirtualMachineImages
54
-
52
+
az provider register -n Microsoft.Compute
53
+
az provider register -n Microsoft.KeyVault
55
54
az provider register -n Microsoft.Storage
56
55
```
57
56
58
-
## Setup example variables
57
+
## Set variables and permissions
59
58
60
59
We will be using some pieces of information repeatedly, so we will create some variables to store that information.
61
60
61
+
For Preview, image builder will only support creating custom images in the same Resource Group as the source managed image. Update the resource group name in this example to be the same resource group as your source managed image.
62
62
63
-
```console
64
-
# Resource group name - we are using myImageBuilderRGin this example
65
-
imageResourceGroup=myImageBuilerRGLinux
63
+
```azurecli-interactive
64
+
# Resource group name - we are using ibLinuxGalleryRG in this example
65
+
sigResourceGroup=ibLinuxGalleryRG
66
66
# Datacenter location - we are using West US 2 in this example
67
-
location=WestUS2
68
-
# Name forthe image - we are using myBuilderImagein this example
69
-
imageName=myBuilderImage
70
-
# Run output name
71
-
runOutputName=aibLinux
67
+
location=westus2
68
+
# Additional region to replicate the image to - we are using East US in this example
69
+
additionalregion=eastus
70
+
# name of the shared image gallery - in this example we are using myGallery
71
+
sigName=myIbGallery
72
+
# name of the image definition to be created - in this example we are using myImageDef
73
+
imageDefName=myIbImageDef
74
+
# image distribution metadata reference name
75
+
runOutputName=aibLinuxSIG
72
76
```
73
77
74
78
Create a variable for your subscription ID. You can get this using `az account show | grep id`.
75
79
76
-
```console
77
-
subscriptionID=<Your subscription ID>
80
+
```azurecli-interactive
81
+
subscriptionID=<Subscription ID>
78
82
```
79
83
80
-
## Create the resource group.
81
-
This is used to store the image configuration template artifact and the image.
84
+
Create the resource group.
82
85
83
86
```azurecli-interactive
84
-
az group create -n $imageResourceGroup -l $location
87
+
az group create -n $sigResourceGroup -l $location
85
88
```
86
89
87
-
## Set permissions on the resource group
88
-
Give Image Builder 'contributor' permission to create the image in the resource group. Without the proper permissions, the image build will fail.
90
+
## Create a user-assigned identity and set permissions on the resource group
91
+
Image Builder will use the [user-identity](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/qs-configure-cli-windows-vm#user-assigned-managed-identity) provided to inject the image into the Azure Shared Image Gallery (SIG). In this example, you will create an Azure role definition that has the granular actions to perform distributing the image to the SIG. The role definition will then be assigned to the user-identity.
89
92
90
-
The `--assignee` value is the app registration ID for the Image Builder service.
93
+
```bash
94
+
# create user assigned identity for image builder to access the storage account where the script is located
95
+
idenityName=aibBuiUserId$(date +'%s')
96
+
az identity create -g $sigResourceGroup -n $idenityName
A parameterized sample image configuration template has been created for you to use. Download the sample .json file and configure it with the variables you set earlier.
To use Image Builder with a shared image gallery, you need to have an existing image gallery and image definition. Image Builder will not create the image gallery and image definition for you.
105
128
106
-
sed -i -e "s/<subscriptionID>/$subscriptionID/g" helloImageTemplateLinux.json
107
-
sed -i -e "s/<rgName>/$imageResourceGroup/g" helloImageTemplateLinux.json
108
-
sed -i -e "s/<region>/$location/g" helloImageTemplateLinux.json
109
-
sed -i -e "s/<imageName>/$imageName/g" helloImageTemplateLinux.json
110
-
sed -i -e "s/<runOutputName>/$runOutputName/g" helloImageTemplateLinux.json
129
+
If you don't already have a gallery and image definition to use, start by creating them. First, create an image gallery.
130
+
131
+
```azurecli-interactive
132
+
az sig create \
133
+
-g $sigResourceGroup \
134
+
--gallery-name $sigName
111
135
```
112
136
113
-
You can modify this example .json as needed. For example, you can increase the value of `buildTimeoutInMinutes` to allow for longer running builds. You can edit the file in Cloud Shell using a text editor like `vi`.
137
+
Then, create an image definition.
114
138
115
-
```bash
116
-
vi helloImageTemplateLinux.json
139
+
```azurecli-interactive
140
+
az sig image-definition create \
141
+
-g $sigResourceGroup \
142
+
--gallery-name $sigName \
143
+
--gallery-image-definition $imageDefName \
144
+
--publisher myIbPublisher \
145
+
--offer myOffer \
146
+
--sku 18.04-LTS \
147
+
--os-type Linux
117
148
```
118
149
119
-
> [!NOTE]
120
-
> For source image, you must always [specify a version](https://github.com/danielsollondon/azvmimagebuilder/blob/master/troubleshootingaib.md#image-version-failure), you cannot use `latest`.
121
-
>
122
-
> If you add or change the resource group where the image is being distributed, you need to make sure the [permissions are set for the resource group](#set-permissions-on-the-resource-group).
123
150
151
+
## Download and configure the .json
124
152
125
-
## Submit the image configuration
126
-
Submit the image configuration to the VM Image Builder service
153
+
Download the .json template and configure it with your variables.
sed -i -e "s/<subscriptionID>/$subscriptionID/g" helloImageTemplateforSIG.json
158
+
sed -i -e "s/<rgName>/$sigResourceGroup/g" helloImageTemplateforSIG.json
159
+
sed -i -e "s/<imageDefName>/$imageDefName/g" helloImageTemplateforSIG.json
160
+
sed -i -e "s/<sharedImageGalName>/$sigName/g" helloImageTemplateforSIG.json
161
+
sed -i -e "s/<region1>/$location/g" helloImageTemplateforSIG.json
162
+
sed -i -e "s/<region2>/$additionalregion/g" helloImageTemplateforSIG.json
163
+
sed -i -e "s/<runOutputName>/$runOutputName/g" helloImageTemplateforSIG.json
164
+
sed -i -e "s%<imgBuilderId>%$imgBuilderId%g" helloImageTemplateforSIG.json
135
165
```
136
166
137
-
If it completes successfully, it will return a success message, and create an image builder configuration template artifact in the $imageResourceGroup. You can see the resource group in the portal if you enable 'Show hidden types'.
138
-
139
-
Also, in the background, Image Builder creates a staging resource group in your subscription. Image Builder uses the staging resource group for the image build. The name of the resource group will be in this format: `IT_<DestinationResourceGroup>_<TemplateName>`.
167
+
## Create the image version
140
168
141
-
> [!IMPORTANT]
142
-
> Do not delete the staging resource group directly. If you delete the image template artifact, it will automatically delete the staging resource group. For more information, see the [Clean up](#clean-up) section at the end of this article.
169
+
This next part will create the image version in the gallery.
143
170
144
-
If the service reports a failure during the image configuration template submission, see the [troubleshooting](https://github.com/danielsollondon/azvmimagebuilder/blob/master/troubleshootingaib.md#template-submission-errors--troubleshooting) steps. You will also need to delete the template before you retry submitting the build. To delete the template:
171
+
Submit the image configuration to the Azure Image Builder service.
Wait until the build is complete, for this example, it can take 10-15 minutes.
167
-
168
-
If you encounter any errors, please review these [troubleshooting](https://github.com/danielsollondon/azvmimagebuilder/blob/master/troubleshootingaib.md#image-build-errors--troubleshooting) steps.
192
+
Creating the image and replicating it to both regions can take a while. Wait until this part is finished before moving on to creating a VM.
169
193
170
194
171
195
## Create the VM
172
196
173
-
Create the VM using the image you built.
197
+
Create a VM from the image version that was created by Azure Image Builder.
Type `exit` when you are done to close the SSH connection.
203
-
204
-
## Check the source
225
+
## Clean up resources
205
226
206
-
In the Image Builder Template, in the 'Properties', you will see the source image, customization script it runs, and where it is distributed.
227
+
If you want to now try re-customizing the image version to create a new version of the same image, skip the next steps and go on to [Use Azure Image Builder to create another image version](image-builder-gallery-update-image-version.md).
207
228
208
-
```bash
209
-
cat helloImageTemplateLinux.json
210
-
```
211
229
212
-
For more detailed information about this .json file, see [Image builder template reference](image-builder-json.md)
230
+
This will delete the image that was created, along with all of the other resource files. Make sure you are finished with this deployment before deleting the resources.
213
231
214
-
## Clean up
215
-
216
-
When you are done, you can delete the resources.
232
+
When deleting image gallery resources, you need delete all of the image versions before you can delete the image definition used to create them. To delete a gallery, you first need to have deleted all of the image definitions in the gallery.
0 commit comments