HOW TO CAPTURE A VM IMAGE AND USE IT TO CREATE A NEW VM USING AZURE PORTAL
Published: 2023-06-21 19:57:54

**This article is a straightforward guide on how to successfully capture a customized VM image, store in in the Compute gallery. The use the image to replicate similar VMs as the need arise in various regions**

**Prerequisites**

1. Azure account
2. Azure compute gallery
3. A running virtual machine

**HERE ARE THE STEPS**

**1. Capture and store an image**

- Go to the search bar at the top of the **Azure portal** and search for **Virtual machines**. Click on the virtual machine and select the virtual machine you want to capture the image and click on it. This opens the overview page of the selected machine.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ynn3yx4vhbzui9x0cys.png)

- Click on the **Capture** button at the top of the overview page. This takes you to the **Create an image** page. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvdrl3xv4ya8edl3tfbi.PNG)

- Under **Basic** you have **Project details** which has **Subscription** and **Resource group** already provided from the configuration of the VM. You can change the resource group, if you wish to.

- Under **Instance details**, the Region is provided by default. Select radio button **Yes** for **Share image to Azure compute gallery**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yqqg70q6mimofn1i6if.PNG)

You may check the box **Automatically delete this virtual machine after creating the image** if you no longer have any use for the Virtual Machine thereafter.

- Under **Gallery details**, select your preferred gallery to save the image in **Target Azure compute gallery** or click on Create new if you have no gallery. Then on **Operating system state**, choose the **Generalized** option if you do not want to use the VM afterwards or the **Specialized** if reverse is the case.
Click on **Create new** for **Target VM image definition**, this will open a tab, where you can provide the details.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzcdkrj7u3liu0mc6a1l.png)

Go ahead and provide the required details. The name of the image, most configurations here are already provided by default. Click **OK** button and continue with the **Create an image** page.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rajk02mzr7teqnx9yv63.PNG)

- Enter the **Version number**, following the format provided eg: **0.0.1**.

- Under **Replication**, enter the number of replicas you want to create, the **Target regions**, **Target region replica count ** is the number of replicas to be created in that region, then select the storage type. All these choices have cost implications.

- Then click on **Review + create** 
When you see the notification **Validation passed**, Click on the **Create** button to commence the process.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jf4m5d0bb73a7dxy7vtg.PNG)

When the deployment is completed, this page will display. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cvq30ovfvt41wqv3ue3.PNG)

- Click on **Go to resource**
This will take you to the **Overview** page of the image you just captured.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/032r43toyxbv3bxwilp9.PNG)


**2. Create a VM from an image**

- 
Go to the **Overview page** of the image in the compute gallery by clicking on the image.

- Then click on the **Create VM** button


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jnped6qebmsh361y1uh.PNG)

This will take you to the **Create a virtual machine** page. 

- Under **Project detail**, you select **Subscription** and **Resource group**

- Under **Instance details**, you provide the **Virtual machine name**, **Region**, and change the security configuration if you wish or leave the one that came with the image. The **Image** is automatically provided. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11468e0uktxas3ssgqam.PNG)
 
Going further down the page, you select the radio button **Allow selected ports** for **Public inbound ports**. You can also select your desired ports for **Select inbound ports**.

- Under **Licensing**, select the **License type**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkpk9v6o6l2lqoopvojn.PNG)

- Click the **Review + create** button.
This will kickstart the validation process. The validation ends with the notification **Validation passed**.

- Then click on the **Create** button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tp6evspkcbzoerlp2rwr.PNG)

Deployment in progress

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppcri6rrjqvr4e960xdg.PNG)

Deployment is complete. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gza7hs21defadso18s4.PNG)

- Click on **Go to resource**
This will take you to the **Overview page** of the new VM you just created from the image in your gallery.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omybkx2xa3ikh02xc3jm.PNG)

- 
Go to the search bar at the top of the Azure portal and search for and select **Virtual Machines**. Then view both machines, the original and the second one you created from the image captured.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqq2sy4eokcfowqicnjb.PNG)

You will notice that the original VM has been deallocated (stopped). You can go ahead and restart it to have both machines running.

Hope this article was able to guide you accomplish your task successfully.