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
The instance store is ideal for temporary storage, because the data stored in instance store volumes is not persistent through instance stops, terminations, or hardware failures. For data you want to retain longer, or if you want to encrypt the data, use Amazon Elastic Block Store (Amazon EBS) volumes instead.
An EBS Volumes can be up to 16TB in size. EBS volumes are like virtual hard disks that are attached to the server for storage. So by default Amazon EC2 instance, takes an EBS volume as a root device. You can, of course, add additional volumes for future purposes.
For each instance store volume to add, choose Add New Volume, from Volume Type select an instance store volume, and from Device select a device name. The number of available instance store volumes depends on the instance type. Complete the wizard and launch the instance.
You could migrate your running instance to an EBS backed AMI. Here's how I did it:
dd bs=65536 if=/dev/sda1 of=/dev/sdd
fsck /dev/sdd
mount /dev/sdd /root/ebs-vol
vim /root/ebs-vol/etc/fstab
umount /dev/sdd
ec2-register -s snap-12345 -a i386 -d "Description of AMI" -n "name-of-image" -k aki-12345 -r ari-12345
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
resize2fs /dev/sda1
This can be done without creating a new AMI and without launching a new instance. When it's done the original root volume stays attached on /dev/sda1 (or wherever it was originally mounted. /dev/sda1 is the default for many AMIs). The original root volume will not be mounted to the filesystem - you'd need to do that yourself via the "mount" command.
The technique requires the recent Ubuntu kernels, the ones that run in their 10.04 and 10.10 releases. Check out alestic.com for the most recent AMI IDs for these Ubuntu releases. These recent kernels are configured to boot from any attached device whose volume label is "uec-rootfs". If you are running one of these kernels all you need to do is to change the volume label of the current (instance-store) root volume to something else, change the volume label of the new root to uec-rootfs, and then reboot. If you're not running one of these kernels, you can't use this technique.
Here's the code. Put this in a file (reroot.sh) on the instance:
#! /bin/bash device=$1 # change the filesystem labels e2label /dev/sda1 old-uec-rootfs e2label $device uec-rootfs
First you would attach the EBS volume you want to act as the new root to one of the available devices /dev/sdf../dev/sdp. This can be done either with direct EC2 API calls, with the EC2 Command Line API tools (ec2-attach-volume), or with a library such as boto, or via the AWS Management Console UI.
Then, run the reroot.sh script as root, and provide the device you attached the new root volume on, as follows:
sudo reroot.sh /dev/sdp
This will do the dirty work. Then you simply reboot:
sudo shutdown -r now
Viola.
To test this you should create an EBS volume that you know will boot properly. I like to do that by snapshotting the root volume of the EBS-backed AMIs from those above mentioned Ubuntu AMIs. From that snapshot you can create a new, bootable EBS volume in any Availability Zone. Make sure you can tell the difference between the running instance's original root volume and the new EBS root volume - before you run the reroot procedure above you can put in a "marker" file on the old root volume:
cd touch this-is-the-original-root-volume
Then, when you reroot and reboot, if that file exists in your home directory you're still running with the original root volume. If it's not there, then the reroot-and-reboot worked.
Here are two example use cases for this technique, with thorough explanations:
http://shlomoswidler.com/2011/02/play-chicken-with-spot-instances/
http://shlomoswidler.com/2011/02/recapture-unused-ec2-minutes/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With