How to Easily Clone a Virtual Machine in Azure

How to Easily Clone a Virtual Machine in Azure

Preface:

In this article, we are going to demonstrate how to create a VM clone both portal and PowerShell script way. Using this guide, you can choose the portal or script to clone an Azure virtual machine based on your requirement and what you are comfortable with. The original virtual machine has been cloned by creating the Snapshot of OS disk and Data Disk using the portal.

The snapshots have been used to create managed disks and virtual machines created by attaching the managed disks. In the first part of the demonstration, we have created a virtual machine using the portal, and in the second part demonstration, we have created the virtual machine using the script and running it on the cloud shell. This tutorial is created to show the audience how it relates portal and PowerShell script to create the VMs, and you can use any one of these two methods to create VM. The portal method will be quick and easy, but PowerShell script would be granular, and you can automate the VM cloning.

The following topics discussed in this article; The parameters given in the demonstration are just examples; you can replace the parameters which is relevant to your environment and create cloned VMs. We start the article with VM cloning using the portal, and, in the end, we are going to discuss how to use the script to accomplish the same.

  1. Cloning VM using Azure Portal
  2. Cloning VM using Cloud Shell (PowerShell)

We have started this article with VM cloning using the portal, and, in the end, we are going to discuss how to use the script to accomplish the same.

Cloning VM using Azure Portal

Log in to https://portal.azure.com and go to the VM, which needs to be cloned. From the dashboard, select Virtual machines and the VM name to go to the VM object.

On the VM object, you can see the resource name, VM size, and Geo-Location, and so on. From this VM, we are going to take a snapshot of the OS and Data disks. So we are interested in navigating to Disks from the left navigation.

Create snapshot of OS Disk

Graphical user interface, application

Description automatically generated

This parent VM is a Microsoft SQL Server 2017 on Windows Server 2019. From the parent, on the disks view we see two disks. one disk is the Operating system disk, called OS disk, and another disk is the Data disk where the databases and its logs are stored. Click on each disk one by one and create a Snapshot of the disks.

Graphical user interface, application

Description automatically generated

From the previous image step, we selected the OS disk, and we are going to create a Snapshot of the OS disk first and, subsequently, the Data disk. Click on OS disk and get the OS disk management properties.

Graphical user interface, application

Description automatically generated

Click Create Snapshot to create an OS disk snapshot.

On the “create a snapshot window,” we will provide the details such as resource group name, snapshot name, and so on. It is good to create the clone VM in a separate resource group, away from where the original VM exists. Once the cloned VM purpose is over, delete that resource group to remove all the related resources to make it clean tidy.

Once a resource group has been created or selected based on your scenario, type Snapshot name, and select storage type. As this is a demo, I have chosen Standard HDD.

Graphical user interface, application

Description automatically generated

Creating OS snapshot will be started once you confirm the validation check is passed and Create Snapshot clicked.

Graphical user interface, text, application

Description automatically generated

On the next screen, the deployment of the resource is complete. In this case, the creating of OS disk snapshot.

Graphical user interface, text, application, email

Description automatically generated

Create a snapshot of Data Disk

As the OS disk snapshot is created, we are making the Snapshot of the data disk, go to the Disks navigation on the VM management page and click on data disk as shown in the image below.

Click Create Snapshot, this time we are create data disk snapshot.

Graphical user interface, text, application, email

Description automatically generated

Select the same resource group you have created or selected in the previous Snapshot of OS disk snapshot and move on to naming the data disk snapshot. Same as the last occasion, we are choosing the Standard HDD as this is just a demonstration.

Click on the Review + Create button to move on to create the Snapshot.

Verify the validation passed by checking the green tick mark and click on Create.

Graphical user interface, application

Description automatically generated

The Data disk snapshot also completed, as shown in the image below, you would get the deployment completed message, so you have finished creating a Snapshot of OS disk and Data disk.

Graphical user interface, text, application, email

Description automatically generated

Create Managed Disks from Snapshots

The next step in this process is creating managed disks from the snapshots. Select the menu icon (three horizontal lines) on the Azure portal and click “Create Resource.”

Search the key word “Managed Disks”

