Creating Amazon EBS Volumes and Snapshots
Topics
- Creating an Amazon EBS Volume
- Attaching the Volume to an Instance
- Describing Volumes and Instances
- Using an Amazon EBS Volume within an Instance
- Creating an Amazon EBS Snapshot
- Describing Snapshots
- Detaching an Amazon EBS Volume from an Instance
- Deleting an Amazon EBS Snapshot
- Deleting an Amazon EBS Volume
This section provides examples of how to create and use Amazon EBS volumes.
Creating 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.
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
Attaching the Volume to an Instance
This example attaches volume vol-4d826724
to instance i-6058a509
and exposes it as device /dev/sdh
.
To attach an Amazon EBS volume
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attaching 2008-02-14T00:15:00+0000
Describing Volumes and Instances
After creating Amazon EBS volumes and attaching them to instances, you can list them using the DescribeVolumes
and the DescribeInstances
operations.
DescribeVolumes
returns 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.
DescribeInstances
lists volumes that are attached to running instances.
To describe volumes
-
Enter the following command.
PROMPT>
Amazon EBS returns information about all volumes that you own.
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
To describe instances
-
Enter the following command.
PROMPT>
Amazon EBS returns information about all running instances and volumes attached to those instances.
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 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 vol-6682670f,vol-50957039
Using an Amazon EBS Volume within an Instance
Inside the instance, the Amazon EBS volume is exposed as a normal block device and can be formatted as any file system and mounted. This example creates an ext3 file system on the Amazon EBS volume and mounts it as /mnt/data-store.
To use an Amazon EBS volume
-
Enter the following command.
PROMPT>
-
Enter the following command.
PROMPT>
-
Enter the following command.
PROMPT>
Any data written to this file system is written to the Amazon EBS volume and is transparent to applications using the device.
Creating 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.
This example creates a snapshot of the vol-4d826724
Amazon EBS volume using the CreateSnapshot
function.
To create a snapshot
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
SNAPSHOT snap-78a54011 vol-4d826724 pending 2008-02-15T09:03:58+0000
The snapshot occurs asynchronously and the volume's status indicates "pending" until it completes.
Note | |
---|---|
For information on creating an Amazon EBS volume from a snapshot, refer to the Amazon Elastic Compute Cloud Developer Guide. |
Describing Snapshots
This example describes snapshots using the CreateSnapshot
function.
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%
When the snapshot is complete, its status will change to completed
and the percentage will change to 100%
.
Detaching 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.
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 detach an Amazon EBS volume
-
Enter the following command.
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
To verify the volume is no longer attached to the instance, use the DescribeVolumes
.
Deleting an Amazon EBS Snapshot
After a snapshot is no longer needed, it can be deleted. This example deletes a snapshot.
To delete a snapshot
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
SNAPSHOT snap-78a54011
Deleting 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 example deletes a volume.
To delete a volume
-
Enter the following command.
PROMPT>
Amazon EBS returns information similar to the following example.
VOLUME vol-4282672b