IBM Cloud Global

 View Only

How to migrate a EC2 Instance from AWS Cloud to IBM Cloud Gen2 VPC?

By Sivasailam Vellaisamy posted Thu September 15, 2022 11:33 AM

  

Migrate your EC2 Instance from AWS to IBM Cloud Gen2 VPC

In this session,  I am going to demonstrate the step-by-step procedure for migrating a EC2 instance from AWS cloud to IBM Cloud.

For this exercise, I have taken a EC2 instance with following Configuration

  •  OS / AMI : RHEL-8.6.0 (RHEL-8.6.0_HVM-20220503-x86_64-2-Hourly2-GP2)
  • Instance type : t2.small and 
  • Installed a sample application to showcase how the application is also migrated to IBM Cloud with zero modification.

Note : In this example I am going to discuss about RedHat Linux EC2 migration but a similar approach can be followed for other OS as per IBM Cloud Certified OS images. Also, Refer to "Reference" section at the end of this document for Custom OS Image requirements and limitations,

Below is the configuration snapshot of  EC2 instance which will be used for this exercise:

 

 Snapshot of OS Level Configuration of the above EC2 Instance in AWS Cloud:

 

For  this exercise, I have also configured a sample web application from the above EC2 instance. Let me access the demo app over Public DNS name of the EC2 instance.

 
Now, lets prepare above EC2 instance for migration from  AWS Cloud to IBM Cloud.

 This Migration process involves 4 logical steps as follows:
  • Preparation of EC2 Instance for migration in  AWS Cloud
  • EC2 Image Creation & Image Import Procedure
  • Export Image to IBM Cloud Object Store
  • Deploy the EC2 Image in IBM Cloud as a VSI & Validate VSI status

  1. Prepare AWS EC2 Instance for migration:
      1. Login (SSH, Eg. ssh -i <ssh-private-key> ec2-user@IP of the EC2 instance>) to the EC2 instance. And elevate your login ID to root user by executing “sudo"
      2. Back up /etc/default/grub
      3. Edit /etc/default/grub
      4. Update following variable “GRUB_CMDLINE_LINUX” in “grub” file with following values “console=ttyS0, vga=normal, nofb, nomodeset” as below :
      5. Back up the /boot/grub2/grub.cfg file
      6. Generate a new grub.cfg file “grub2-mkconfig -o /boot/grub2/grub.cfg”
      7. Reboot the EC2 Instance with above changes.
      8. After successfully rebooting, login(SSH) to ec2 instance & elevate your login ID to root user by executing “sudo su” and validate following configurations. Check for virtio drivers by executing “grep -i virtio /boot/config-$(uname -r)” Look for VIRTIO_BLK and VIRTIO_NET in the output. If those lines are not present, then the virtio driver is not built into the kernel.   
      9. If the VIRTIO_BLK and VIRTIO_NET lines are present, verify that the drivers are present in the temporary root filesystem by running the following command “lsinitrd /boot/initramfs-$(uname -r).img | grep virtio”
      10. Validate if Network interface is set up to auto-configure, switch to “/etc/sysconfig/network-scripts”. Identify your network interface drive & in this example my interface name is “ifcfg-eth0”. “cat” or “vi” this file to validate “BOOTPROTO” set to “DHCP”
      11. Verify “BOOTPROTO” set to DHCP
      12. Run the following command to verify if cloud-init package is installed,: cloud-init –version.                                                                                             Note : Cloud-init version 0.7.9 or greater is required
      13. If cloud-init is not installed then run the following command. yum install cloud-init
      14. Edit /etc/cloud/cloud.cfg, check  datasources_list property exists. If this variable exists then verify that it contains ConfigDrive and NoCloud  or remove the datasources_list property entirely. Note : In this demo setup I could not find the above property hence skipping this step.
      15. In the /etc/cloud/cloud.cfg file, verify that the cloud_final_modules section includes the scripts-vendor module and that it is enabled.                                                                                                                                                                                                                                                Now the EC2 instance is ready for creating VHD image. Shutdown the ec2 instance and follow below procedure to create the image.                                
    1. EC2 Image Creation & Import Procedure:
    1. Configure AWS CLI in your workstation /laptop. Please refer to this link for AWS CLI config procedure. For this demo setup I have configured AWS CLI environment “config” & “credentials” as follows in my laptop.                                                                                                                                                           i. Create a Profile  ii. Configure AWS credentials
    2. To export a EC2 instance from AWS, Create a S3 bucket where the EC2 instance image will be stored. Login to AWS Console & search for S3 service. Then select “Create bucket”.  For this demo I have created a bucket named : vsm001-demo                                                                                                                                                   Note : The bucket must be in the same Region where you want create a VSI from this Image.

    3. After the successful creation of S3 bucket,  Attach an access control list (ACL) to your S3 bucket containing the following grants.
    4. Under permission go to ACL section & select edit button to set “Grantee” for the bucket.
    5. Select “Add grantee”

      Enter “Grantee”. For Grantee, we need to provide the appropriate Region-specific canonical account ID, which can be obtained from the  following link

      For this exercise I will be using “All other Regions” ID from following list.                                                                                                                                                                                                                                                                                
    6. Enable Read & Write permission after entering “All other Regions” canonical ID under Grantee. After setting above values select “Save changes”

      S3 bucket is created successful with required ACL where the “to-be” migrated EC2 image will be stored.

    7. Create file.json (file anme could be any name) file that specifies S3 bucket which will be used in this exercise for storing EC2 instance image. For this demo I have created a file call file.json. In this file “vsm001-demo” is the name of the bucket which created from previous steps. And the “S3Prefix”  is the folder where you want to store EC2 image and this folder is auto created as part of export procedure.


    8. Execute following command to create image into the above S3 bucket:
       
      aws ec2 create-instance-export-task --instance-id <Instance ID> --target-environment microsoft --export-to-s3-task <location of the JSON file in your local macine>.                                                                                                                                                                                                                         

      Example: "aws ec2 create-instance-export-task --instance-id i-06z7efe3m00fme91d --target-environment microsoft --export-to-s3-task file:///Users/sivasaivm/file.json"

      Execution of above command will give you the following output:

      {

          "ExportTask": {

              "ExportTaskId": "export-i-07845f25dfcad0d33",

              "ExportToS3Task": {

                  "DiskImageFormat": "vhd",

                  "S3Bucket": "vsm001-demo",

                  "S3Key": "vms1/ export-i-07845f25dfcad0d33.vhd"

              },

              "InstanceExportDetails": {

                  "InstanceId": " i-07845f25dfcad0d33",

                  "TargetEnvironment": "microsoft"

              },

              "State": "active"

          }

      }

       

      Make a note of Taks ID. In this example task ID is - "export-i-07845f25dfcad0d33".                                                                                                                  Note : Instance ID can be located from EC2 “Details” page from AWS Console.
    9. To track the progress of export Job, Run following command. 

      #aws ec2 describe-export-tasks --export-task-ids export-i-07845f25dfcad0d33 

      {

          "ExportTasks": [

              {

                  "ExportTaskId": "export-i-054663cb745db4db3",

                  "ExportToS3Task": {

                      "DiskImageFormat": "vhd",

                      "S3Bucket": "vsm001-demo",

                      "S3Key": "vms1/ export-i-07845f25dfcad0d33.vhd"

                  },

                  "InstanceExportDetails": {},

                  "State": "active"

              }

          ]

      }

       

      The state will be changed to "State": "completed" as soon as export job completes.

      #aws ec2 describe-export-tasks --export-task-ids export-i-07845f25dfcad0d33

      {

          "ExportTasks": [

              {

                  "ExportTaskId": "export-i-054663cb745db4db3",

                  "ExportToS3Task": {

                      "DiskImageFormat": "vhd",

                      "S3Bucket": "vsm001-demo",

                      "S3Key": "vms1/ export-i-07845f25dfcad0d33.vhd"

                  },

                  "InstanceExportDetails": {},

                  "State": "completed"

              }

          ]

      }
    10. As soon as the image creation job is completed you should be able to see a VDH image in bucket "vsm001-demo", under folder “vms1” with a file named “export-i-07845f25dfcad0d33.vhd”. Now, Select “Download” to import EC2 image to  your local machine. 3. Export Image to IBM Cloud Object Store:
    1. Login to IBM Cloud “cloud.ibm.com” (Note : let's assume that this IBM Cloud user ID is required of IAM privilege enabled to perform the following tasks)

    2. Create a Object storage
    3. For this demo purpose I have used  “Lite” (Free) version of IBM Cloud Object storage which can store up to 25GB of storage at free of cost. I have used following object storage naming “aws-ibm-demo-store01” for this demo. Now, Lets create bucket.
    4. Go to Resources List
    5. Go to Storage under “Resource list” and chose the Object Store ““aws-ibm-demo-store01” for creating bucket.
    6. Create a bucket
    7. Chose “Customize your bucket” option.
    8. I have the Set Bucket name as “ec2-2-ibm-vsi” and location (For this demo) as US-East region. 
    9. And leave other settings with default  value and choose “Create bucket”button and the bucket is ready for file uploading
    10. Object (File) size of more that 200MB can not be uploaded directly to IBM Cloud Object store hence user should use either Aspera Browser plug-in or Cyberduck  to upload VHD image into Object storage. For this demo, I will be using Aspera Browser plugin to export EC2 image to IBM Cloud. Open this link to download Browser Plugin. [ Note : I have also created a detailed file on uploading a procedure using Cyberduck. Kindly refer to Appendix section for details]. I would strongly recommend to use Aspera based file upload since Aspera based file transfer reduce file upload time drastically compared to any other file transfer tool.
    11. Select “Download Aspera Connect a.b.x for os” and install it in your  workstation from where you want to upload EC2 instance image into IBM Cloud Object Storage.
    12. In the browser you get an option to complete both install Add-on and Install connect procedure.
    13. Select “Install Add-on” & Select “Add to Firefox

    14. And you get a confirmation screen as follow.
    15. Now browser is ready with Aspera Plugin.Upload the image to IBM Cloud Object storage which was created during step a,b & in this section. Open IBM Cloud Console. Go to “Resources list” from IBM Cloud console
    16. Select storage “aws-ibm-demo-store01”
    17. Chose the object store bucket ““ec2-2-ibm-vsi” which was created from the previous steps. And chose “Upload” button.
    18. Chose “Aspera high-speed transfer”option then select “Drag and drop files and folders or click to upload files"
    19. Select the VHD Image which you want to Upload to IBM Object store.
    20. Select “Upload”  and the upload process will show the progress on a small windows as below.
    21. File upload progress can be monitored from this window. Now the EC2 instance in VHD image format is ready for deployment in IBM Cloud.
    4. Deploy the EC2 Instance VHD Image in IBM Cloud.

    1. Enable “Authorization” between Object Storage Services & IBM Cloud Image Repository Service hence the Exported EC2 image will be visible from IBM Cloud VSI image catalogue. Login to IBM Cloud & Choose IAM. 
    2. Choose “Authorization” Tab then Select “Create”
    3. Under “Grant a service authorization” choose following setting of “This Account".   After selecting above marked values then select option “Authorize”.

    4. Now you should be able to see this service authorization as given below.
    5. Import EC2 Image from IBM Cloud Object and store as Custom Image into the IBM Cloud Catalog.
    6. Choose “Create” tab from Custom Image for the VPC window.
    7. Chose following values while creating custom image. Since the demo image is uploaded to IBM Cloud US-East region I am choosing the following values for creating VSI Image in the Washington Region.  Select Following Values then select Custom Image button. In this form, Operating system name and version should be same as AWS EC2 instance OS version.  VSI Image creating progress can be monitored from the following window. The status should be changed to “Available” and this process may take few minutes to complete.

    8. Lets Provision a VSI from custom Image & Attach a Public IP to validate application access. In the custom image window select the three dots and chose “Create virtual server instance”
    9. A new VSI Provisioning form appears and  update the form with the following values.  [Note : For this exercise I am using all default value from Compute Profile and using a SSH key which was uploaded earlier in my account. You may follow SSHkey gen process to create your own SSH key].

      Leaving the other values with default value and choose the “Create Virtual Server” tab.  VSI Creating process started & the status should be “Starting”.    After few minutes, the server status should be changed to “Running" 

    10. Lets attach Floating IP to this instance.Click on the name of the VSI.    Select the edit “pencil” icon.  Now a Public IP is attached to the instance & make a note of this IP.   
    11. SSH to the VSI Instance
    12. Validate OS Config details. You would have noticed that the Kernel Release, OS version etc. is same as the Source EC2 details from AWS .
    13. Lets access the demo application from browser. URL : http://<floating-IP-address>

         

        Congratulations!!! EC2 Instance from AWS cloud is successfully migrated to IBM Cloud Gen2 VPC

        References:

         

        AWS (Image Import / Export) : https://docs.aws.amazon.com/vm-import/latest/userguide/vmimport-image-import.html

        IBM Cloud Image Upload Process : https://cloud.ibm.com/docs/vpc?topic=vpc-create-linux-custom-image#upload-image-icos

        IBM Cloud Object Storage HMAC Credential creation process: https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-service-credentials

        IBM Cloud Importing Custom images: https://cloud.ibm.com/docs/vpc?topic=vpc-importing-custom-images-vpc#import-custom-image-cloud-object-storage

        Demo App : https://github.com/juice-shop/juice-shop

         

         Appendix:

        ALTERNATE OPTION FOR FILE UPLOAD

        Note : If a user is not comfortable with Aspera plugin based upload process then user can follow this procedure to upload image into IBM Cloud but not both.

         

        ​Create HMAC credentials for IBM cloud Object store. Login to IBM Cloud then go to “Resources list” from IBM Cloud console

        Select storage “aws-ibm-demo-store01”
        In Object storage section go to “Service Credentials” and select “New Credential”
        Update the following values in the new credentials form.


        Note down the Access & Secret Key


        Download Cyberduck client from following Link.

        Open the Cyberduck file which was downloaded from previous step.

        Cybeduck utility will open a small window as below & Select “Open Connection” from utility window.


        From drop-down choose ‘Amazon S3”


        After you choose “Amazon S3” the following window will appear. Server end point, Access Key & Secret Key value needs to be passed. (In the subsequent steps I have given the procedure to get the values requested in the below UI.)


        Get the Server endpoint from your Object Store location. Please pay attention to following filters based on your Object store location.


        API & Secret can be gathered from “Service Credentials” tab.


        Once all the values are keyed in, Press Connect.


        Now user should be able to see the Object Store Bucket in the IBM Cloud.


        Right click on the bucket and chose “Upload” option.




        Chose the Image file which you may want to upload.


        Monitor the progress in the same window. As soon as the upload process completes, user should be able to see the Image in IBM Cloud Object store bucket.


        Now the EC2 instance in VHD image format is ready for deployment in IBM Cloud.








        #Featured-area-1
        #Featured-area-1-home
        #Spotlight
        3 comments
        1803 views

        Permalink

        Comments

        Wed March 29, 2023 06:38 PM

        I had no idea the images between AWS and IBM were so compatible.  This is a great solution for migrating prototypes to IBM without having to rebuild everything!

        Fri September 16, 2022 04:29 AM

        Thanks Brahm Singh.

        Fri September 16, 2022 01:59 AM

        Thanks for writing this knowledgeable blog