Unlock the Magic: Mastering Azure's Compute Gallery and VM Image Creation
Tags: cloudcomputing, azure, virtualmachine, cloud
Published: 2023-08-26 01:26:11

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.

Prerequisites
Before you begin, ensure that you have the following prerequisites in place:

Azure Subscription: You need an active Azure subscription. If you don't have one, you can sign up for a free trial at Azure Portal.

Azure Resource Group: Create an Azure Resource Group to organize and manage your gallery resources.

Virtual Machine: An existing Azure [virtual machine](https://dev.to/princemaxi/creating-azure-virtual-machine-a-step-by-step-guide-for-beginners-2j0i) that you want to capture an image from.

## Step 1: Create a Gallery

- Log in to the Azure Portal.

In the left-hand menu, click on Create a resource.

![Create a resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tkpdq2wevg0p6r4ezadi.png)

- In the search bar, type "Compute Gallery" and select it from the search results.

![Compute Gallery](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nrx2pvp52otwvxbxi1b5.png)

- Click the Create button.

![Create button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fceiardxv416yrdqqrz3.png)

- Fill in the required details:

1. **Subscription:** Select your Azure subscription.

![Azure subscription](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l4bk7pa2wqczm1an2wq.png)

2. **Resource group:** Choose the resource group you created earlier.
![Resource group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8c2u1mbv8zuf1as7ofx.png)
3. **Gallery name:** Choose a unique name for your gallery.

![Gallery name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqe3co89v38bd8xfepgf.png)

4. **Region:** Choose the Azure region where you want to deploy the gallery.

![Region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2uye7n5jcxhvxdekxwd.png)

- Click the 'Next + Sharing method' button.

![Next + Sharing method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lj5wgyke7ih67vaxbocy.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._

![Sharing method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qo97njeki5m65n42md8u.png).

- Click the 'Next: Tag' button.

![Next: Tag](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a85haahlshrlir7aukof.png)

Leave the Tags on default or 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.

![Next: Tag](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/crvd5a6q3qs9uuhb1ugs.png)

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

![click the Create button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3hxmhou3ma8hn9pjdl0.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.

![Go to resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxnofyguel6dhy5vs6nl.png)

![Go to resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/44jnbngzn4nwuh1xxqpr.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

In the Azure Portal, navigate to the Virtual machines section.

Select the VM you want to capture an image from.

![VM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg0s6yvjipu72o1litut.png)

In the VM's overview page, under Settings, click on Capture. This action initiates the image capture process.

![click on Capture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwdqy9sx0ycd7aoumk15.png)

**Provide the required information:**

- **Image target gallery:** Select the Azure Compute Gallery where you want to store this image.

![Image target gallery](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4g3d6e0je0nxjnm3sxl.png)

- **Operating system state:** choose one out of the two option 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:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k2lt3h9fsbrzqvyyrvbv.png)

- **Target VM image definition:** Click on 'Create New'.

![Target VM image definition:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnu4j0xkkq753nometc9.png)

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

![VM Image definition name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lstsv8a1g6bjom2qh83u.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 version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6m1gs9dvlnsuh8d5gfq.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 1 image of our VM and our storage option is Zone Redundant. Configure the target region(s) where this image version will be available.
 
![Replication](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6v6912wegh4q6d32rv0.png)

- Click 'Review + create' to review your settings. Ensure that everything is configured correctly.

![Review + create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njq8wgye4xxp5f3ipq0x.png)

- Finally, click 'Create' to start the image capture process. The VM will be deallocated, and Azure will capture an image of it.

![Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xkeisamkhkb4hzyws70.png)

Once the process is complete, the captured image will be stored in your specified Azure Compute Gallery. Once deployment is complete you can now 'Go to resource'.

![Go to resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nd8nw2ysjkb0mwkehcjp.png)

Tadaa! 🎉This is our captured VM Image in our compute gallery.

![Tadaa!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8vzky3k4t21kodzkpj0.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.