Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Deploy an Azure VM from a generalized image in Azure RM portal

  • August 2, 2016
  • 13 min read
IT and Virtualization Consultant. Romain is specializing in Microsoft technologies such as Hyper-V, System Center, storage, networking, and MS Azure. He is a Microsoft MVP and MCSE in Server Infrastructure and Private Cloud.
IT and Virtualization Consultant. Romain is specializing in Microsoft technologies such as Hyper-V, System Center, storage, networking, and MS Azure. He is a Microsoft MVP and MCSE in Server Infrastructure and Private Cloud.

Microsoft Azure provides a way to deploy Azure VM from the Marketplace or from a generalized image. When you deploy the Azure VM from the Marketplace, no customization is deployed. You have to configure the operating system as your master. When you have several Azure VMs to deploy, the customization of each system can be time consuming. A lot of companies have a master or a baseline image in a VMDK for VMWare, in a VHD(X) for Hyper-V or in a WIM image. In this topic we will see how to create a generalized image from a single Azure VM and how to deploy Azure VM from this generalized image.

In the old portal (https://manage.windowsazure.com), all steps can be done from the GUI but also by using PowerShell. In the new portal (https://portal.azure.com), you have to use PowerShell because it is not yet integrated to the portal. In this topic, I will work from the new portal (AzureRM).

Resource group
Microsoft Azure provides a way to deploy Azure VM from the Marketplace or from a generalized image. When you deploy the Azure VM from the Marketplace, no customization is deployed. You have to configure the operating system as your master. When you have several Azure VMs to deploy, the customization of each system can be time consuming. A lot of companies have a master or a baseline image in a VMDK for VMWare, in a VHD(X) for Hyper-V or in a WIM image. In this topic we will see how to create a generalized image from a single Azure VM and how to deploy Azure VM from this generalized image.

In the old portal (https://manage.windowsazure.com), all steps can be done from the GUI but also by using PowerShell. In the new portal (https://portal.azure.com), you have to use PowerShell because it is not yet integrated to the portal. In this topic, I will work from the new portal (AzureRM).

Requirements

To follow this topic, you need some requirements:

  • I recommend you to install PowerShell v5 to import AzureRM PowerShell module
  • The AzureRM PowerShell module deployed (see below to install the module)
  • A deployed resource group
  • A deployed storage account from VM
  • A deployed virtual network with a subnet for VM
  • A deployed virtual machine to be generalized

If you have installed PowerShell v5, just run the following command to install the AzureRM module (in RunAs Administrator):

Install-Module AzureRM

In the below screenshot, you can see the deployed prerequisites in the TechCoffee resource group. The VM that will be generalized is called VM01.

Resource group

Make the customization and the sysprep

First of all, connect to the VM and make the customization. In my example, I create a folder c:\temp and I install .NET 3.5 feature:

Remote Desktop Connection

Once you have finished the customization, navigate to c:\windows\system32\sysprep and run sysprep.exe. Run the system preparation with the following settings:

Remote Desktop Connection

Export the sysprep VHD as template

Before running any PowerShell cmdlet on your Azure Subscription, you have to login and select the right Azure Subscription by using the following cmdlet:

First the VM must be stopped from the Azure perspective to be deallocated. The VM can be marked as generalized only on an Azure VM with deallocated state. When the below command will be executed, the VM state will be changed from Stopped to Stopped (Deallocated).

PowerShell command

Then you have to mark the VM as generalized. To make this operation, run the following command:

PowerShell command

Then you can save the VM image in the Storage Account by running the following command:

Regarding the parameters, the VM image will be stored in the following location:

https://.blob.core.windows.net/system/Microsoft.Compute/Images//-osDisk.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.vhd

6

Once the above command is executed, you can see your VM Image in the storage account.

VHDS folder

Deploy a VM from the image

To deploy the Azure VM from the image, you have also to use PowerShell:

Once the VM is deployed, I check again if the customization is set in the VM. As you can see in the below screenshot, the c:\temp folder is created and the .NET 3.5 feature is installed.

Remote Desktop Connection

Conclusion

In Microsoft Azure, it is possible to create VMs from the same image to deploy several VMs with the same baseline. However, in the new portal, you have to use PowerShell and not the GUI to generate the VM Image and to deploy VM from the image. But it is great for automation: you can create with a block of PowerShell a lot of Azure VM. If you like also deploy resources with JSON, you can specify the VM Image URL to deploy the Azure VM.

Found Romain’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!