domingo, 27 de julio de 2014

AWS: Convert T1 instances to T2

AWS released new T2 instance type recently. New instance type only support HVM virtualization. What happen if you have a T1 PVM instance and want to move to T2? Because  PVM virtualization is not supported in T2, you can't directly change instance type using AWS EC2 web console. But you can convert it! To do it, I suggest you to follow next guide.

NOTE: If you are going to use this guide with production instances is highly recommended to create an image before proceed.

The procedure has been tested using Amazon Linux instances, but should work with any other Linux flavors: Ubuntu, SUSE, Redhat, etc.

Imagine you have one T1 micro PVM instance with next characteristics:

First, login to the instance and ensure is updated. If not, I recommend you to update the instance to the latest stable version using apt-get/yum commands:

Wait until instance is updated and reboot, if needed. Verify everything is correct. I´m also going to create a file named info.txt just to know this is the root volume associated to my T1 PVM instance:

Now, launch a new T2 instance. Don't forget to:
  • Select a compatible T2 AMI closer to your current T1 AMI with same architecture (32 or 64bits)
  • Select same size for root volume
  • Select same instance type (if original T1 instance is t1.micro, select t2.micro)
  • Launch T2 instance in the same availability zone (AZ) of your current T1 instance

Stop both instances. Now, go to AWS EC2 web console, Volumes section and:
  • Set an easy-to-remember name for each volume
  • Review attachment information of T2 HVM root volume (at least) and take note of device name. In my example: /dev/xvda. We'll need this information later.
  • Detach both root volumes
After these steps, both volumes should be available in AWS console:

Now, we need to launch a new instance. We'll use this instance to perform required changes, so work instance seems a good name. Don't forget to launch this new instance in the same availability zone of T1 and T2 instances:

Attach T1 PVM and T2 HVM volumes as secondary volumes in work instance:

As you can see, T1 PVM volumes has been attached in /dev/sdf device and T2 HVM volume in /dev/sdg device. This information is important because will help us to identify volumes inside work instance.

Now, login to the work instance and run dmesg command to know how volumes are identified by the kernel:

According to dmesg information, /dev/sdf (PVM volume) is associated to /dev/xvdf and /dev/sdg (HVM volume) to /dev/xvdg1. Create two mountpoint directories, one for each device, and mount them. Required commands:
  • sudo mkdir /pvm
  • sudo mkdir /hvm
  • sudo mount /dev/xvdf /pvm
  • sudo mount /dev/xvdg1 /hvm

In the next step we're going to backup current HVM kernel. To ensure maximum compatibility, preserve current HVM kernel is recommended. You can skip this step if you're 100% sure PVM kernel will work with the new T2 HVM instance. You will need to backup /boot directory inside /hvm and modules associated to the running kernel. To know what is the active kernel, review /hvm/boot/grub/menu.lst file. Will give you the information to know what modules are required to backup:

For our example, next commands will be required:
  • sudo cp -prf /hvm/boot /tmp/
  • cat /hvm/boot/grub/menu.lst . Active kernel is tagged 3.10.42-52.145.amzn1.x86_64. So, command to backup modules will be:
  • sudo cp -prf /hvm/lib/modules/3.10.42-52.145.amzn1.x86_64 /tmp/

