> ## Content Index
> Fetch the complete content index at: https://codeisahighway.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to create a virtual machine from a custom image using an ARM template
- URL: https://codeisahighway.com/how-to-create-a-virtual-machine-from-a-custom-image-using-an-arm-template/
- Published: 2015-09-11T03:01:54.000Z
- Updated: 2026-08-10T07:12:31.000Z
- Author: Stephane Lapointe
- Tags: Microsoft Azure, Virtual Machines, Azure Resource Manager, ARM, HowTo, ARM Template, #Import 2023-07-11 16:44, #Import 2026-09-04 10:31, #Import 2026-09-04 13:56

Wish you could deploy your own virtual machines from a custom image (specialized or generalized) using an Azure Resource Manager template? He're is how to do it...

## Prerequisites

- A custom VM image captured using the Azure Resource Manager API (more detail just below)

## Things to know before you get started

Here is few items you need to be aware before you continue...

### The custom VM image need to have been captured using a v2 Compute resource provider

VM images captured from a v1 Compute resource provider (Microsoft.ClassicCompute) cannot be used to create virtual machines using a v2 Compute resource provider (Microsoft.Compute) or the other way around.

If you need a new image after reading this, see *Step by Step: How to capture your own custom virtual machine image under Azure Resource Manager API* in the [References](#References) section.

### The Custom VM image need to reside in the same storage account as your virtual machine at creation time

Another important limitation is that the image need to be present at creation time in the very same storage account that will host your virtual machine's vhd. *The custom VM image can be deleted afterward without problems.*

It's not that big thing if you are using a standard storage account. On the other hand, if you want your virtual machine to run on premium storage, leaving that P10 (or bigger) custom VM image around, doing nothing, will cost you the same money per month as any other premium storage disk. For more details, see *Azure Storage Pricing* link in the [References](#References) section.

## Creating a virtual machine from the custom image

Now the fun part... In a basic example, you'll see how to reference your custom image in the VM creation process using an ARM template.

*We assume the storage account already exists since you are supposed to have your custom VM image already in it at this point.*

When you created your custom VM image there was a json file generated at the same time. In the storageProfile node, take a look at the image URI and save this information somewhere, we'll need it later.

```language-json
{
  "storageProfile": {
    "osDisk": {
      "osType": "Windows",
      "name": "template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd",
      "createOption": "FromImage",
      "image": {
        "uri": "http://vmcapturetestdemo.blob.core.windows.net/system/Microsoft.Compute/Images/mytemplates/template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd"
      },
      "vhd": {
        "uri": "http://vmcapturetestdemo.blob.core.windows.net/vmcontainerd1bd9914-b1e8-44a0-a06c-663eedda8d1a/osDisk.d1bd9914-b1e8-44a0-a06c-663eedda8d1a.vhd"
      },
      "caching": "ReadWrite"
    }
  }
}

```

The very first thing to do is to create an ARM template. There is plenty of way to do this. If you need full control over your template, you can create an *Azure Resource Group project* using the Azure SDK in Visual Studio. If you want to go this way I created an article a while ago that can help you get started named *How to create and deploy a development machine on Azure using Azure Resource Manager template in Visual Studio* (see the [References](#References) section). If you intend to do this, take the `storageProfile` node from your generated json file and replace that very same section in the template in Visual Studio. Be sure to adjust the image URI and vhd URI properties if needed.

There is a basic template that already exist for this in the *Azure quickstart templates* repo on GitHub and we'll use it.

Browse to the template page [101-vm-from-user-image template](https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image?ref=codeisahighway.com) and take a minute to check the readme section. This template creates a VM from a custom image, a virtual network, a public IP and a NIC.

![101-vm-from-user-image template](https://codeisahighway.com/content/images/2015/09/TemplateOverview.png)

Before you click the *Deploy to Azure* button, we'll take a look at the template parameters. There is more parameters than the three listed below, we'll only concentrate on those that are related to the custom image.

## Custom VM image related parameters in the template

```language-json
"parameters": {
    "userImageStorageAccountName": {
      "type": "string",
      "metadata": {
        "description": "This is the name of the your storage account"
      }
    },
    "userImageStorageContainerName": {
      "type": "string",
      "metadata": {
        "description": "This is the name of the container in your storage account"
      }
    },
    "userImageVhdName": {
      "type": "string",
      "metadata": {
        "description": "This is the name of the your customized VHD"
      }
    }
  }

```

### userImageStorageAccountName

Correspond to the storage account name where your vhd will be created but also where your custom image is located.

Ex: In our image URI, it correspond to the subdomain `vmcapturetestdemo` in the host *blob.core.windows.net*  
http://vmcapturetestdemo.blob.core.windows.net/system/Microsoft.Compute/Images/mytemplates/template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd

### userImageStorageContainerName

Correspond to the storage account's container.

Ex: In our image URI, it correspond to `system`. It is the first segment in the path.  
http://vmcapturetestdemo.blob.core.windows.net/system/Microsoft.Compute/Images/mytemplates/template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd

### userImageVhdName

Correspond to the blob filename.

Ex: In our image URI, it correspond to `Microsoft.Compute/Images/mytemplates/template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd`. It is all the remaining path after the container name.  
http://vmcapturetestdemo.blob.core.windows.net/system/Microsoft.Compute/Images/mytemplates/template-osDisk.187d9455-535b-48b4-b10d-8370ec9bad42.vhd

## Time to deploy

You can now click the deploy button from the template page you just opened.  
![Deploy To Azure button](https://codeisahighway.com/content/images/2015/09/DeployToAzureButton.png)

You will be redirected to the Azure preview portal on the *Parameters* section of a *Custom deployment* blade. Fill the parameters values as needed and click the OK button.

![Custom Deployment Parameters](https://codeisahighway.com/content/images/2015/09/PortalTemplateParameters.png)

If you need more information about a parameter you can click the little exclamation mark near the parameter name in the portal, ex:

![Template parameter description](https://codeisahighway.com/content/images/2015/09/PortalTemplateParameterDescription.png)

You can change your subscription if needed.

Now for the Resource Group, choose your storage account's Resource Group.

![Custom Deployment Resource Group selection](https://codeisahighway.com/content/images/2015/09/PortalTemplateSelectResourceGroup.png)

You can ignore *Resource Group location* since you are not creating a new one.

Click the *Legal terms* section, read the Legal terms and click the **Buy** button when ready.

![Custom Deployment Legal terms](https://codeisahighway.com/content/images/2015/09/PortalTemplateLegalTerms.png)

As a last step, click the **Create** button to start the template deployment.

![Custom Deployment Ready to deploy template](https://codeisahighway.com/content/images/2015/09/PortalTemplateReadyToCreate.png)

If all goes well you'll have a new virtual machine named *MyVm* for you to play with.

Have fun!

## References

- [Step by Step: How to capture your own custom virtual machine image under Azure Resource Manager API](https://codeisahighway.com/how-to-capture-your-own-custom-virtual-machine-image-under-azure-resource-manager-api)
- [Azure Storage Pricing](http://azure.microsoft.com/en-us/pricing/details/storage/?ref=codeisahighway.com)
- [Azure Resource Manager QuickStart Templates](https://github.com/Azure/azure-quickstart-templates?ref=codeisahighway.com)
- [How to create and deploy a development machine on Azure using Azure Resource Manager template in Visual Studio](https://codeisahighway.com/how-to-create-and-deploy-a-development-machine-on-azure-using-azure-resource-manager-template-in-visual-studio)