Clone an Azure VM
In one of previous post Setup an Azure Virtual Machine we have been talking about the Azure Virtual Machine (VM). An Azure Virtual Machine (VM) is an on-demand, scalable computing resource deployed on Azure through different methods, gives more control over the computing environment. You can create either a Windows Server based or Linux based Azure VM, fully depends on requirement and circumstance.
In some specific scenario we required to create the exact copy or better to say clone the existing Azure VM with its current state and software in order to save time. In addition to this we can keep the exact configuration as exists in the original VM, which is certainly useful during testing, validating or making ensure the security etc.
With the introduction of managed disks, it became 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 feasible and can be achieved by different ways, using –
- Generalized
- Snapshot
- Site Recovery
Here we will walk through to Clone an Azure Virtual machine using Generalize option only, that is stored as either a managed disk or an unmanaged disk in a storage account. Later, the image can be used to create multiple VMs.
Generalized the Virtual Machine
Generalization is a preparation process of a virtual machine creating an image with both Windows and Linux. In Windows, there is a tool called as Sysprep to get done us with generalization, that is located under system32/sysprep.
Sysprep stands for System Preparation, that prepares a Windows installation (Windows client and Windows Server) for imaging, allowing you to capture a customized installation. It removes all your personal account and security information, and then prepares the machine to be used as an image.
Note: 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.
Pre-requisites
Before moving ahead, we need some pre-requisites to accomplish this Cloning VM task using Azure Portal.
- Azure subscription, if you don't have an account then sign up for a free Azure account - https://azure.microsoft.com/en-gb/free/
- An existing Windows Azure virtual machine (VM).
STEP – 1: Validate and log on to existing 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.
If it is in stop mode, i.e. deallocated then start the same, further copy the Public IP address or can click the Connect button from the menu bar to log on the VM, once Status indicates Running.
STEP – 2: Log on to Azure Virtual Machine (VM)
Next, required to log on the VM using either mstsc utility and copied the public IP address or go ahead with the downloaded RDP file.
I went through the mstsc utility to connect the remote desktop, and logged on the Azure VM.
STEP – 3: Generalize the Virtual Machine using Sysprep utility
Post successful, now logged on the Azure Virtual Machine, execute the Command Prompt under Administrator privilege.
Once Command Prompt available, then navigate the directory path to as listed here –
C:\Windows\System32.
Verify the Sysprep directory and existence of utility using directory listing, further move inside to Sysprep directory.
Next, time to execute sysprep.exe utility to prepare the Windows Azure VM, as soon as sysprep starts, the VM is considered Generalized and cannot be restarted or access the same.
We will talk and walk through in another post how to clone an existing Azure VM and keep old VM in working condition, i.e. both VM would be in running mode.
Promptly the Sysprep utility launch the System Preparation Tool, here need to select the check box of Generalize and select the Shutdown Options as Shutdown from the drop down box, proceed with click to OK button.
Next, post clicking the OK button the tool starts the processing generalize phase quickly.
Sooner you will lose the remote connection to the Azure virtual machine, since deallocation process has been started and VM turned to Stopped mode.
You can verify the status of the Azure VM on Azure Portal simultaneously, it will be appearing as Stopped status.
STEP – 4: Create a Managed image using Azure Portal
Since the said VM has been generalized using the sysprep utility, next we can proceed to create a managed image via Azure Portal.
Move to the Overview blade of the selected virtual machine page, in my case it is named as ‘cloudVM’. Here on the upper menu, select Capture button.
Once you click the Capture button, the Create image blade will be loaded along with the following required properties –
- Name – Submit a specific name to this image or can go with dynamic generated name.
- 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.
- Checkbox – Since the VM is marked as generalized, no further actions are allowed on it. Henceforth you can select this checkbox to have the virtual machine deleted automatically once the image is created.
Proceed by clicking the Create button the minute you provided above listed properties.
The sooner the system will validate and proceed to stopping the virtual machine as soon as click the Create button.
In a little while, the VM will be stopped as well deallocated and the same you can verify under its Overview blade. Here you can see the Status as Stopped (deallocated) and the Public IP address has now been revoked.
STEP – 5: Validate the newly created image
In previous steps we have been generalized the Azure VM as well created a new image for the existing VM, now validate the image. Go to Resource groups and here you can see a new entry of the newly created image of the VM.
Apart from this you can notice the old VM is not listed here because it has been deleted as you selected the checkbox during creation of an image, rest other services exist as NIC, NSG and VNET etc.
Congratulations, VM image has been created!! 😊
STEP – 6: Restore Virtual Machine from the Cloned image
Time to restore the said Azure Virtual Machine using its cloned image which we have been walking through already. Move to Resource groups blade and click the VM image.
Once you click the VM image, it will load its dashboard with all available details, here you can click the + Create VM button on upper menu to proceed further.
It will load the Create a virtual machine blade the time you click the Create VM button inside the image blade in the previous step.
On the Basics tab, under Project Details, make sure the correct subscription is selected and then choose either an existing Resource group or can create a new using Create new.
I am going with earlier created resource group ‘rajresource’.
STEP – 7: Provide specifics for Instance Details
Under the Instance Details section of Create a virtual machine blade, provide a valid Virtual Machine name as well Size only. Since this is the cloned image so Region would be pre-selected and under an Image property, you can see the earlier created cloned image is already pre-selected.
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 is appears blank and asking for Select size due to cloned image.
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.
Once you select the desired size, click the Select button which will lead to back to Instance Details with selected option of Size.
STEP – 8: Provide specifics for Account and Port rules
Under Administrator Account, provide valid username and password for the administrator of this Virtual Machine.
Along with under Inbound Port Rules - Public inbound ports, choose Allow selected ports and then select RDP from the drop-down.
Next leave the remaining defaults and then click the Review + create button at the bottom of the page.
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 cloned image.
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.
You will get a notification once the cloned VM is created successfully.
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.
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.
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.
Congratulation, Clone to an Azure VM using Generalize done!! 😊
At this time advancements in is also affecting a point associated with argument. https://onohosting.com/
ReplyDelete