Migrating a VM from EC2 to Azure at 300 Mbps
Join the DZone community and get the full member experience.Join For Free
This post contains instructions for migrating a VM from Amazon Web Services EC2 to Microsoft Azure. The instructions assume a basic setup where the AWS EC2 instance is running Windows Server and comprises a single disk containing the OS. A similar technique can be used to migrate additional disks.
The general idea is as follows:
- Add a volume to the EC2 instance
- Clone the OS disk to a VHD on that volume (using the Disk2VHD utility)
- Upload the VHD to Azure Storage (using the Azure PowerShell cmdlets)
- Create a logical Azure Disk from that VHD
- Create an Azure VM from that Disk
- Remove AWS software from the Azure VM
- Install the Azure Agent on the Azure VM
This is a pretty smooth process. The only novelty lies in cloning the OS disk and uploading the resulting VHD to Azure Storage.
Add a Volume to the EC2 Instance
A new volume is attached to the EC2 instance to provide a disk sufficiently large to contain the cloned OS disk. The VHD generated in the cloning process is a dynamic VHD that is smaller than the original disk.
Use the AWS portal to create a volume and attach it to the EC2 instance. Once attached, this volume must be initialized and formatted like any other attached volume. It should be provided with some drive letter.
Clone the OS Disk to a VHD
The cloning of the OS disk is performed using the Disk2VHD utility created by Mark Russinovich (@markrussinovich), a technical fellow on the Microsoft Azure team. This utility allows the cloning of a running disk into a VHD.
While logged into an RDP session on the EC2 instance download Disk2VHD. Unzip the Disk2VHD download and copy the directory to a convenient location on the C:\ drive.
Disk2VHD clones a disk into either a dynamic VHD or a dynamic VHDX. Azure supports only fixed format VHDs, but the VHD will be converted to fixed format during the upload process.
- Double click on the Disk2VHD.exe to bring up the UI
- Select the disks to be cloned
- Specify the output VHD file name
- Unselect the VHDX option.
- Click Create to start the cloning process.
The Disk2VHD UI displays a progress bar. On successful completion, the VHD is in the specified location. Note that a dynamic VHD is likely to be smaller than the original disk.
Install the Azure PowerShell cmdlets
The Azure PowerShell cmdlets are used to copy the VHD to Azure Blob Storage in the appropriate region (datacenter). The cmdlets can be downloaded directly from the Azure GitHub repository and installed into the EC2 instance
While logged into an RDP session on the EC2 instance:
- Browse to the Azure PowerShell release page in GitHub
- Click on the Windows Standalone link
- Click Run to install the cmdlets.
- Click Finish
The Azure PowerShell cmdlets are now installed.
Upload the VHD to Azure Storage
The Azure PowerShell cmdlets must be configured to use the appropriate Azure subscription and storage account, as follows
- Go to Start/All Programs/Windows Azure – and click on Windows Azure PowerShell
- Invoke Add-AzureAccount (and sign in to Azure with an appropriate Administrator account)
- Invoke Select-AzureSubscription and provide the subscription name.
- Invoke Set-AzureSubscription to specify a default storage account
Once the configuration is completed the Add-AzureVhd cmdlet can be used to automatically convert the VHD to fixed format and upload it to Azure Storage. Add-AzureVhd is supplied with the local path to the VHD and the full URL for the VHD in Azure Storage (in a storage account and container which already exists)
Add-AzureAccount Select-AzureSubscription -SubscriptionName YourSubscription Set-AzureSubscription –SubscriptionName YourSubscription ` –CurrentStorageAccount YourStorageAccount Add-AzureVhd –Destination ` http://YourStorageAccount.blob.core.windows.net/vhds/EC2InstanceTest.vhd ` -LocalFilePath d:\vhds\EC2Instance.vhd
Note that the Add-AzureVhd command in the example should be a single line.
The upload proceeds in two steps: the creation of an MD5 hash used to verify the success of the upload; and the conversion of the VHD to fixed format and its upload to the specified location in Azure Storage. Note that the uploaded VHD is expanded to the original size of the disk.
Create an Azure Disk from the VHD
Before a VHD in Azure Blob Storage can be used as a disk in an Azure VM it must be configured. This configuration comprises providing a logical name for the disk that can be used in subsequent operations. The Azure Disk is configured as follows:
- Browse to the Azure Portal
- Navigate to the Virtual Machines menu (on the LHS)
- Click on the Disks tab
- Click on the Create button
- Provide a logical name for the Disk
- Locate the VHD URL in Azure Blob Storage
- Select the VHD contains an Operating System check box
- Ensure Windows is selected for the Operating Systems Family
- Click the tick button to create the Azure Disk
On completion, the disk is made visible in the list of Disks on the Azure Portal.
Create an Azure VM from the Azure Disk
This is the standard Azure process of creating a VM from the Gallery, with the only difference being that a custom Disk is used instead of an Image. The general process of using the Gallery to create an Azure VM is documented on this page.
The Azure VM is created as follows:
- Click on the Instances tab (on the Virtual Machines section of the Azure Portal)
- Click on the New button
- Click on From Gallery
On the Choose an Image window
- Click on My Disks
- Click on the appropriate Disk
- Click the Next arrow button
On the Virtual Machine Configuration page
- Provide a Virtual Machine Name
- Leave Tier at Standard
- Select an appropriate Size
- Click on the Next arrow button
On the next Virtual Machine Configuration page
- Specify either a new or existing Cloud Service name
- Select the Azure Subscription
- Specify the Region that contains the VHD
- Leave the Availability Set option at None
- Leave the default Endpoints configuration
- Click on the Next arrow button
On the third Virtual Machine Configuration page
- Unselect the VM Agent that supports extensions is already installed checkbox
- Click the Next arrow button
An Azure VM will now be created with the OS disk being the VHD migrated from AWS. This process takes a few minutes. Note that normally the Virtual Machine name provided would become the hostname, but following this migration the created VM uses the existing EC2 hostname instead.
Connect to the VM
Once the VM reaches the Running state it is possible to RDP into it. This may require a couple of attempts the first time while DNS entries are being updated.
In the Virtual Machines section of the Azure Portal:
- Click on the Instances tab
- Click on the VM in the instances list
On the Instance page
- Click on the Connect button
This brings up a standard RDP Connection dialog
- Click through the RDP dialogs
- Sign in to the Azure VM with the original EC2 VM credentials
On the Azure VM Desktop a Shutdown Event Tracker dialog is displayed.
- Provide a Comment
- Press OK
You are now successfully signed in to an Azure VM that has been migrated from EC2. Note that the instance information provided on the desktop is that of the original EC2 VM rather than the current Azure VM. This display can be removed by selecting a new desktop background.
Uninstall AWS Software
The AWS software should be removed from the VM. While signed in to an RDP session, use the Control Panel / Uninstall a Program feature to remove the following software:
- AWS Tools for Windows
- Citrix Tools for Virtual Machines (requires reboot)
Install Azure Agent
The Azure Agent can be installed on the Azure VM.
From inside an RDP session to the Azure VM, download and install the Azure Agent.
The Azure Agent is configured using the Azure PowerShell cmdlets, which can be invoked from anywhere the Azure PowerShell cmdlets are installed and configured:
$vm = Get-AzureVM -ServiceName YourService -Name YourVM $vm.VM.ProvisionGuestAgent = $true Update-AzureVM -ServiceName YourService -Name YourVM -VM $vm.VM
The installation of the Azure Agent can be tested by installing the BGInfo extension which the agent uses to provide instance information on the desktop background. The BGInfo extension is installed using the following PowerShell script:
$vm = Get-AzureVM -ServiceName YourService -Name YourVM Set-AzureVMBGInfoExtension -VM $vm Update-AzureVM -ServiceName YourService -Name YourVM -VM $vm.VM
The next time an RDP session is opened the desktop background will contain information about the current Azure VM.
This post describes the fairly simple process to migrate a Windows Server VM from Amazon Web Services EC2 to Microsoft Azure.
Published at DZone with permission of Neil Mackenzie, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Using OpenAI Embeddings Search With SingleStoreDB
Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
Knowing and Valuing Apache Kafka’s ISR (In-Sync Replicas)
Database Integration Tests With Spring Boot and Testcontainers