How to Capture the Image of a Virtual Machine
Tags: capture, capturetheimage, virtualmachine, image
Published: 2023-07-01 09:59:45

Hi! I'm here again with some little tips on capturing the Image of a virtual machine. You may wonder, why do I need to do this? Well, it is a good idea to have something you can refer to or make use of in future in case you need to know something about your VM or use your virtual machine again from its fresh state it was when you created and deployed it.

More importantly, when you created an image of a virtual machine, it can be used to create multiple VMs.
In Azure, when the image of a virtual machine is captured, the virtual machine will be temporarily stopped. This to achieve consistency of the data and prevent encountering any problem while creating the image. This is crucial because capturing an image requires a point-in-time snapshot of the virtual machine's disk.   
Azure Compute Gallery is an Azure service used for storing images of VMs captured. From the gallery you can share your images and you can replicate them to multiple regions. 
Yes, that's the gist.

In my earlier post, [Adding Data Disk to a Virtual Machine](https://dev.to/yemmyoye/adding-data-disk-to-a-virtual-machine-257c) I created a virtual machine, connected to it, installed a web server role and added a data disk. You can click on the link to see how this was done.

Now let's go through some simple steps to capture the image of a virtual machine. I want to capture the image of the Virtual machine **Abiksvm** created in the post referred to above.

**Step 1**
Go to Azure Portal and click on the virtual machine to be captured


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

Ascertain the Status of the virtual machine that it is running

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

**Step 2**
Go back to the Azure portal home page and select Azure Compute Gallery

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

Click on 'Create'

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

I will complete the Project details and Instance details as follows:
Subscription: Azure Pass Sponsorship
Resource group: UniRg
Gallery name: Abiksgallery
Region: East US


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

Click on Review and Create

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

Click on Create

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

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

Go to Resource

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

The Compute Gallery for storing the VM image we want to capture has been created.

**Step 3**
Lets go back to the virtual machine we want to capture
Click on Capture

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

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

Select the Compute Gallery already created, **Abiksgallery**
And name the VM Image definition. I will name is **Abiksimage**


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

Input the Version number **0.0.1**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zxz52lfmnm0ui0qovhn.png)
The Default replica count is 2.I will leave it at 2.You can input any number you desired.
I will select the two regions where I want to replicate the image captured: **West US 2 and UK South**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zfwnw44snr4sfhpu232.png)
Click on Review and Create

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhylr2y1gqfiqhepucif.png)
Click on Create
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76g003t7a6ouy8dx33ca.png)

When you click on 'Create', the VM has to be stopped before the snapshot will be taken as seen in the picture above.

Then, the Virtual machine will also be generalised. Generalizing is a process that removes machine and user specific information from the VM. This also has to take place before the image of the VM is taken.

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


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

When the deployment is complete, that means that the image has been taken. Lets click on Go to Resource and see for ourselves.


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

Also, go to the Portal's home page and Click on the gallery, Abiksgallery


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

Viola! The image has been successfully captured and stored in the gallery.

Simple. Not so?

What is your view about this? Please leave your comments below