Migrating a VMware VM to AWS

aws

This document describes the steps necessary to migrate a VMWare virtual machine (.vmx and accompanying .vmdk) to the Amazon Web Services (AWS) cloud.

Setting up AWS Command Line Tools

There are many actions in AWS that can only be completed by using the AWS command line tools. This section describes the steps necessary to set up these tools (Evens, 2009).

Install Java

Download and install Java if you do not already have it: http://www.java.com/en/download/manual.jsp#win.

Download APIs

  1. EC2 Command line tools: http://aws.amazon.com/developertools/351
  2. Elastic Load Balancing tools: http://aws.amazon.com/developertools/2536?_encoding=UTF8&jiveRedirect=1

It is a good idea to pick somewhere to place all of your command line related items; for example: C:\AWS. Unzip both archives into this folder.

Get your AWS Certificates

  1. Go to https://aws-portal.amazon.com/gp/aws/securityCredentials
  2. Log in
  3. Scroll down to the X.509 section
  4. Create a new certificate (if one does not exist)
  5. Download the Private Key File (pk-.pem) and store in AWS directory
  6. Download the Certificate File (cert-.pem) and store in AWS directory
  7. KEEP THESE FILES PROTECTED – they provide access to your AWS account

Configure Environment Variables

Create a batch file in your AWS directory awsTools.bat and add the following text:

SET JAVA_HOME="C:\Program Files (x86)\java\jre6"
SET EC2_PRIVATE_KEY=c:\aws\aws-pk.pem
SET EC2_CERT=c:\aws\aws-cer.pem
SET EC2_HOME=c:\aws\ec2\ec2-api-tools-1.5.2.4
SET PATH=%PATH%;%EC2_HOME%\bin
SET AWS_ELB_HOME=D:\aws\ElasticLoadBalancing-1.0.15.1
SET PATH=%PATH%;%AWS_ELB_HOME%\bin
CLS
CMD

JAVA_HOME will need to be set to the appropriate path for your machine. Find java.exe (it will be a in a folder called bin) and set JAVA_HOME to the parent directory of bin. For example with java.exe at “C:\Program Files (x86)\java\jre6\bin\java.exe” set JAVA_HOME to “C:\Program Files (x86)\java\jre6”.

EC2_HOME and AWS_ELB_HOME both point to the folders you unzipped the APIs into.

Test Command

If you run awsTools.bat you should have a command prompt that you can run the EC2 tools from.
Type ec2-describe-regions at the command prompt
Your results should look something like the following:

REGION eu-west-1 eu-west-1.ec2.amazonaws.com
REGION us-east-1 us-east-1.ec2.amazonaws.com

If you get an error or nothing is returned, check your configuration.

Setting Up Your VMware Image

There are several changes that should be made (if needed) to your VMware image before it is converted and uploaded to AWS.

  1. Remove all snapshots – remove any snapshots that you may have. If you do not want to remove snapshots, create a copy of your .vmdk and create a new VMware image that points to it.
  2. Partition must be IDE – If you have any SCSI Devices, you should convert them to IDE. You may want to use a third party tool to do this such as Acronis.
  3. Uninstall VMware tools- if you have installed the VMWare tools, remove them.
  4. Enable Remote Desktop Access – you will want to enable remote desktop connections and make sure that they are permitted through the firewall (if enabled).

Convert VM to OVF

OVF (Open Virtual Format) is a universal virtual machine format that is used for distribution across organizations and products. You must convert your VMware image to this format so that AWS can convert it to its virtualization format. This process may take several hours depending on the size of the image.

    1. Download the too from: http://www.vmware.com/resources/techresources/1013
    2. Open a command line with administrator privileges
    3. Example Syntax:
      ovftool “C:\Virtual Machines\Windows Server 2008 x64.vmx” “C:\Virtual Machines\Windows Server 2008 x64.ovf”

Import to AWS, Setup & Connect

