DEV Community

Cover image for How to create a Compute Gallery and Capture VM Images.
Kehinde Oloye
Kehinde Oloye

Posted on

How to create a Compute Gallery and Capture VM Images.

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

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

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

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

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

Image description

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

Image description

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
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

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

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

Image description

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

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

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

Image description

Verify your settings and click create.

Image description

Wait till the VM image is fully deployed

Image description

Now fully deployed, go to resource.

Image description

Image description

Windows virtual machine Image now successfully created in your compute gallery

Image description

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

Click Create VMSS

Image description

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

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.

Top comments (0)