Add block device mappings to Amazon EC2 instance
By default, an instance that you launch includes any storage devices specified in the block device mapping of the AMI from which you launched the instance. You can specify changes to the block device mapping for an instance when you launch it, and these updates overwrite or merge with the block device mapping of the AMI.
Limitations
-
For the root volume, you can only modify the following: volume size, volume type, and the Delete on Termination flag.
-
When you modify an EBS volume, you can't decrease its size. Therefore, you must specify a snapshot whose size is equal to or greater than the size of the snapshot specified in the block device mapping of the AMI.
Contents
Update the block device mapping when launching an instance
You can add EBS volumes and instance store volumes to an instance when you launch it. Note that updating the block device mapping for an instance doesn't make a permanent change to the block device mapping of the AMI from which it was launched.
Update the block device mapping of a running instance
You can use the modify-instance-attribute AWS CLI command to update the block device mapping of a running instance. You do not need to stop the instance before changing this attribute.
aws ec2 modify-instance-attribute --instance-id i-
1a2b3c4d
--block-device-mappings file://mapping.json
For example, to preserve the root volume at instance termination, specify the following
in mapping.json
.
[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": false } } ]
Alternatively, you can use the -BlockDeviceMapping
parameter with the
Edit-EC2InstanceAttribute command (AWS Tools for Windows PowerShell).
View the EBS volumes in an instance block device mapping
You can easily enumerate the EBS volumes mapped to an instance.
Note
For instances launched before the release of the 2009-10-31 API, AWS can't display the block device mapping. You must detach and reattach the volumes so that AWS can display the block device mapping.
View the instance block device mapping for instance store volumes
The instance type determines the number and type of instance store volumes that are available to the instance. If the number of instance store volumes in a block device mapping exceeds the number of instance store volumes available to an instance, the additional volumes are ignored. To view the instance store volumes for your instance, run the lsblk command (Linux instances) or open Windows Disk Management (Windows instances). To learn how many instance store volumes are supported by each instance type, see Amazon EC2 instance type specifications.
When you view the block device mapping for your instance, you can see only the EBS volumes, not the instance store volumes. The method you use to view the instance store volumes for your instance depends on the volume type.
NVMe instance store volumes
You can use the NVMe command line package, nvme-cli
[ec2-user ~]$
sudo nvme list
The following is example output for an instance. The text in the Model column indicates
whether the volume is an EBS volume or an instance store volume. In this example, both
/dev/nvme1n1
and /dev/nvme2n1
are instance store
volumes.
Node SN Model Namespace ---------------- -------------------- ---------------------------------------- --------- /dev/nvme0n1 vol06afc3f8715b7a597 Amazon Elastic Block Store 1 /dev/nvme1n1 AWS2C1436F5159EB6614 Amazon EC2 NVMe Instance Storage 1 /dev/nvme2n1 AWSB1F4FF0C0A6C281EA Amazon EC2 NVMe Instance Storage 1 ...
You can use Disk Management or PowerShell to list both EBS and instance store NVMe volumes. For more information, see Map NVMe disks on Amazon EC2 Windows instance to volumes.
HDD or SSD instance store volumes
You can use instance metadata to query the HDD or SSD instance store volumes in the block device mapping. NVMe instance store volumes are not included.
The base URI for all requests for instance metadata is
http://169.254.169.254/latest/
. For more information, see Use instance metadata to manage your EC2
instance.
First, connect to your running instance. From the instance, use this query to get its block device mapping.
The response includes the names of the block devices for the instance. For example, the
output for an instance store–backed m1.small
instance looks like
this.
ami
ephemeral0
root
swap
The ami
device is the root device as seen by the instance. The instance
store volumes are named ephemeral[0-23]
. The swap
device
is for the page file. If you've also mapped EBS volumes, they appear as ebs1
,
ebs2
, and so on.
To get details about an individual block device in the block device mapping, append its name to the previous query, as shown here.
First, connect to your running instance. From the instance, use this query to get its block device mapping.
PS C:\>
Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/block-device-mapping/
The response includes the names of the block devices for the instance. For example, the
output for an instance store–backed m1.small
instance looks like
this.
ami
ephemeral0
root
swap
The ami
device is the root device as seen by the instance. The instance
store volumes are named ephemeral[0-23]
. The swap
device
is for the page file. If you've also mapped EBS volumes, they appear as ebs1
,
ebs2
, and so on.
To get details about an individual block device in the block device mapping, append its name to the previous query, as shown here.
PS C:\>
Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/block-device-mapping/ephemeral0