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 section describes how to attach a volume that you created to an instance.
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
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. |
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.
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 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
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.
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.
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, see Amazon Elastic Block Store. |
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 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.
#
umount -d
/dev/sdh
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