Using Amazon Elastic Block Store
Topics
- Amazon EBS API Overview
- How to Create an Amazon EBS Volume
- How to Attach the Volume to an Instance
- How to Describe Volumes and Instances
- How to Make an Amazon EBS Volume Available for Use
- How to Create an Amazon EBS Snapshot
- How to Describe Snapshots
- How to Detach an Amazon EBS Volume from an Instance
- How to Delete an Amazon EBS Snapshot
- How to Delete an Amazon EBS Volume
- Related Topics
This section provides examples of how to create and use Amazon Elastic Block Store (Amazon EBS) volumes.
Amazon EBS API Overview
To configure and use Amazon EBS, we provide eight API functions. This section provides a brief overview of each function. For information on Amazon EBS concepts, see Amazon Elastic Block Store.
-
CreateVolume—Creates a new Amazon EBS volume using the specified size or creates a new volume based on a previously created snapshot.
-
DeleteVolume—Deletes the specified volume.
This function does not delete any snapshots that were created from this volume.
-
DescribeVolumes—Describes all volumes, including size, source snapshot, Availability Zone, creation time, and status (
available
,in-use
). -
AttachVolume—Attaches the specified volume to a specified instance, exposing the volume using the specified device name.
A volume can only be attached to a single instance at any time. The volume and instance must be in the same Availability Zone and the instance must be running.
-
DetachVolume—Detaches the specified volume from the instance to which it is attached.
This operation does not delete the volume. The volume can be attached to another instance and will have the same data as when it was detached.
-
CreateSnapshot—Creates a snapshot of the volume you specify.
Once created, you can use the snapshot to create volumes that contain exactly the same data as the original volume.
-
DeleteSnapshot—Deletes the specified snapshot.
This function does not affect currently running Amazon EBS volumes, regardless of whether they were used to create the snapshot or were derived from the snapshot.
-
DescribeSnapshots—Describes all snapshots, including their source volume, snapshot initiation time, progress (percentage complete), and status (
pending
,completed
).
How to Create an Amazon EBS Volume
To use Amazon EBS, you first create a volume that can be attached to any Amazon EC2 instance within the same Availability Zone. This example creates an 800 GiB Amazon EBS volume.
AWS Management Console
To create an Amazon EBS volume
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Volumes in the Navigation pane.
The console displays a list of current volumes.
-
Click Create Volume.
The Create Volume dialog box appears.
-
Configure the following settings and click Create.
- Size of the volume (in GiB)
- Availability Zone in which to launch the instance
- The ID of the snaphsot from which you are launching the volume (optional)
Amazon EC2 begins creating the volume.
Command Line Tools
To create an Amazon EBS volume
-
Enter the following command.
PROMPT>
Amazon EBS returns information about the volume similar to the following example.
VOLUME vol-4d826724 800 us-east-1a available 2008-02-14T00:00:00+0000
-
To check whether the volume is ready, use the following command.
PROMPT>
Amazon EBS returns information about the volume similar to the following example.
VOLUME vol-4d826724 800 us-east-1a available 2008-07-29T08:49:25+0000
How to Attach the Volume to an Instance
This section describes how to attach a volume that you created to an instance.
Note | |
---|---|
Windows instances currently support devices xvda through xvdp. Devices xvda and xvdb are reserved by the operating system, xvdc is assigned to drive C:\, and, depending on the instance type, devices xvdd through xvde might be reserved by the instance stores. Any device that is not reserved can be attached to an Amazon EBS volume. For a list of devices that are reserved by the instance stores, see Instance Storage. |
AWS Management Console
To attach an Amazon EBS volume
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Volumes in the Navigation pane.
The console displays a list of current volumes.
-
Click Create Volume.
The Create Volume dialog box appears.
-
Select a volume and click Attach Volume.
The Attach Volume dialog box appears.
-
Select the instance to which the volume will attach from the Instance list box.
-
Select how the device is exposed to the instance from the Device list box.
-
Click Attach.
The volume is attached to the instance.
Command Line Tools
To attach an Amazon EBS volume
-
Enter the following command.
PROMPT>
volume_id
-iinstance_id
-ddevice
Amazon EBS returns information similar to the following.
ATTACHMENT
volume_id
instance_id
device
attachingdate_time
Example
This example attaches volume vol-4d826724
to instance i-6058a509
in Linux and UNIX and exposes it as device /dev/sdh
.
PROMPT>
ec2-attach-volume vol-4d826724 -i i-6058a509 -d /dev/sdh
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attaching 2008-02-14T00:15:00+0000
This example attaches volume vol-4d826724
to instance i-6058a509
in Windows and exposes it as device xvdf
.
PROMPT>
ec2-attach-volume vol-4d826724 -i i-6058a509 -d xvdf
ATTACHMENT vol-4d826724 i-6058a509 xvdf attaching 2008-02-14T00:15:00+0000
How to Describe Volumes and Instances
After creating Amazon EBS volumes and attaching them to instances, you should verify they are available.
AWS Management Console
To view information about an Amazon EBS volume
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Volumes in the Navigation pane.
The console displays a list of current volumes and the instances to which they are attached.
-
To view more information about a volume, select it.
Information about the volume appears in the lower pane.
Command Line Tools
To describe volumes, which lists information about all volumes that you own
-
Enter the following command.
PROMPT>
Amazon EBS returns the following information.
VOLUME vol-4d826724 us-east-1a 800 in-use 2008-02-14T00:00:00+0000 ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attached 2008-02-14T00:00:17+0000 VOLUME vol-50957039 13 us-east-1a available 2008-02-091T00:00:00+0000 VOLUME vol-6682670f 1 us-east-1a in-use 2008-02-11T12:00:00+0000 ATTACHMENT vol-6682670f i-69a54000 /dev/sdh attached 2008-02-11T13:56:00+0000
This information includes the volume ID, capacity, status (in-use or available) and creation time of each volume. If the volume is attached, an attachment line shows the volume ID, the instance ID to which the volume is attached, the device name exposed to the instance, its status (attaching, attached, detaching, detached), and when it attached.
To describe instances, which lists volumes that are attached to running instances
-
Enter the following command.
PROMPT>
Amazon EBS returns the following information.
RESERVATION r-e112fc88 416161254515 default INSTANCE i-3b887c52 ami-3fd13456 ec2-67-202-27-216.compute-1.amazonaws.com domU-12-31-38-00-35-94.compute-1.internal running gsg-keypair 0 m1.small 2007-11-26T13:20:35+0000 windows vol-4d826724 RESERVATION r-e612fc8f 416161254515 default INSTANCE i-21b63c22 ami-3fd13456 ec2-67-202-18-227.compute-1.amazonaws.com domU-12-31-38-00-39-28.compute-1.internal running gsg-keypair 0 m1.small 2007-11-26T13:21:51+0000 windows vol-6682670f
How to Make an Amazon EBS Volume Available for Use
Inside the instance, the Amazon EBS volume is exposed as a normal block device and can be formatted as any file system and mounted.
After making the Amazon EBS volume available for use, you can take snapshots of it for backup purposes or to use as baselines to launch new volumes.
Linux and UNIX
This section describes how to make a volume available to the Linux and UNIX operating system.
To create an ext3 file system on the Amazon EBS volume and mount it as /mnt/data-store
-
Enter the following command.
$
-
Enter the following command.
$
-
Enter the following command.
$
Any data written to this file system is written to the Amazon EBS volume and is transparent to applications using the device.
Windows
This section describes how to make a volume available to the Windows operating system.
To use an Amazon EBS volume
-
Log in to your instance using Remote Desktop.
-
On the taskbar, click Start, and then click Run.
-
Type diskmgmt.msc and click OK. The Disk Management utility opens.
-
Right-click the Amazon EBS volume, select New Volume, and follow the on-screen prompts.
Note If the New Volume option does not appear, select Format.
Any data written to this file system is written to the Amazon EBS volume and is transparent to applications using the device.
How to Create an Amazon EBS Snapshot
After writing data to an Amazon EBS volume, you can periodically create a snapshot of the volume to use as a baseline for new volumes or for data backup.
Note | |
---|---|
Snapshots occur asynchronously and the status settings of volumes indicate "pending" until they complete. For information on creating an Amazon EBS volume from a snapshot, see Amazon Elastic Block Store. |
AWS Management Console
To create a snapshot
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Snapshots in the Navigation pane.
The console displays a list of current snapshots.
-
Click Create Snapshot.
The Create Snapshot dialog box appears.
-
Select the volume to create a snapshot for and click Create.
Amazon EC2 begins creating the snapshot.
Command Line Tools
To create a snapshot
-
Enter the following command.
PROMPT>
volume_id
Amazon EBS returns information similar to the following example.
SNAPSHOT snap-78a54011 vol-4d826724 pending 2008-02-15T09:03:58+0000
How to Describe Snapshots
This section describes how to view snapshots that you created.
Note | |
---|---|
When the snapshot is complete, its status will change to |
AWS Management Console
To describe snapshots
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Snapshots in the Navigation pane.
The console displays a list of current snapshots and their status.
-
To view more information about a snapshot, select it.
Information about the snapshot appears in the lower pane.
Command Line Tools
To describe snapshots
-
Enter the following command.
PROMPT>
Amazon EBS returns information about all snapshots that you own.
SNAPSHOT snap-78a54011 vol-4d826724 pending 2008-02-15T09:03:58+0000 60%
How to Detach an Amazon EBS Volume from an Instance
An Amazon EBS volume can be detached from an instance by either explicitly detaching the volume or terminating the instance. This example unmounts the volume and explicitly detaches it from the instance. This is useful when you want to terminate an instance or attach a volume to a different instance.
Caution | |
---|---|
A volume must be unmounted inside the instance before being detached. Failure to do so will result in damage to the file system or the data it contains. |
To verify the volume is no longer attached to the instance, see How to Describe Snapshots.
AWS Management Console
To detach an Amazon EBS volume
-
Enter the following command from the command line.
#
umount -d
/dev/sdh
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Volumes in the Navigation pane.
The console displays a list of current volumes.
-
Select a volume and click Detach Volume.
A confirmation dialog box appears.
-
Click Yes, Detach.
The volume is detached from the instance.
Command Line Tools
To detach an Amazon EBS volume
-
Enter the following commands.
#
umount -d
/dev/sdh
PROMPT>
Amazon EBS returns information similar to the following example.
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh detaching 2008-02-14T00:00:17+0000
To detach an Amazon EBS volume by terminating the instance
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
INSTANCE i-6058a509 running shutting-down
How to Delete an Amazon EBS Snapshot
After a snapshot is no longer needed, it can be deleted. This section describes how to delete a snapshot.
AWS Management Console
To delete a snapshot
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Snapshots in the Navigation pane.
The console displays a list of current snapshots.
-
Select a snapshot and click Delete Snapshot.
A confirmation dialog box appears.
-
Click Yes, Delete.
The snapshot is deleted.
Command Line Tools
To delete a snapshot
-
Enter the following command.
PROMPT>
snapshot_id
Amazon EBS returns information similar to the following example.
SNAPSHOT snap-78a54011
How to Delete an Amazon EBS Volume
After a volume is no longer needed, it can be deleted. Once deleted, its data is deleted and it cannot be attached to any instance. However, you can store a snapshot of the volume that you can use to recreate it later.
This section describes how to delete a volume.
AWS Management Console
To delete a volume
-
Log in to the AWS Management Console and click the Amazon EC2 tab.
-
Click Volumes in the Navigation pane.
The console displays a list of current volumes.
-
Select a volume and click Delete Volume.
A confirmation dialog box appears.
-
Click Yes, Delete.
The volume is deleted.
Command Line Tools
To delete a volume
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
VOLUME vol-4282672b