Once the VM has been converted to OVF format, it is ready to be imported to AWS.

  1. Open awsTools.bat
  2. Get Access Key and Secret Access Key from AWS: My Account / Console > Security Credentials
  3. Create Import instance using ec2-import-instance
    1. Example Syntax:
      ec2—import—instance “C:\Documents\Virtual Machines\Windows Server 2008 x64—disk1.vmdk” -f vmdk -t ml.large —a x86_64 —o XXXXXXXXXXXXXXXXXXXX —w XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX —b my_bucket
    2. b. -o = Access Key
    3. c. -w = Secret Access Key
    4. d. -t = Instance Types (see http://aws.amazon.com/ec2/instance-types/)
  4. Wait until the Instance is uploaded and converted
    1. Use ec2-describe-conversion-tasks to check status
  5.  Start Instance
  6. Open up RDP port (3389) using the AWS Security Group inbound rules
  7. Obtain an Elastic IP from AWS
  8. Under Network Interfaces in AWS, assign Elastic IP to the network interface that belongs to the instance
  9. Connect via RDP using Elastic IP address

References

Evens, S. (May 19, 2009). Setting up EC2 command line tools on Windows. Retrieved March 20, 2012 from http://sevans.info/2009/05/19/setting-up-ec2-command-line-tools-on-windows/.

matiasimc. (June 21, 2011). Re: VMWare Workstation VM import Windows 2008 R2 failing. Retrieved March 29, 2012, from https://forums.aws.amazon.com/thread.jspa?threadID=58171.

VMware. (May 21, 20009). VMware OVF Tool. Retrieved March 29, 2012, from http://www.vmware.com/resources/techresources/1013.

 

12 thoughts on “Migrating a VMware VM to AWS”

  1. Note: if you run into weird errors such as “–waiting on stdin–“, make sure your command text is clean. Copy / paste from this post can put some hidden characters into the command. To be safe, retype the whole thing.

  2. “Partition must be IDE – If you have any SCSI Devices, you should convert them to IDE. You may want to use a third party tool to do this such as Acronis.”

    Can you give me some detail? When I play with vmware workstation 10,whatever IDE or SCSI it fails.It alwayze said:” Instance does not have a volume attached at root (/dev/sda1)”

    1. Does your AWS Instance have a volume attached to it? When you select an instance and then scroll down in the description tab. You should see something like:

      Root device type: ebs
      Root device: /dev/sda1
      Block devices: /dev/sda1

      If not, you probably do not have a volume attached; so it has no place to put the image.

  3. Well,I’m glad to receive from you !
    The following is my all steps:

    D:\>ovftool “D:/vmware/win2008r2/win2008r2.vmx” “D:/vmware/win2008r2/win2008r2.ovf”
    Opening VMX source: D:/vmware/win2008r2/win2008r2.vmx
    Opening OVF target: D:/vmware/win2008r2/win2008r2.ovf
    Writing OVF package: D:/vmware/win2008r2\win2008r2.ovf
    Transfer Completed
    Completed successfully

    D:\>ec2-import-instance “D:/vmware/win2008r2/win2008r2-disk1.vmdk” -f VMDK -p Windows -a x86_64 -t m1.small –region ap-southeast-1 -b vmfile

    When it is uploaded completely, I create a volume in the aws console and attach to it.Then description tab as following:
    Root device type
    ebs
    Root device
    /dev/sda1
    Block devices
    /dev/sda1

    Then I check the task status,following is the result:
    D:\>ec2-describe-conversion-tasks –region ap-southeast-1 import-i-fgmvkz4k
    TaskType IMPORTINSTANCE TaskId import-i-fgmvkz4k ExpirationTime
    2014-04-09T06:48:04Z Status active StatusMessage Progress: 53% InstanceID i-d3ad68fb
    DISKIMAGE DiskImageFormat VMDK DiskImageSize 4350580224 VolumeId
    vol-ddbcbfd2 VolumeSize 40 AvailabilityZone ap-southeast-1a ApproximateBytesConverted 4350575488 Status completed

    D:\>ec2-describe-conversion-tasks –region ap-southeast-1 import-i-fgmvkz4k
    TaskType IMPORTINSTANCE TaskId import-i-fgmvkz4k ExpirationTime
    2014-04-09T06:48:04Z Status cancelled StatusMessage FirstBootFailure: This import request failed because the instance failed to boot and establish network connectivity. InstanceID i-d3ad68fb
    DISKIMAGE DiskImageFormat VMDK DiskImageSize 4350580224 VolumeId
    vol-ddbcbfd2 VolumeSize 40 AvailabilityZone ap-southeast-1a ApproximateBytesConverted 4350575488 Status completed

    Could you give me some adivces to fix it?

  4. Great post. The steps you have outlined for migration are quite detailed and accurate.
    Have you considered simply uploading your vmdks and running them as-is in AWS (without converting the VM or editing the networking)? You can actually do that with Ravello ‘s nested virtualization Saas http://www.ravellosystems.com .

Leave a Reply

Your email address will not be published. Required fields are marked *