What Happens When an EC2 Root Volume Has DeleteOnTermination?
When an Amazon EC2 instance is terminated and the DeleteOnTermination attribute on its root Amazon Elastic Block Store volume is set to true, AWS automatically and permanently deletes that root EBS volume along with all the data stored on it. The instance transitions through the shutting-down state before reaching the terminated state, during which AWS detaches and destroys the root storage resource without creating an automatic backup or snapshot. Once the termination process completes, the deleted root volume cannot be recovered unless you previously created an EBS snapshot or configured a backup policy, though any additional non-root EBS volumes attached to the instance may persist if their individual DeleteOnTermination attributes are set to false.
Understanding the DeleteOnTermination Attribute
Amazon Elastic Block Store (EBS) provides block-level storage volumes
for use with Amazon EC2 instances. Every EBS volume attached to an
instance is governed by a block device mapping configuration, which
includes the DeleteOnTermination boolean attribute. This
attribute instructs the AWS control plane on how to handle the lifecycle
of the storage volume when its parent compute instance is permanently
destroyed.
By default, Amazon EC2 sets DeleteOnTermination to
true for the root EBS volume—the volume that holds the
operating system boot image and system files—while setting it to
false for any additional data volumes attached to the
instance. This default behavior is designed to prevent orphaned boot
volumes from accumulating in your AWS account and generating unnecessary
storage charges after temporary or scaled-down compute instances are
terminated.
Step-by-Step Lifecycle During Instance Termination
When you issue a TerminateInstances API call via the AWS
Management Console, AWS CLI, or an SDK, a specific sequence of events
unfolds:
- State Transition to Shutting-Down: The EC2 instance
immediately changes its state from
running(orstopped) toshutting-down. During this phase, the guest operating system receives an ACPI shutdown signal to gracefully stop running processes and flush file system buffers. - Evaluation of Block Device Mappings: The EC2
service inspects the block device mapping table associated with the
instance to check the
DeleteOnTerminationflag for every attached EBS volume. - Volume Detachment and Destruction: Because
DeleteOnTerminationis set totrueon the root volume, AWS detaches the root volume as soon as the instance halts and immediately initiates an asynchronous deletion of the EBS volume. - Final State Transition to Terminated: The instance
enters the
terminatedstate. The root volume disappears from your list of active EBS volumes, and billing for both the EC2 compute capacity and the root EBS storage ceases immediately.
If we denote the total monthly storage cost \(C\) of a root volume with size \(S\) (in gigabytes) and price rate \(R\) per gigabyte-month over an active fraction of the month \(t \in [0, 1]\), terminating the instance stops storage accumulation at time \(t\):
\[C = S \times R \times t\]
Once the volume is deleted at termination, \(S\) becomes \(0\) for the remainder of the billing cycle \((1 - t)\), eliminating ongoing storage costs for that volume.
Impact on Data and Additional Volumes
Understanding the distinction between the root volume and secondary volumes is critical for preventing accidental data loss:
- Root EBS Volume: All operating system
configurations, local logs, application binaries, and user files stored
on the root partition (such as
/dev/xvdaor/dev/sda1) are permanently erased. No automatic snapshot is taken prior to deletion. - Additional Attached EBS Volumes: Secondary EBS
volumes attached to the instance have
DeleteOnTerminationset tofalseby default. Unless explicitly modified totrue, these volumes are simply detached when the instance terminates, remaining in theavailablestate in your AWS account with their data intact. - EBS Snapshots: Existing Amazon EBS snapshots that were previously created from the root volume are unaffected by the termination and deletion of the root volume. Snapshots are stored independently in Amazon S3 managed storage.
How to Check the Current DeleteOnTermination Setting
Before terminating an instance, you can inspect the current
DeleteOnTermination status of its root volume using the AWS
CLI. Run the describe-instances command and query the
BlockDeviceMappings array:
aws ec2 describe-instances \
--instance-ids i-0123456789abcdef0 \
--query "Reservations[*].Instances[*].BlockDeviceMappings[*].[DeviceName,Ebs.VolumeId,Ebs.DeleteOnTermination]" \
--output tableIf the output shows True next to the root device name
(for example, /dev/xvda), the volume will be destroyed upon
termination.
How to Prevent Root Volume Deletion Before Terminating
If you want to terminate an EC2 instance but preserve its root EBS
volume for forensic analysis, data recovery, or attaching to a new
instance, you can modify the DeleteOnTermination attribute
while the instance is still running or stopped. You do not need to
reboot the instance to change this setting.
Using the AWS CLI, execute the modify-instance-attribute
command:
aws ec2 modify-instance-attribute \
--instance-id i-0123456789abcdef0 \
--block-device-mappings "[{\"DeviceName\": \"/dev/xvda\",\"Ebs\":{\"DeleteOnTermination\":false}}]"Once updated to false, terminating the EC2 instance will
leave the root EBS volume in the available state in your
account rather than deleting it.
Best Practices for Protecting Root Volume Data
To avoid unintended data loss when working with ephemeral or replaceable EC2 instances, follow these operational best practices:
- Store Persistent Data on Separate Volumes: Keep application databases, user uploads, and critical state on secondary EBS volumes, Amazon EFS, or Amazon S3 rather than on the root operating system volume.
- Automate Snapshots with Amazon Data Lifecycle Manager (DLM): Configure automated snapshot policies so that periodic backups of critical volumes exist even if an instance is accidentally terminated.
- Enable Termination Protection: For production instances where the root volume holds indispensable state, enable EC2 termination protection to prevent accidental termination via the console, CLI, or API until the protection flag is explicitly disabled.