How To Create Virtual Machine Image In Azure

Let us learn in what cases, we use VM images to create a new one and how it can be helpful for us. So, let’s start our journey.
 

Scenario

 
In the corporate sector, most of the time, we’re working on Virtual Machines. And, to set up and configure a virtual machine with required relevant software installation and VM plus application configuration is not an easy task. So, to automate the things, we use VM image to create more VM images for the future.
 
Step 1
 
Open Azure Portal and create Virtual Machine. I’ve selected the VM size as B1ms because it is designed for development and testing. So, I’m creating one VM of B1ms.
 
How To Create Virtual Machine Image In Azure
 
After clicking on "Review + create", I’ve created my VM.
 
Step 2
 
Open your created VM and open its RDP session.
 
How To Create Virtual Machine Image In Azure
 
Click on "Connect" and "Download RDP File".
 
Step 3
 
Confirm the certificate and enter your credentials. Your environment will be ready.
 
How To Create Virtual Machine Image In Azure
 
Step 4
 
Open File Explorer and go to this path.
 
%windir%\system32\sysprep
 
And now, run sysprep.exe
 
How To Create Virtual Machine Image In Azure
 
This is what you get when you run sysprep.exe.
 
How To Create Virtual Machine Image In Azure
 
Select these options in your dropdown and mark the checkbox of Generalize and hit OK.
 
Now, sysprep will start its working and after completing its process, it will automatically make the VM shut down.
 
Point
 
Windows Azure VM uses sysprep to make it generalize to make the VM images. sysprep removes all the personal and security information of VM and generalize it for VM image.
 
Step 5
 
Come back to the portal and click on "Capture".
 
How To Create Virtual Machine Image In Azure
 
After clicking on Capture, a new blade will show on the screen to create an image.
 
How To Create Virtual Machine Image In Azure
 
Check the checkbox of "Automatically delete this VM after creating image". It is because now we can’t run this VM. It becomes in the deallocated state when we create its image. And in the last textbox, we need to write the VM name from where we’re making the VM image; just for confirmation. Now at the end; hit Create button.
 
Step 6
 
Now, open your resource group and here you find you’ve created the Virtual Machine image.
 
How To Create Virtual Machine Image In Azure
 
Note
When we create something in Azure portal, it becomes the part of our account, our subscription and our cloud drive directory. So, don’t confuse it with Azure VM Marketplace images; and don’t expect that this VM image will show in the Azure VM Marketplace images section. It will only be available within your account, subscription directory. So, you can automate and create the same VM images from this image.
 
Step 7
 
Now you want to create a new VM from our created custom VM. So,
 
Create a resource > Search (“Windows Server”) > Create
 
How To Create Virtual Machine Image In Azure
 
And this time enter your credentials and click on Browse all public and private images
 
How To Create Virtual Machine Image In Azure
 
And this time click on My Items and select your VM.
 
How To Create Virtual Machine Image In Azure
 
And this is how you can create new VM from your own custom VM.
 
How To Create Virtual Machine Image In Azure
 
Now, you can see the Region is disabled. It is because there are a few configurations which we have already done in our image. So, there are a few things which we don’t need to do again and again. Every time now when you generate VM from your custom image; it will be deployed in the same region where you deployed your VM image. But we can change the size of the VM.
 
Ok so fill the complete the form and deploy the VM and open the RDP Port.
 
Step 8
 
Ok so now new VM has been deployed. And now let’s open its RDP with the same method which we have already discussed above.
 
How To Create Virtual Machine Image In Azure
 
And now when we open the RDP file and enter username, password; we'll see that our environment will be ready to use.
 
How To Create Virtual Machine Image In Azure
 

Portal vs Azure CLI vs PowerShell

 
To generate the resources in Azure, we have 3 different ways to create resources.
 
Only the difference is among these mediums; through portal, we can do everything manually one by one which is really very time consuming and annoying that’s why we use Azure CLI or PowerShell for automation. Through Azure CLI and PowerShell we create the resources through scripts and resources are acquired very quickly. In our upcoming articles; we’ll also cover how to use Azure CLI and PowerShell and how we can create the multiple VMs from 1 script.
 

Conclusion

 
In this article, we’ve learned how to generalize the Windows Virtual Machine through Sysprep; we’ve also learned how to capture the VM image and how we create the new VMs from custom image.


Similar Articles