Sub topic 8
Root volumes, AMIs and DeleteOnTermination
This chapter assumes you can launch EC2 instances and use the AWS CLI. It also assumes you know what an AMI is and that volumes and snapshots exist as separate objects. By the end you should be able to explain where a root volume comes from, decide what happens to it on termination, and change that behavior.
What a root volume is
The root volume holds the operating system that the instance boots from. An instance launched from an EBS-backed AMI gets a root volume that EBS creates from the snapshot the AMI references. An AMI (Amazon Machine Image) is a template made of launch permissions, a root device description, and block device mappings. The block device mappings point to snapshots.
Each launch creates a fresh volume from the snapshot. Changes you make on one instance do not affect the AMI or other instances launched from it. To capture those changes, you must create a new AMI.
Root device names
The root device name is set by the AMI, for example /dev/xvda or /dev/sda1. On Nitro instances the OS shows it as an NVMe device such as /dev/nvme0n1. Use the name from the AMI's block device mapping when you override settings, not the name the OS shows.
DeleteOnTermination
Each EBS volume attached to an instance has a DeleteOnTermination attribute. It controls whether the volume is deleted when the instance is terminated.
| Volume | Default value |
|---|---|
| Root volume | `true` |
| Other volumes attached at launch | `false` |
| Volumes attached after launch | `false` |
The attribute only applies to termination. Stopping an instance keeps all of its volumes. Detaching a volume does not delete it. A volume that survives termination keeps incurring charges until you delete it, so check for orphaned volumes after terminating instances.
Check the current value:
aws ec2 describe-instances \
--instance-ids i-0123456789abcdef0 \
--query 'Reservations[].Instances[].BlockDeviceMappings[]'Keep the root volume after termination on a running instance:
aws ec2 modify-instance-attribute \
--instance-id i-0123456789abcdef0 \
--block-device-mappings '[{"DeviceName":"/dev/xvda","Ebs":{"DeleteOnTermination":false}}]'You can also set it at launch with the --block-device-mappings option of aws ec2 run-instances. Replace /dev/xvda with your AMI's root device name.
Creating your own AMI
You can build an AMI from a configured instance:
aws ec2 create-image \
--instance-id i-0123456789abcdef0 \
--name web-base-2026-11-26 \
--no-rebootEBS snapshots every volume attached to the instance and registers an AMI that references them. Without --no-reboot, EC2 stops the instance briefly to get a consistent file system. With it, the snapshot is crash-consistent only, so in-flight writes may be missing.
Deregistering an AMI does not delete its snapshots. Delete the snapshots yourself, or you keep paying for them.
Common errors
- Terminating an instance and finding the data is gone, because the root volume used the default
true. - Using the OS device name (
/dev/nvme0n1) instead of the AMI's root device name in a block device mapping. - Deregistering AMIs and leaving their snapshots behind.
- Expecting a new AMI to include data from instance store volumes. It does not, because only EBS volumes are snapshotted.
Exercise
You launch an instance with one root volume and one extra data volume attached at launch, both with default settings. You terminate the instance. Which volumes remain, and how would you keep the root volume instead?
Show answer
The data volume remains, because volumes other than the root default to DeleteOnTermination=false. The root volume is deleted because its default is true. To keep the root volume, set DeleteOnTermination to false for the root device name, either at launch in --block-device-mappings or on a running instance with aws ec2 modify-instance-attribute.