Amazon Elastic Compute Cloud
User Guide (API Version 2012-04-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid 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 either by explicitly detaching the volume or terminating the instance. However, a volume must be unmounted inside the instance before being detached. Failure to do so will result 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.

This example explicitly unmounts the volume and then detaches it from the instance. This is useful when you want to terminate an instance or attach a volume to a different instance.

[Note]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 will no longer be associated with the instance.

AWS Management Console

To detach an Amazon EBS volume

First unmount the volume from your instance drive.

  1. For Linux/UNIX, enter the following command.

    # 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]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 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.

Command Line Tools

To detach an Amazon EBS volume

  • Enter the following command.

    # umount -d /dev/sdh
    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]Caution

    If your volume stays in the detaching state, you can force the detachment using the --force option. 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. For more information about the --force option, go to ec2-detach-volume in the Amazon Elastic Compute Cloud Command Line Reference.

To detach an Amazon EBS volume by terminating the instance

  • Enter the following 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

  • Construct the following Query request.

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

    Following is an example response.

    <DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2012-04-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]Caution

    If your volume stays in the detaching state, you can force the detachment using the Force option. 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. For more information about the Force option, go to DetachVolume in the Amazon Elastic Compute Cloud API Reference.

To verify the volume is no longer attached to the instance, see Describing Volumes and Instances.