Booting an EC2 instance from an existing EBS volume

amazon ec2amazon-ebs

I'm just getting up to speed on AWS and had a question about using an existing EBS volume as a boot device for an EC2 instance.

It looks like a lot of the instances create an EBS volume for their boot devices. In the situation where the EBS volume has been setup so that it is not deleted when the instance is terminated, is it possible to use that EBS volume as the boot/root device for a new instance?

For example say I have an instance using an EBS volume as the root device that is running on a hypervisor that crashes. Can I boot another instance using that EBS volume?

I can see that you could take a snapshot of the EBS volume and then create an AMI from that snapshot. So I guess that is one way to get it back, but I was curious if there was a more direct way?

I realize that ideally instances are throw away, but I'm just curious from a learning PoV.

Thanks,
Joe

Best Answer

EBS volumes can be attached and detached from EC2 instance.

If you have an EC2 instance that crashes for some reason, you can move the root volume to another EC2 intance.

  1. Launch a new EC2 instance.
  2. Stop that EC2 instance.
  3. Detach the root volume from the new instance. Make note of the device name that it was attached as (such as /dev/sda1).
  4. Detach the root volume from the original instance.
  5. Attach the root volume from the original instance to the new instance, using the same device name (such as /dev/sda1).
  6. Start your new instance.

Technically, it can be done.

However, you may encounter the same problem that you had with the original EC2 instance since you're booting from the original root volume.

Another thing you can do is to attach the original root volume as a non-root volume on your new EC2 instance, such as /dev/sdb1. If you do this, you can examine the data on the volume to determine the cause of the crash and perhaps fix it.

One more thing, while you can make an AMI image out of an EBS snapshot, you can also make AMI images directly from the EC2 instance instead. As a process, this often is simpler.