Friday, February 08, 2019

Clone an Azure Virtual Machine using Snapshot option



Cloned VM using Snapshot





Clone an Azure VM


We already talked about an Azure Virtual Machine as well how to clone or create a managed image of an Azure Virtual Machine. Undoubtedly, in some precise scenario, it is essential to keep the exact configuration and details as exist in the original VM, here cloning fulfil the desired need.

We discussed that, the introduction of managed disks, makes quite feasible to simplify working with Azure Virtual Machines (VM) and Virtual Machine Scale Sets (VMSS). Now cloning or creating a managed image of an Azure VM is realistic and can be achieved by different ways, using – 
  • Generalized
  • Snapshot
  • Site Recovery


In one of the previous article, we already covered how to clone an Azure Virtual Machine using Generalized option. Generalization has been a preparation process of a virtual machine creating an image, through a tool called as Sysprep that located under system32/sysprep.

However, we have noticed that post execution of Sysprep utility over an Azure VM, that VM would be considered as generalized for capturing the image, the VM gets deallocated and you cannot login to it again. In other words, the process of generalizing a Virtual Machine is not reversible and here overcome the situation Snapshot appears.

In this post, we will talk and walk through how to clone an existing Azure VM and keep old VM in working condition, i.e. both VM would be in running mode.

Snapshot an Azure Virtual Machine


In fact, a snapshot is a full, read-only copy of a Virtual Hard Drive (VHD) belongs to an Azure Virtual machine. Purpose behind taking snapshot of an OS or a data disk VHD to use as a backup, or to troubleshoot Azure Virtual Machine (VM) issues.

Using snapshot, you can create an Azure Virtual Machine by creating a managed disk from the snapshot and then attaching the new managed disk as the OS disk. You can either use the Azure Portal or instead, achieve the same through PowerShell.

In this hand on an activity, you will create a cloned VM using following steps as – 
  • Validate existing VM
  • Create Snapshot from the VM
  • Create Managed Disk from the Snapshot
  • Create/Restore VM from the Managed Disk

Clone VM using Snapshot steps


Note: If you are moving ahead to use the snapshot to create a new VM, it is preferred that you quickly shut down the VM before taking a snapshot, to clear out any processes that are in progress.

Pre-requisites


Before proceeding, we need some pre-requisites to accomplish this Cloning VM task using Azure Portal.
  1. Azure subscription, if you don't have an account then sign up for a free Azure account - https://azure.microsoft.com/en-gb/free/
  2. An existing Windows Azure virtual machine (VM). 


STEP – 1: Validate an Azure Virtual Machine (VM)


It is essential to exist a Windows based Azure Virtual Machine (VM) to accomplish this demo task, login to Azure portal https://portal.azure.com/.

On the left Hub menu, click All resources and select the existing virtual machine, verify the VM is either running or stopped. 

Hub menu


STEP – 2: Move to attached Disk


Next, required to select the Disks option under the Settings section that will load the existing virtual machine disk blade. Here you can see the OS disk with brief details like size, storage type etc.

Disks blade


Now launch the OS disk blade by clicking the disk link, which appears in the OS disk list. Here you can see the brief details under the Overview section.

Disk overview

STEP – 3: Create a Snapshot


Post launches the OS disk blade, you can notice a + Create snapshot option exist on the menu tab, that is being used to create a snapshot. 

Create Snapshot


By clicking the + Create snapshot option, the Create snapshot blade will be loaded and essential to fill the following parameters to proceed further –
  • Name – The name of snapshot.
  • Subscription – The name of your Azure subscription, it would be either free, paid or specific subscription etc. 
  • Resource group – The name of the resource group used to organize related resources, you can either create a new resource or choose an existing one.
  • Location – The region where to store your snapshot information, it would be pre-selected by default.
  • Account Type – Select the Account type to use to store the snapshot. Go ahead with by default option as Standard HDD, unless you need the snapshot to be stored on a high-performing disk.


Create Snapshot blade

Once you are done with all required properties, proceed by clicking the Create button to create the snapshot. Promptly the process will be started and complete the creation of the snapshot, the same you can validate in the Notifications section.

STEP – 4: Validate the newly created Snapshot


In previous steps we have created the snapshot of the Azure Virtual Machine’s OS disk, now validate the snapshot. Go to Resource groups and here you can see a new entry of the newly created snapshot of the disk.

Along with this, you can notice the existing OS disk is also exist, that means we can still log on the old VM, will validate later.

Resource Group


By clicking the newly created snapshot, you can launch the Snapshot blade and verify the details like source disk, size, account type etc.

Snapshot Overview



Congratulations, snapshot has been created!! 😊

STEP – 5: Create a Managed Disk


Post creation of a snapshot, essential to create a Managed disk so that further you can create a virtual machine (VM) from the disk accordingly.

Move to Hub menu and click the All services, which will launch the All service blade. Here in the All services search box, enter disk that will display the list of available disks.

Disk Search


Select the Disks that you would like to use; most probably, the first option is preferable, which will load the Disks blade.

Disks blade list


