Generalizing Virtual Machines In Azure

Introduction

 
In this article, we will learn how to generalize virtual machines in Azure.
 
Generalization is process of creating custom images on virtual machines.
 
The image will have all the software configuration of the virtual machine which is used to create the  image. Using this base image we can create new virtual machines which will have default software configuration as per the virtual machine image.
 
Prerequisites
  • Microsoft free account and Azure Credits.
  • Basic knowledge of using Azure Services and understanding of Virtual Machines in general.
In this article, we will cover the following topics:
  • Create windows virtual machine and configure IIS services on the same 
  • Create Custom image of the Virtual Machine 
  • Create new Virtual Machine with custom image and base software configuration.

Implementation

 
When we create an image of a virtual machine we cannot use the original virtual machine.We can only use the image to create new virtual machines.
 
Generalization is a destructive process.
 
Step 1 - Create and configure windows VM
 
Use this link to create a free Microsoft account.
 
The account creation will require you to provide your credit/debit card details for validation. The first month of the Azure Subscription is free and you will not be automatically charged unless you upgrade your account manually.
 
Once the account is created successfully, we can log into the Azure Portal using this link.
 
The home screen will display all recently used Azure resources.
 
Under Virtual machines, click add new VM
 
Generalizing Virtual Machines In Azure
 
Resource Group is a logical grouping of resources.
 
Any Azure service is a resource.
 
The user can create a new resource group and select Windows service 2019 Image for our VM configuration.
 
Configure admin user and specify log on password.
 
We can select the VM CPU Size and RAM Size and our cost will vary as per the selected size.
 

Configure Disk type and Size

 
This is the OS Disk. Additionally, we can add a storage disk.
 
Generalizing Virtual Machines In Azure
 
Configure the networking tab with the default setting and we are good to go,
 
Review Final changes and click on create. Our VM machine is deployed and ready for use in less than 5 min.
 

Remotely access VM from our local machine

 
Navigate to VM resource and click on connect and select RDP
 
Generalizing Virtual Machines In Azure
 
Download the RDP file and using the admin account, log on to your VM.
 
Download and accept the security certificate,
 

Install IIS services on VM

 
Navigate to server Dashboard and click on add roles and features.
 
Select the IIS service and complete the setup.
 
Generalizing Virtual Machines In Azure
 
Navigate to the IE browser on your server and type localhost and you could see the IIS service up and running.
 
Navigate to your local machine and type Public IP address of your server and you could notice you would not be able to reach to IIS service.
 
Web server listens on port 80.
 
We need to add inbound port rule under the networking tab and enable port 80
 
Generalizing Virtual Machines In Azure
 
Step 2 - Create custom Image of Virtual Machine 
 
I have created 2 virtual machines, both have  IIS services enabled
 
Generalizing Virtual Machines In Azure
 
Log on to the VIrtual Machine for which you would need to create an image using RDP and navigate to C:\Windows\System32\Sysprep folder.
 
Generalizing Virtual Machines In Azure
 
Click on generate and in showdown options select shutdown.
 
Once the process is complete we would automicaticlly log out from VM session and will not be able to access the VM.
 
Navigate to https://shell.azure.com/ using powershell option and stop the VM using below command 
 
Stop-AzVM -ResourceGroupName "Enter name here' -Name "VM name" -Force
 
Once the VM is stopped we can no generate Image using below option 
 
Generalizing Virtual Machines In Azure
 
Navigate to the virtual machine and select capture.
 
Select the name for our image and click create.
 
Once you get the noticaiton image created succesfully navigate to search and enter your image name.
 
Generalizing Virtual Machines In Azure
 
We have succesfully created the image.
 
Step 3 - Create new virtual machine with custom image and base software configuration.
 
Now click on create VM from image.
 
Follow all details in step 1 and we will able to create a new virtual machinewith default software configuration as base Image.
 
Type the public IP adress and we can see the IIS services running on a new virtual machine.
 
We will still need to enable port 80 on new VM to be able to acess the public network.
 

Summary

 
In this article, we have learned how to generalize virtual machine in Azure.
 
Thanks a lot for reading. I hope you liked this article. Please share your valuable suggestions and feedback. Write in the comment box in case you have any questions. Have a good day!