Next steps will be: remove all files from HVM volume, copy files from PVM volume to HVM and restore HVM kernel. The commands:
  • sudo rm -rf /hvm/*
  • sudo cp -prf /pvm/* /hvm/
  • sudo rm -rf /hvm/boot
  • sudo cp -prf /tmp/boot /hvm/
  • sudo cp -prf /tmp/3.10.42-52.145.amzn1.x86_64/ /hvm/lib/modules/

Important: review root label in kernel configuration, fstab file and root filesystem. In order to work, they need to be the same. In previous screenshot, volume labeled as / will be use as root device by kernel configuration and fstab file. Requesting information about HVM volume label, I get the same value. Finally, HVM volume filesystem is ext4. So, nothing additional is required in my example. If you find differences in your environment, you'll need to modify /hvm/boot/grub/menu.lst, /hvm/etc/fstab and/or HVM volume label to solve it. Otherwise, instance start-up will fail.

If all is correct, umount both volumes:
  • sudo umount /pvm
  • sudo umount /hvm
Go to AWS EC2 web console, Volumes section, and detach both secondary volumes (T1 PVM and T2 HVM volumes) from work instance.

Now, attach HVM volume as T2 instance root volume. In AWS EC2 web console, Volumes section (Important: don't forget to put as device name the value you copied previously. In my example: /dev/xvda):

Optional: If T1 instance has an Elastic IP assigned, I suggest you to associate this IP to the new T2 instance. To do it, just disassociate Elastic IP from T1 instance and associate to the new T2 instance in Elastic IPs section. Example:

All done. Now you can start and login to the new T2 instance using the old Elastic IP. As you can see in the next screenshot, files contained are the same T1 PVM root volume, but using the new T2 instance type:

If after procedure you experience issues during T2 instance start-up, in AWS EC2 web console select the instance, right click and select Get System Log. If there is any issue associated to the kernel, filesystem or volume label; useful information for troubleshooting will be displayed here.

When all work as expected, you can remove old T1 and work instance. Be sure you won't need them before remove because as soon as you delete them won't be able to access again.

34 comentarios:

Anónimo dijo...

Thanks a lot! I was be able to accomplish the migration from t1.micro (PV) to t2.micro (HVM) following this post... great job

Francisco dijo...

Very nice post, I was also able to accomplish the task. Thanks!

JShort dijo...

Shouldn't this be:

sudo cp -prf /tmp/3.10.42-52.145.amzn1.x86_64 /hvm/lib/modules/

Note the lack of trailing slash on the 1st positional argument.

Xianjun Feng dijo...

Thanks! The clearest tutorial I have read. It helps me a lot when i upgrade my ubuntu-t1.micro instance to t2.micro.

Yuri Zhylyuk dijo...

Thank you Javier! Very clear instructions for migrating from t1, to t2 EC2 micro instances.

Keith Gillette dijo...

Thanks for the clear, step-by-step instructions! I was successful in migrating from a t1.micro instance to a t2.micro. Unfortunately, I can't seem to reassign the Elastic IP (and DNS record) from the t1.micro instance, which appears to be in EC2-Classic, while the t2.micro is in EC2-VPC. Equally clever recommendations for work-arounds appreciated!

Manu dijo...

Funciona genial!!

Andrew Melvin dijo...

Even with google translate! saved me hours. thank you

Stefano Lazzaro dijo...

Is it suitable even to migrate a m1.small PV to t2.medium HVM? Thanks

Javier Sianes dijo...

Stefano: yes, it is.

Thomas dijo...

Thx man, worked like a charm! What a timesaver, really appreciate it!

吾人‧祖絲 dijo...
Este comentario ha sido eliminado por el autor.
Ember dijo...

Thank you for the article. :) One extra thing I had to do was setup the aws cli and migrate my Elastic IP to be on the VPC network.

Mike dijo...

Very useful. Despite my own stupidity I did an ubuntu migration very smoothly.

JB dijo...

Thanks so much for this! I'd been lazy on porting my servers, primarily because I had no Idea how to do it. Very well done!

Abiya Carol dijo...

I agree with your points but i can't understand what's logic behind by including with the number? Why most of the marketers will suggest that one? Is there any important factor within that please convey me.....

Digital Marketing Training in Chennai

Hadoop Training in Chennai

Unknown dijo...

I migrated my Ubuntu 14.04 from t1 to t2 using your guide. Gracias!

Sneha rathod dijo...

Thanks for updating your information for more updates AWS Online Training

siva dijo...

This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.
Thank you for this blog. This for very interesting and useful.
Java training in Chennai
Java training in Bangalore
Java online training
Java training in Pune
Java training in Bangalore|best Java training in Bangalore

service care dijo...

Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you.
Keep update more information..
xiaomi service centre chennai
redmi service center
mi service center
redmi service center near me
redmi mobile service centre in chennai
redmi note service center in chennai

suresh H dijo...

Hi, Great.. Tutorial is just awesome useful to improve my knowledge as updated one, keep blogging.

Splunk Training | Splunk Training Institute | Splunk Training in Chennai | Splunk Training Institute in Chennai

Python Training | Python Course | Python Training in Chennai | Python Course in Chennai

service care dijo...

I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future lenovo service center in velachery
lenovo service center in porur
lenovo service center in vadapalani

service care dijo...

Your blog’s post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
redmi service center
mi service center
redmi service center near me
redmi mobile service centre in chennai

service care dijo...
Este comentario ha sido eliminado por el autor.
service care dijo...

This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
lg mobile service center in porur
lg mobile service center in vadapalani

service care dijo...

This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.
oppo service center chennai

service care dijo...

Hi! Thank you for the share this information. This is very useful information for online blog review readers. Keep it up such a nice posting like this.
best mobile service center in chennai
mobile service center in velacherry

service care dijo...

Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definitely interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
lg mobile service center near me
lg mobile service center in velachery

digitalsourabh dijo...

PHP Training in Bhopal
Graphic designing training in bhopal
Python Training in Bhopal
Android Training in Bhopal
Machine Learning Training in Bhopal
Digital Marketing Training in Bhopal

shivani dijo...

An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training

spot dijo...

Excellant your post and blog.
It’s amazing in support of me totruly have a blog site, which will be valuable meant for my knowledge. Thanks admin
Transcription in USA
Transcription in USA
Transcriptions in US
Medical Transcription in USA
Medical Transcription Companies in USA
best Medical Transcription Companies in USA
Medical Transcription Services USA
Transcription companies in USA
Transcription services in USA
transcription companies in us
Transcription USA
General Transcription companies in US
Medical Transcriptionist in us

shivani dijo...

A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training

shivani dijo...

A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training

Techxinx dijo...

Thanks for sharing excellent information.If you Are looking Best smart autocad classes in india,
provide best service for us.
autocad in bhopal
3ds max classes in bhopal
CPCT Coaching in Bhopal
java coaching in bhopal
Autocad classes in bhopal
Catia coaching in bhopal