Are files saved on EBS volume? Are they not supposed to be saved? I'm confused
Asked Answered
A

2

6

So I create an instance using one of the Public AMI EBS Ubuntu flavors. I create an EBS volume and attach it to the instance. I format the volume and add an entry to /etc/fstab to mount it on /vol. I add mysql to the AMI and move the data files to the EBS volume I formatted and mounted at /vol. I then create an AMI from the running instance. Then I terminate the running instance.

I start a new instance using the freshly created AMI (with mysql on it). The /vol is mounted has the mysql data files - good, I expect that. Here's where I am confused. When I create any directory or files on the EBS volume /vol they aren't there any more after I terminate the instance and create a new one. The mysql stuff is there but no new stuff I created. Aren't those files and directory supposed to be there? Or am I misunderstanding how this works?

Allstar answered 18/6, 2012 at 3:53 Comment(0)
S
2

When you create an AMI, "Amazon EC2 powers down the instance, takes images of any volumes that were attached, creates and registers the AMI, and then reboots the instance." -Amazon. When the AMI is used to launch an instance, the images (snapshots) of the attached drives are used to create new volumes. It is these new volumes that are attached to the new instance, not your original EBS. (This generates lots of orphan volumes and snapshots with ongoing use.)

There is no automatic attaching of the EBS volume you created. What is automatically attached is the volume it creates at the time of launching the instance from your AMI! It creates this volume from the snapshot it made of your EBS at the time of the AMI creation!

The way to avoid clone volumes from being created and attached to new instances is simple: detach your volumes before making AMIs. You need to attach your EBS volumes manually with the EC2 Web Control Panel, or programmatically with .net or Java programming, scripting or command line tools.

Stater answered 30/6, 2012 at 22:26 Comment(0)
B
1

EBS volumes are not tied to an AMI, only to the literal instance you attach them to. When you created your AMI and a new instance from that, the EBS is not cloned, nor does it follow you to the new instance.

You could move the EBS drive to the new instance manually. Alternately you could snapshot the EBS volume & clone a new drive from that.

Boiled answered 18/6, 2012 at 6:10 Comment(2)
Ok. That's helpful understanding an EBS volume is not tied to an AMI. But why do I see a snapshot of the EBS volume as one of the block devices (under AMI attributes) after I create the AMI? Can't I save files on that EBS snapshot? Or can I have a volume attach automatically as a block device where I can save files?Allstar
Sounds like creating the AMI takes EBS snapshots for you. In which case new instances would get new copies of the EBS, but they would not be mutually shared: they'd be independent clones. The snapshots themselves are read-only.Boiled

© 2022 - 2024 — McMap. All rights reserved.