1
votes

I ran into a problem the other day while cloning a github repo, and all of a sudden my EC2 Instance (EC2 A) became completely unusable. My question is: how can I re-attach an EBS Volume from an EC2 Instance that I terminated to a new EC2 Instance that I just created?

Step-by-Step of the problem:

0) broke my first EC2 Instance (EC2 A).

1) created a snapshot of the EBS Volume (EBS Volume A) attached to EC2 A.

2) stopped EC2 A.

3) detached EBS Volume A.

4) terminated EC2 A.

Then...

5) created a brand new EC2 Instance (EC2 B) with a new EBS Volume automatically created (EBS Volume B), which is currently attached to EC2 B.

6) set it all up (apache, mysql, php, other plugins, etc...)

7) Now I want to access my data from EBS Volume A. I do not care about anything in EBS Volume B. Please Advise...

Thank you so much for your time!

1
This question would be better asked on serverfault.comEric Hammond

1 Answers

2
votes

Yes, you can attach an existing EBS volume to an EC2 instance. There are a number of ways to do this depending on your tools of preference. I prefer the command line tools, so I tend to do something like:

ec2-attach-volume --instance-id i-XXXXXXXX /dev/sdh --device vol-VVVVVVVV

You could also do this in the AWS console:

https://console.aws.amazon.com/ec2/home?#s=Volumes

Right click on the volume, then select [Attach Volume]. Select the instance and enter the device (e.g., /dev/sdh).

After you have attached the volume to the instance, you will want to ssh to the instance and mount the volume with a command like:

sudo mkdir -m000 /vol2
sudo mount /dev/xvdh /vol2

You can then access your old data and configuration under /vol2

Note: The EBS volume and the EC2 instance must be in the same region and in the same availability zone to make the attachment.