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. |
Note | |
---|---|
If an Amazon EBS volume is the root device of an instance, it cannot be detached. |
How To
To detach an Amazon EBS volume
-
If you are using SOAP, construct the following request:
<DetachVolume xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <volumeId>
volume-id
</volumeId> <instanceId>instance-id
</instanceId> </DetachVolume> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DetachVolume &VolumeId=
volume-id
&InstanceId=instance-id
&...auth parameters... -
View output similar to the following:
<DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <volumeId>vol-4d826724</volumeId> <instanceId>i-6058a509</instanceId> <device>/dev/sdh</device> <status>detaching</status> <attachTime>2008-05-08T11:51:50.000Z</attachTime> </DetachVolumeResponse>
To verify the volume is no longer attached to the instance, see How to Describe Snapshots.