Amazon Elastic Compute Cloud
User Guide (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Detaching an Amazon EBS Volume from an Instance

You can detach an Amazon EBS volume from an instance explicitly or by terminating the instance. However, a volume must be unmounted inside the instance before being detached. Failure to do so results in the volume being stuck in the busy state while it is trying to detach, which could possibly damage the file system or the data it contains.

Note

If an Amazon EBS volume is the root device of an instance, it cannot be detached unless the instance is in the stopped state.

If the root volume is detached from an instance with an AWS Marketplace product code, then the AWS Marketplace product codes from that volume are no longer associated with the instance.

This example unmounts the volume and then explicitly detaches it from the instance. This is useful when you want to terminate an instance or attach a volume to a different instance. To verify that the volume is no longer attached to the instance, see Describing Volumes.

AWS Management Console

To detach an Amazon EBS volume

  1. First, unmount the volume.

    For Linux/UNIX, use the following command to unmount the /dev/sdh device.

    # umount -d /dev/sdh

    For Windows, open Disk Management, right-click the volume to unmount, and select Change Drive Letter and Path. Then, select the mount point to remove and click Remove.

  2. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  3. Click Volumes in the navigation pane.

    The console displays a list of current volumes.

  4. Select a volume and click Detach Volume.

    A confirmation dialog box appears.

  5. Click Yes, Detach.

    The volume is detached from the instance.

Caution

If your volume stays in the detaching state, you can force the detachment using the Force Detach button. Forcing the detachment can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance doesn't get an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.

Command Line Interface

To detach an Amazon EBS volume explicitly

  1. For Linux/UNIX, use the following command to unmount the /dev/sdh device.

    # umount -d /dev/sdh

    For Windows, open Disk Management, right-click the volume to unmount, and select Change Drive Letter and Path. Then, select the mount point to remove and click Remove.

  2. To detach the volume, use the ec2-detach-volume command.

    PROMPT>  ec2-detach-volume vol-4d826724

    Amazon EC2 returns information similar to the following example.

    ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh detaching 2010-03-30T13:58:58+0000 

    Caution

    If your volume stays in the detaching state, you can force the detachment using the --force option of ec2-detach-volume. Forcing the detachment can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance doesn't get an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.

To detach an Amazon EBS volume by terminating the instance

  • Use the ec2-terminate-instances command.

    PROMPT>  ec2-terminate-instances i-6058a509

    Amazon EC2 returns information similar to the following example.

    INSTANCE    i-6058a509    running shutting-down 

API

To detach an Amazon EBS volume, use the DetachVolume action. Construct the following request.

https://ec2.amazonaws.com/
?Action=DetachVolume
&VolumeId=volume-id
&InstanceId=instance-id
&AUTHPARAMS

The following is an example response.

<DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> 
  <volumeId>vol-4d826724</volumeId>
  <instanceId>i-6058a509</instanceId>
  <device>/dev/sdh</device>
  <status>detaching</status>
  <attachTime>2008-05-08T11:51:50.000Z</attachTime>
  </DetachVolumeResponse>

Caution

If your volume stays in the detaching state, you can force the detachment using the Force option of DetachVolume. Forcing the detachment can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.