Migrating Ubuntu Virtual Machine from Azure to AWS EC2 Using AWS MGN

Ubuntu Virtual Machine from Azure to AWS EC2 Using AWS MGN

Introduction

As our customers sought to migrate their Ubuntu-based virtual machines from Azure to AWS EC2 to optimize costs and improve flexibility, ensuring a seamless migration process was critical. Any downtime or data inconsistency could negatively impact their business operations. We proposed leveraging AWS cloud migration, specifically AWS Application Migration Service (MGN), to facilitate the migration of Ubuntu VMs from Azure to AWS with minimal downtime.

This blog will discuss the step-by-step process of using AWS MGN to migrate an Ubuntu Linux VM, focusing on the prerequisites and technical steps required for a successful migration.

Prerequisites

Before starting the migration process, ensure the following:

  • Disable secure boot and vTPM in the source Azure VM
  • Create an IAM user in AWS with the necessary policies:

AWSApplicationMigrationAgentInstallationPolicy, AWSApplicationMigrationAgentPolicy

  • Generate access and secret keys for the IAM user, which will be used to install the replication agent in the Azure VM
  • Ensure that the Azure VM has internet access (public IP or through NAT)

Handling EC2 Status Check Failure

Instance check failed; system check passed

 

If the steps outlined in this guide are not followed correctly, you may encounter an issue where the status check fails when launching the EC2 instance. This typically happens because the migrated VM is still using Azure-specific settings, such as the wrong kernel or cloud-init configuration.

When the Azure-specific kernel or services are still active, the EC2 instance may fail to boot properly in the AWS environment, resulting in a Status Check Failed error. To avoid this issue, follow the migration steps.

Setup, replicate, test, and finalize migration
Application Migration: Source to AWS Target

Migration Steps

1. Prepare the Azure VM:

  • Connect to the Azure VM via SSH.
  • Verify the running kernel

uname -r

  • Enable root password authentication for troubleshooting.

sudo passwd root

2. Install AWS Replication Agent on Azure VM:

  • Update the GCC compiler if the replication agent is not getting installed

sudo apt-get update

sudo apt-get install gcc-12

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-12 12

sudo update-alternatives –config gcc

sudo apt-get install linux-headers-$(uname -r)

  • In the AWS MGN console, In source server click on add server and select the linux machine option
  • Provide the IAM access key ID  and secret access key
  • Download the installer using the below command

sudo wget -O ./aws-replication-installer-init

“https://aws-application-migration-service-ap-south-1.s3.ap-south-1.amazonaws.com/latest/linux/aws-replication-installer-init”

3. Install AWS Linux Kernel:

  • Install the AWS-tuned kernel

sudo apt install linux-aws

  • Verify the kernel installation

dpkg –list | grep linux-image

  • Update the system to boot from the AWS kernel. (Do not reboot the machine)

sudo vim /etc/default/grub

By default GRUB_DEFAULT value will be 0. Update it with the AWS kernel.

GRUB_DEFAULT=”Advanced options for Ubuntu>Ubuntu, with Linux 6.5.0-1024-aws” (update the version based on the aws kernel version installed in the source VM)

  • Important: Do not reboot the VM at this point, as a reboot will apply the kernel changes on the source VM, which could cause the Azure VM to enter a generalized state

4. Disable Azure Services (Since azure services are not supported by aws ec2)

  • Identify running Azure-native services

systemctl –type=service

  • Disable unnecessary Azure services if it is running.

sudo systemctl disable hv-kvp-daemon.service

sudo systemctl disable walinuxagent.service

sudo systemctl disable walinux-agent-network-setup.service

5. Reconfigure Cloud-Init Data Source

  • Change the data source to AWS EC2

dpkg-reconfigure cloud-init

Select the “EC2: read data from EC2 metadata service” option by clicking the space bar and unselect the azure option and press the tab and click enter

6. Start Replication Process

  • Execute this command in the Azure VM to begin the replication

sudo chmod +x aws-replication-installer-init; sudo ./aws-replication-installer-init –region –aws-access-key-id –aws-secret-access-key –no-prompt

: Replace this with your AWS region (e.g., us-west-2, ap-south-1)

: Replace this with the IAM Access Key ID

: Replace this with the IAM Secret Access Key

7. Launch Test Instance:

  • After completing the replication we can see the  azure VM in the source server section of the MGN console
  • Click on the azure VM in the MGN console and create a launch template and update the version of launch template from the EC2 service launch template section
  • Access the test instance
  • The default SSH username and private key will remain the same as the source Azure VM. Even if a new key is attached to the EC2 instance during launch, it will not take effect
  • Therefore, update the public key to match the private key that you want to use with the target EC2 instance
  • ssh-keygen -y -f /path/to/new-key.pem
  • Copy the output and add it to ~/.ssh/authorized_keys on the target ec2 instance

8. Final Steps

  • Reboot the instance
  • After rebooting, you will be able to SSH into the migrated instance

Conclusion

By following this process, we successfully migrated the client’s Ubuntu VM from Azure to AWS using AWS cloud transformation services with minimal downtime. The AWS Linux kernel optimizes performance in the AWS environment, while our method retains the integrity of data and system configurations during the migration. This process is an essential step in legacy Cloud management services helping clients move their Azure cloud applications to AWS while ensuring cost optimization and flexibility. If you’re planning a similar migration, this guide can serve as a detailed reference to execute it smoothly.

Looking for a reliable Cloud consulting company to optimize your cloud journey? CloudifyOps offers top-tier cloud infrastructure services,delivering scalable, secure, and cost-efficient solutions. Whether you need seamless cloud migration or expert cloud management, we are here to help.

Get in touch with CloudifyOps today to unlock your cloud potential and drive innovation.

 

 

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from - Youtube
Vimeo
Consent to display content from - Vimeo
Google Maps
Consent to display content from - Google
Spotify
Consent to display content from - Spotify
Sound Cloud
Consent to display content from - Sound