How to create a Compute Gallery and Capture VM Images.
Tags: webdev, azure, hagital, aws
Published: 2023-08-30 16:11:36

Azure Compute Gallery is a service in Microsoft Azure that allows you to create, manage, and share custom virtual machine (VM) images with ease. This write-up will guide you through the process of creating an Azure Compute Gallery step by step.

PREREQUISITE
1). Get a PC with online access.
2). Microsoft Azure account - If you don't have an Azure paid subscription, create a Free Account before you begin.

Search for "Azure Compute Galleries" in the Azure portal and click on Create.

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

_Fill in the required details:_
**Subscription:** Select your Azure subscription.
**Resource group:** Choose the resource group you created earlier or create a new one.
**Gallery name:** Choose a unique name for your gallery.
**Region:** Choose the Azure region where you want to deploy the gallery.
_Click the 'Next + Sharing method' button._

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

**Sharing method:** On the sharing method page, leave it on default which is the Role based access control (RBAC). Role-Based Access Control (RBAC) in Azure is a security mechanism that regulates access to resources. It employs roles with specific permissions, which are assigned to users, groups, or applications through role assignments. RBAC functions across various levels like management groups, subscriptions, resource groups, and resources themselves. It prioritizes least privilege and can be managed through the Azure Portal, PowerShell, CLI, or templates. Regular audits are important for maintaining security and compliance.

Click the 'Next: Tag' button.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8i8v48s8ezot4gem92r.png)

You can create a Tag, or you can assign tags based on your preference. Click the Review + create button to review your settings. Make sure everything is configured correctly.

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

Finally, click the Create button to create the gallery once validation is passed.

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

Once your deployment is completed, you have successfully created an Azure Compute Gallery. Click on the 'Go to resource' button to access your newly deployed compute gallery.

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

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


**Step 2: Capturing an Azure Virtual Machine Image to Compute Gallery**

**Prepare the Virtual Machine**
Before capturing the VM image, ensure that your VM is in a suitable state:

**Stop the VM:** It's recommended to stop the VM to ensure a consistent state during the capture process. You can stop it from the Azure Portal.

**Deallocate the VM:** If you are capturing an image from a VM that is not in a deallocated state, you can deallocate it from the Azure Portal to avoid additional charges. Azure deallocates VM automatically during this process if you don't do it manually.

**Step 3: Capture the VM Image**
Go to the VM image you want to replicate and click on **capture**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xwzinxgfkg6abpka0yk.png)
In the Azure Portal, navigate to the Virtual machines section.

**Provide the required information:
Resource group:**
**Share image to Azure compute gallery:** Select Yes, share it to a gallery as a VM image version.
**Image target gallery:** Select the Azure Compute Gallery where you want to store this image. I selected DemoACG which I created earlier in the resource group-kenACGRG.

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

**Operating system state:** choose one out of the two options Generalized and Specialized, In the context of Azure Virtual Machine (VM) image capture, "Generalized" and "Specialized" refer to two different states of the VM:

**Generalized:** When a VM is in a "Generalized" state, it has been prepared to be a reusable image. In this state, any specific configuration and unique information, such as the computer name, have been removed or generalized. This process typically involves running the "Sysprep" tool on a Windows VM or executing similar steps on a Linux VM. After this, the VM is often shut down. Generalized VMs are suitable for creating custom images that can be used to deploy multiple VM instances with the same base configuration.

**Specialized:** A VM in a "Specialized" state is one that hasn't undergone the generalization process. It's in a specific, unique configuration with potentially personalized settings and data. Specialized VMs are typically used for ongoing production purposes and are not intended to be used as a template for creating new VM instances.

When capturing an image of an Azure VM, it's essential to generalize the VM first if you want to create a reusable image. Specialized VMs, on the other hand, are kept as-is for ongoing operations. Understanding and appropriately managing the state of your VMs is crucial for efficient image management in Azure. Here we picked Specialized since we are having an ongoing operation and want to have the ease of not authenticating when we scale.

**Target VM image definition:** Click on 'Create New'.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ieyclrriva2ayyll4b3m.png)

**VM Image definition name:** Choose a unique name for your captured image. Leave other fields as default and click 'Ok'.

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

**Image version:** Provide a version number and an optional description for this image version. Versioning in VM image capture is the practice of maintaining multiple snapshots or versions of a virtual machine image in Azure. Instead of overwriting the original image, each change or update creates a new version. This allows for flexible deployment, enabling you to choose specific image versions when creating VM instances. It's essential for managing changes and ensuring the ability to revert to known, stable configurations when needed.

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

**Replication:** This refers to the process of duplicating the VM's virtual hard disk (VHD) to create a copy of the VM's entire state, including the operating system, installed software, and data. Here we are replicating just one image of our VM and our storage option is Zone Redundant. Configure the target region(s) where this image version will be available.

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

Click Tag to add Tag then click 'Review + create' to review your settings. Ensure that everything is configured correctly.

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

Verify your settings and click create.

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

Wait till the VM image is fully deployed

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

Now fully deployed, go to resource.

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

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

Windows virtual machine Image now successfully created in your compute gallery

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

Finally, I would like us to verify if the VM image created in our compute gallery will be made available when creating a virtual machine scale set **VMSS**.

Click on kenVMimg (DemoACG/kenVMimg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mr278pia7lbg7fcsuys7.png)

Click Create VMSS

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

On the basic tab, scroll down to image under instance details, you will discover that the Imgage we created earlier is amongst other images.

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

**Conclusion**
You've successfully captured an image from an Azure virtual machine and stored it in an Azure Compute Gallery. This process allows you to maintain a library of custom VM images, making it easier to provision standardized virtual machines for your Azure deployments. Remember to update your gallery with new versions as your VM images evolve over time.

_Thank you for reading my article till the end. I hope you learned something special today. If you enjoyed this article, then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box._