Here you can see there is only one disk in the list, which is in fact the disk belongs to the old existing virtual machine. Now similar to this disk need to create a new managed disk, click the + Add button from the top menu that will load the Create managed disk where essential to fill the following parameters to proceed further – 
  • Name – The name of your new managed disk.
  • Subscription – The name of your Azure subscription, it would be either free, paid or specific subscription etc. 
  • Resource group – The name of the resource group used to organize related resources, you can either create a new resource or choose an existing one.
  • Location – The region where to store your storage account information, prefer to go with default-selected location.
  • Availability zone – Since this is demo task and it is not required so go with default-selected option as None.
  • Account Type – Select the Account type to use to store the snapshot. Go ahead with by default option as Standard HDD, unless you need the snapshot to be stored on a high-performing disk.
  • Source type – Here make sure the Snapshot should be selected.
  • Source snapshot – Select the created snapshot from the Source snapshot drop-down list.
  • Size – Size of disk as per need, by default it would be pre-populated based on a snapshot.

Create Managed disk

If required, make any other adjustments as needed and then proceed by clicking the Create button to create the managed disk. Quickly the process will be started and complete the creation of managed disk, the same you can validate in the Notifications section.

Along with it, if you reload the Disks blade, you can see this new entry in the disk list.

Disk blade lists

STEP – 6: Restore (Create) Virtual Machine from the Managed Disk


Now you have the managed disk VHD, next you can restore or better to say can create an Azure Virtual Machine (VM) using the same managed disk.

Time to load the Disks blade again, which list all available managed disks.

Managed disk list


You can notice the newly created managed disk, proceed ahead by clicking the same and load the Disk blade.

Managed Disk overview


In the Overview page, ensure that Disk state appears as Unattached. If it is not, you might need to either detach the disk from the source. Here from the top menu, click the + Create VM to proceed creating a new VM.

It will load the Create a virtual machine blade the time you click the + Create VM button inside the disk blade in the previous step.

Create Virtual Machine Basics


On the Basics tab, under Project Details, make sure the following parameters need to be filled up correctly as – 
  • Subscription – The name of your Azure subscription, it would be either free, paid or specific subscription etc. 
  • Resource group – The name of the resource group used to organize related resources, you can either create a new resource or choose an existing one.

STEP – 7: Provide specifics for Instance Details 


Under the Instance Details section of Create a virtual machine blade, provide following property details in the context of new VM as – 
  • Virtual machine name – The name new VM which is being created using the snapshot.
  • Region – Since this is based on image so most probably it would be pre-selected, go with the default-selection.
  • Availability options – Go ahead with by default selection as No infrastructure redundancy required.
  • Image – You can see the earlier creared managed disk is already pre-selected, go with this selection.


Create Virtual Machine Instance Details


If you create a fresh VM then most probably the size would be pre-selected with Standard D2s v3 2 vcpus, 8 GB memory options (might be variations in some scenario), but here it appears blank and asking for Select size due to selection of image/managed disk.

Next, click the Select size link, it will load the Select a VM size blade where you can choose an appropriate size for the new VM. 

Select Size

Once you select the desired size, click the Select button which will lead to back to Instance Details with  selected option of Size.

Create Virtual Machine Size


STEP – 8: Provide specifics for Inbound Port rules


Under Inbound Port Rules - Public inbound ports, choose Allow selected ports and then select RDP from the drop-down. 

Along with under the Save Money – Already have a Windows license, go with the default selection as No.

Create Virtual Machine Save Money


Next, proceed ahead by clicking the Review + create button at the bottom of the page, promptly the validation will be started.

STEP – 9: Review and Creating the VM


On the Create a virtual machine page, post validation success you can see the details for the VM you are about to create from the managed disk (based on snapshot).

Create Virtual Machine Validation


If you feel each information is fine and ready, then click the Create button. It will take a few minutes for your VM to be deployed. Sooner you will be notified once the cloned VM is created successfully.

Virtual machine deployed


The new virtual machine using the cloned image is deployed successfully, time to connect the VM now.

STEP – 10: Connect to new Virtual Machine


Move to newly created VM Overview dashboard and copy the Public IP address or can click the Connect button from the menu bar to log on the VM.

Cloned VM overview


As usual, you have both options to log on the VM using either mstsc utility and copied the public IP address or go ahead with the downloaded RDP file, I am moving with mstsc.

Note: Here the same administrator credentials will be required, which was provided during the provisioning of old virtual machine (VM).

Remote connection to cloned VM


Once you get connected with newly created Azure VM, here you can notice the same Operating Software, all other applications and settings are appearing which were part of previous VM.

Cloned VM connected


Congratulation, Clone to an Azure VM using Snapshot done!! 😊

STEP – 11: Connect to old Virtual Machine


Since we created the new virtual machine based on Snapshot and Managed Disk option, respectively, henceforward still we can access the old virtual machine. In other words, still the old virtual machine is running.

Virtual Machine list


Let us connect the same, move to old VM Overview dashboard and copy the Public IP address or can click the Connect button from the menu bar to log on the VM.

Old VM overview


As usual, I am moving with mstsc utility and copied the public IP address to connect to the virtual machine. 

Remote connection to old VM


Post get connected with the old Azure VM, here you can notice nothing has been changed neither Operating Software nor all other applications and settings. 

Old VM connected


Therefore, in previous article, we have seen that using sysprep.exe which is a part of Generalization process, the virtual machine (VM) is considered Generalized and cannot be restarted or access the same. In brief, using Generalized option we can create the cloned VM, but the old VM get deallocated so further you cannot access the old VM.

However, using the Snapshot option, we clone an existing Azure VM and keep old VM in working condition, i.e. both VM would be in running mode.

Keep visiting for further posts.

No comments:

Post a Comment