Amazon EC2 - Root Instance Storage Device with EBS

I have an EC2 instance with an instance storage device as the root device. Now I would like to add the EBS volume to the same instance, only that I would like it to be the root device. Is it possible? What happens to the instance storage device in this case?

Thank you in advance

+52
cloud amazon-web-services amazon-ec2 amazon-ebs
Jan 17 '10 at 21:26
source share
6 answers

You can port your executable instance to AMI with EBS support. Here is how I did it:

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

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

  • Check the scope of EBS for consistency:

fsck / dev / sdd

  • Install the EBS volume in the instance:

mount / dev / sdd / root / ebs-vol

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

vim / root / ebs-vol / etc / fstab

  • Turn off EBS volume:

umount / dev / sdd

  • Take a snapshot of the EBS volume using the AWS Management Console (or the command line API tools).
  • Pay attention to the snapshot identifier
  • Register the snapshot image using AWS and pay attention to the created AMI identifier, when registering, do not forget to specify the kernel image and ramdisk (they should be the same as in your current instance):

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

  • To create an instance with more than 10G persistent storage, you must use 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 load an instance based on one of these AMI s> default volume sizes, after starting it, you can perform an online file system change:

resize2fs / dev / sda1

+78
Jan 19 '10 at 17:31
source share

This can be done without creating a new AMI and without starting a new instance. When this has been done, the original root volume remains mounted on / dev / sda 1 (or where it was originally mounted. / Dev / sda 1 is used by default for many AMIs). The original root volume will not be connected to the file system - you will need to do this yourself using the mount command.

The technique requires the latest Ubuntu cores, which run in their 10.04 and 10.10 releases. Check out alestic.com for the latest AMI identifiers for these releases of Ubuntu. These latest kernels are configured to boot from any connected device with a volume label of uec-rootfs. If you use one of these kernels, all you need to do is change the volume label of the current (exact storage) root volume to another, change the volume label of the new root to uec-rootfs, and then reboot. If you are not using one of these cores, you cannot use this technique.

Here is the code. Put this in the file (reroot.sh) in the instance:

#! /bin/bash device=$1 # change the filesystem labels e2label /dev/sda1 old-uec-rootfs e2label $device uec-rootfs 

First, you attach the EBS volume that you want to use as the new root to one of the available devices /dev/sdf../dev/sdp. This can be done either through direct calls to the EC2 API, using the EC2 command-line API tools (ec2-attach-volume), or using a library such as boto or through the user interface of the AWS management console.

Then run reroot.sh script as the root user and provide the device to which you connected the new root volume as follows:

 sudo reroot.sh /dev/sdp 

This will do the dirty work. Then you just reboot:

 sudo shutdown -r now 

Viola.

To verify this, you must create an EBS volume that, as you know, will boot properly. I like to do this by snapshoting the root volume of supported EBS AMIs from the aforementioned Ubuntu AMIs. From this snapshot, you can create a new EBS boot volume in any availability zone. Make sure you can tell the difference between the original root volume of the executable instance and the new EBS root volume - before you perform the restart procedure described above, you can put the old root volume in the β€œmarker” file:

 cd touch this-is-the-original-root-volume 

Then, when you reboot and reboot, if this file exists in your home directory, you are still working with the original root volume. If this did not happen, then rebooting and rebooting worked.

Here are two examples of using this method with detailed explanations:

http://shlomoswidler.com/2011/02/play-chicken-with-spot-instances.html

http://shlomoswidler.com/2011/02/recapture-unused-ec2-minutes.html

+13
Mar 31 '11 at 6:45
source share

You can also try the following tool to convert the AMI of the storage instance to the AMI download of ebs: https://cloudyscripts.com/tool/show/2

+6
Mar 25
source share

AlexM came up with good steps.

You will also be interested in checking out 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

+1
Jul 14 '10 at 7:48
source share

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

0
Jan 17
source share

Instead of another long comment here, I used the following command:

ec2-register --snapshot snap-9eb4ecf6 --architecture i386 - name "Zenoss Enterprise 3.0 beta 2 on centOS" - description "This is from installing the beta version of zenoss beta-1 and zenoss-beta-2, as from version 3.0 (or internally 2.5.70 217). The block device ebs was connected, and the file system rsynced over, then ebs was removed, and this is based on this. " --root-device-name / dev / sda1 --kernel aki-9b00e5f2

0
Jun 16 '10 at 21:16
source share



All Articles