views:

4713

answers:

8

I have an EC2 instance with "instance store" device as a root device. Now, I would like to attach an EBS volume to that same instance, only that I want it to be the root device. Is that possible? What happens to the instance store device in such case?

Thanks in advance

+1  A: 

I don't know of any operating system that will let you replace the current root volume while the system is running. With EC2, normally you would start up a new instance with the configured volume.

kdgregory
+1  A: 

I'm not sure how easy it would be to convert an existing instance, but Amazon now offers the ability to boot directly from an EBS volume when you create a new instance.

gareth_bowles
+13  A: 

You could migrate your running instance to an EBS backed AMI. Here's how I did it:

  • Boot up a regular S3 AMI backed instance (or since you've already got an instance you're happy with, use that)
  • Make an EBS volume of the same size as your root sda1 partition (currently the default is 10G for an m1.small and possibly others)
  • Attach that EBS volume to a free block device on the instance using the web console or command line tools (e.g. /dev/sdd)
  • Stop the services on the instance (e.g. /etc/init.d/mysql stop etc.)
  • Copy the ephemeral root volume to the EBS volume:

dd bs=65536 if=/dev/sda1 of=/dev/sdd

  • Check the EBS volume for consistency:

fsck /dev/sdd

  • Mount the EBS volume onto the instance:

mount /dev/sdd /root/ebs-vol

  • Remove the /mnt entry from the fstab on your EBS vol:

vim /root/ebs-vol/etc/fstab

  • Unmout the EBS volume:

umount /dev/sdd

  • Create a snapshot of the EBS volume using the AWS management console (or command line API tools)
  • Make note of the snapshot id
  • Register the snapshot image with AWS and take note of the AMI id produced, when registering remember to specify the kernel and ramdisk image (these should be the same as those used in your current instance):

ec2-register -s snap-12345 -a i386 -d "Description of AMI" -n "name-of-image" -k aki-12345 -r ari-12345

  • To create an instance with more than 10G of persistent storage you have to use the cli tools. e.g. for 20G

ec2-run-instances ami-54321 -t m1.small -n 1 -g default --availability-zone=eu-west-1a -k ec2-key1 -b /dev/sda1=snap-12345:20:false

  • If you boot up an instance based on one of these AMIs with > default volume size, once it's started up you can do an online resize of the filesystem:

resize2fs /dev/sda1

AlexM
+1 nice instructions, although I don't think it's what the OP wants.
kdgregory
Thank you very much for the comprehensive answer. That's great
Sug
We basically did the same, but used rsync with excludes instead of dd, worked like a charm too.One more thing to take care of (I know it's obvious, but it happens over and over again): when creating your EBS volume, make sure to double check it's in the same region as the instance you want to attach it to ;-)
Michael Kohl
+1  A: 

You might also try the following tool to convert an instance-store AMI to an ebs-boot AMI: https://cloudyscripts.com/tool/show/2

elasticsecurity
@elasticsecurity great work on this tool!
Andy
A: 

Interesting read. I was curious about the swap space though. Why not just take the whole devices /dev/sda ?

joel
A: 

In place of the other long comment on here, I used the following command to do this:

ec2-register --snapshot snap-9eb4ecf6 --architecture i386 --name "Zenoss Enterprise 3.0 beta 2 on centOS" --description "This is from an install of zenoss core beta 1 and zenoss enterprise beta 2, both of version 3.0 (or internally 2.5.70 217). An ebs block device was attached, and the file system rsynced over, then ebs was snapshotted and this is basedd off that." --root-device-name /dev/sda1 --kernel aki-9b00e5f2

A: 

Hi - thanks for this howto, I found it very useful. However, to make sure you don't get a corrupted disk I would recommend remounting /dev/sda1 read-only before dd'ing:

mount -o remount,ro /dev/sda1

Uli
+1  A: 

AlexM has come up with good steps.

You would also be interested in checking this link: http://coderslike.us/2009/12/07/amazon-ec2-boot-from-ebs-and-ami-conversion/

EDIT: Another link: http://www.elastician.com/2009/12/creating-ebs-backed-ami-from-s3-backed.html

Gnanam