We can launch a new EC2 instance with e.g.:
$ aws ec2 run-instances \
--image-id ami-0179dbab9bb7ab8f7 \
--count 1 \
--instance-type t3.medium \
--key-name my-key-pair \
--security-group-ids sg-0eb70243855088ab1
Note
here that we didn't need to explicitly specify Storage as default
settings based on storage type set in AMI will be applied. This is the
same as leaving default values in the Storage section when launching a
new EC2 instance in AWS Console:
So, what is the storage (virtual hard disk...) where our EC2 instance boots from and where OS and applications are stored? It is called a root device.
From O’Reilly's AWS Certified Developer - Associate Guide by Vipul Tankariya, Bhavin Parmar:
Root device types
While
choosing an AMI, it is essential to understand the root device type
associated with the AMI. A bootable block device of the EC2 instance is
called a root device. As EC2 instances are created from an AMI,
it is very important to observe the root device type at the AMI. An AMI
can have either of two root device types:
- Amazon EBS-backed AMI (uses permanent block storage to store data)
- Instance store-backed AMI (which uses ephemeral block storage to store data)
While creating an EC2 instance using a web console, we can see whether an AMI is EBS- or instance-backed.
AWS EC2 Root Device Volume
When an EC2 instance is launched from an AMI, the root device volume
contains the image used to boot the instance—mainly the operating
system, all the configured services, and applications. This volume can
be backed by either EBS or Instance Store (both are explained in the
following sections) and can be configured when the AMI is created.
The
Vector AMI is backed by EBS. This means that when you launch an EC2
instance from the Vector AMI, you will have at least one EBS volume
attached to the instance, which will be the root volume. It will contain
the operating system, a configured and ready-to-use Vector
installation, sample data, and the sample database.
The root device
is the virtual device that houses the partition where your filesystem
is stored -- ephemeral d---evices have it running on the same physical host
at the server, and EBS devices have it mounted using iSCSI.
Amazon EC2 instance root device volume - Amazon Elastic Compute Cloud
Amazon EBS volumes - Amazon Elastic Compute Cloud
AWS EBS Ultimate Guide & 5 Bonus Features to Try
AWS — Difference between EBS and Instance Store | by Ashish Patel | Awesome Cloud | Medium
What Is EBS?. EBS is a popular cloud-based storage… | by Eddie Segal | Medium
Create an Amazon EBS volume - Amazon Elastic Compute Cloud
Tutorial: Get started with Amazon EC2 Linux instances - Amazon Elastic Compute Cloud
It is important knowing what happens with EBS volumes when we stop and when we terminate EC2 instance.
From What is the difference between terminating and stopping an EC2 instance?
Amazon
supports the ability to terminate or stop a running instance. The
ability to stop a running instance is only supported by instances that
were launched with an EBS-based AMI. There are distinct differences
between stopping and terminating an instance.
Terminate Instance
When
you terminate an EC2 instance, the instance will be shutdown and the
virtual machine that was provisioned for you will be permanently taken
away and you will no longer be charged for instance usage. Any data that
was stored locally on the instance will be lost. Any attached EBS
volumes will be detached and deleted.
Stop Instance
When
you stop an EC2 instance, the instance will be shutdown and the virtual
machine that was provisioned for you will be permanently taken away and
you will no longer be charged for instance usage. The key difference
between stopping and terminating an instance is that the attached
bootable EBS volume will not be deleted. The data on your EBS volume
will remain after stopping while all information on the local
(ephemeral) hard drive will be lost as usual. The volume will continue
to persist in its availability zone. Standard charges for EBS volumes
will apply. Therefore, you should only stop an instance if you plan to
start it again within a reasonable timeframe. Otherwise, you might want
to terminate an instance instead of stopping it for cost saving
purposes.
The ability to stop an instance is only supported on
instances that were launched using an EBS-based AMI where the root
device data is stored on an attached EBS volume as an EBS boot partition
instead of being stored on the local instance itself. As a result, one
of the key advantages of starting a stopped instance is that it should
theoretically have a faster boot time. When you start a stopped instance
the EBS volume is simply attached to the newly provisioned instance.
Although, the AWS-id of the new virtual machine will be the same, it
will have new IP Addresses, DNS Names, etc. You shouldn't think of
starting a stopped instance as simply restarting the same virtual
machine that you just stopped as it will most likely be a completely
different virtual machine that will be provisioned to you.
If we try to terminate an instance via AWS Console we'll see a warning which states:
On an EBS-backed instance, the default action is for the root EBS volume to be deleted when the instance is terminated. Storage on any local drives will be lost.
---