16

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

2 Answers 2

22

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.

3
  • Why can't I directly boot from that EBS volume? Dec 18, 2020 at 10:01
  • works really well for me. one thing to add is the new EC2 needs to be in the same Availability Zone as the old one. Otherwise, I couldn't attach the volume. Also worth adding to note other settings you might have with the EC2 such as tags, security group, IAM, IP, etc etc.
    – Laurence
    Dec 14, 2021 at 23:35
  • Does not work for me. You cannot detach the root volume unfortunately. Maybe this changed recently? Apr 13 at 2:23
0

Some times we need to give the exact device name like /dev/xvda for this to work. If the previous mounted volume is /dev/xvda, try to load with the same name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.