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
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