Graphical user interface, application

Description automatically generated

You will see the managed disks option and click create from the bottom of it.

Graphical user interface, text, application, email

Description automatically generated

Select the Resource group where the snapshots exist.

Type a name for the managed disk for OS disk snapshot

Select Source type as Snapshot

Select the OS disk snapshot Source snapshot

The size of the managed disk must be the size of the original OS disk.

Graphical user interface, application

Description automatically generated

Once you enter the details, go to Create and Review and check for ‘validation passed’ indication and click Create.

Graphical user interface, application

Description automatically generated

You will get the message deployment is complete.

Clone a Virtual Machine

Same way, create a managed disk from the data disk snapshot.

Select the Resource group where the Snapshot exists.

Type a name for the managed disk for Data disk snapshot

Select Source type as Snapshot

Select the Data disk snapshot Source snapshot

The size of the managed disk must be the size of the Original Data disk.

Click Review + Create, and it will run validation.

Clone a Virtual Machine

You will get the ‘validation passed’ indication click create the Data managed disk.

Clone a Virtual Machine

Upon the completion of Data managed disk creation, you will get “Your deployment is complete” message.

Clone a Virtual Machine

Go to the Resource Group, where the managed disk created, and open the OS managed disk.

Create VM clone from Managed Disk

Clone a Virtual Machine

From the OS disk managed disk control, create VM as in the image below.

Clone a Virtual Machine

On the Create Virtual Machine window,

Select the Resource Group where managed disk exists

Type a name for the virtual machine

Select the OS disk managed disk as Image

Clone a Virtual Machine

Select the VM size from the drop-down list, recommended using the same size as the original VM.

Choose Windows Server as License type

And select the option whether you have a license or not. If you are not sure about this, click No.

Click Next Disks to go to disk selection.

Clone a Virtual Machine

On the Disks page, select attach on the data disk attach column.

Clone a Virtual Machine

On the existing disks list, select the data managed disk.

Graphical user interface, application

Description automatically generated

Once the data disk is selected, select read-only from the host caching drop-down.

Clone a Virtual Machine

On the virtual network page, select the Virtual network of the original VM or the one assigned on VPN, if point to site is configured to access the VMs.

Select the subnet that is matching to original VM.

And leave the public IP to create an IP.

Click Review + Create and wait for validation to complete.

Clone a Virtual Machine

Once you see the validation passed prompt click create to create the VM.

Clone a Virtual Machine

After the virtual machine’s deployment is complete, click Go to Resource to go to the VM management page.

Clone a Virtual Machine

You can now copy the public IP and login to the VM with the Original VM user account.

Clone a Virtual Machine

The RDP screen of Cloned is VM shown in the below screenshot.

Clone a Virtual Machine

Conclusion

In this demonstration, we have walked through the steps to create a cloned Virtual Machine using the Azure portal. We created Snapshot of OS disk and Data Disk and created managed disks from those snapshots. If your Virtual machine has only OS disk, ignore the data disk part while creating Snapshot and managed disk. Also, create the cloned VM only with OS disk. Most of the scenario requires data disks also to be cloned. So, having that in my intention, I have created a cloned VM with a Data disk. Your mileage may vary.

I hope the portal way of creating a cloned Virtual Machine is comprehensive. We will do the same type of cloning using a cloud shell (PowerShell). Click the link below to go to “Cloning VM using PowerShell” Cloning VM using PowerShell demonstration. I will be right with you in that article.

If you have any comments or feedback, please feel free to send it to me in the comments. I will reply to you when I get it.

How to Automate Cloning Virtual Machines in Azure using PowerShell – Part 2

2 Comments on "How to Easily Clone a Virtual Machine in Azure"

    Hi Kannan,

    I just have to upgrade a software which i am using for my web application in my vm. But i want to test that upgraded software version works well with our application.

    So, I want to clone the VM and upgrade the software and test thoroughly whether my application works well with new version.

    Just wondering will this cloning activity on a VM effects anything on the original VM?

    will that old VM still works without data loss? or will there any risks of cloning a vm?

    Thank you in advance
    Hari

Leave a Reply

Your email address will not be published. Required fields are marked *


*