Tuesday, November 25, 2014

Importing raw VM kvm image to Amazon AWS


Note: I am assuming that you have already configured ec2 tools, system path and environment variables

1. First create a VM host on your KVM of appropriate size (You don’t have to create a specified size that you on AWS here). Smaller the size better to upload and less you will be charged
In my case I created 8 GB size with two partition (one /boot and another /) on same volume.
AWS recommends to have / and /boot on one vol otherwise it won’t work.
2. During installation, make sure you are getting IP address dynamically.
3. Once installation is complete, disable and stop iptables
#chkconfig iptables off
#/etc/init.d/iptables stop
4. create a file named authorized_keys inside /root/.ssh directory and paste public key in the file
5. Try to login from another host
#ssh -i <key> root@<IP_ADDRESS>
if you are able to login without password then you are good proceed to another step
6.  update your OS
#yum update -y
7.  Once update is done reboot your system
8. Install all necessary packages/software you need, make necessary changes and shutdown your system
9. Now upload your VM to AWS using ec2-import-instance command
#ec2-import-instance test.img -f RAW -p Linux -t m3.xlarge -a x86_64 -b vmbucket  -s 50 GiB -o <ACCESS_KEY> -w <Secret KEY> –region us-west-2
Note:  you can upload Linux only to certain types of ec2 instance
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/VMImportPrerequisites.html
Using -s option you can specify the size of EBS vol you want to create for ec2 instance
10. You can monitor the progress using
#ec2-describe-conversion-tasks import-i-ffrs53ha -O <ACCESS_KEY> -W <SECRET_KEY> –region us-west-2
11. Once the conversion is complete, it will create a EBS vol of size and instance type you specified (It takes some time to create a vol even though ec2-describe-conversion-tasks reports process completion, so please be patient )
12. start your instance and you are good to go

5 comments: