You can call this operation to detach a pay-as-you-go data disk or a system disk from an ECS instance.

Description

When you call this operation, note that:

  • The disk must have been attached to the ECS instance and be in the In Use state.
  • If you want to detach a data disk from an ECS instance, the instance must be in the Running or Stopped state.
  • If you want to detach a system disk from an ECS instance, the instance must be in the Stopped state.
  • If the attached instance is under security control and its OperationLocks parameter is set to "LockReason" : "security", you cannot start the instance.
  • DetachDisk is an asynchronous operation. It takes about one minute to complete the detachment after the DetachDisk operation is called.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
DiskId String Yes d-bp67acfmxazb4ph***

The ID of the disk to be detached.

InstanceId String Yes i-bp67acfmxazb4ph***

The ID of the ECS instance from which the disk is to be detached.

Action String No DetachDisk

The operation that you want to perform. Set the value to DetachDisk.

DeleteWithInstance Boolean No false

Specifies the automatic release attribute of a system disk. That is, whether the system disk is released together with the ECS instance. Valid values:

  • true: The system disk is to be released together with the instance.
  • false: The system disk is not to be released together with the instance. The system disk is changed into a pay-as-you-go data disk and is retained.

Default value: true.

Note If a data disk is to be detached from an instance, the default value is false.

Response parameters

Parameter Type Example Description
RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=DetachDisk
&DiskId=d-bp67acfmxazb4ph***
&InstanceId=i-bp67acfmxazb4ph***
&<Common request parameters>

Sample success responses

XML format

<DetachDiskResponse>
      <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E</RequestId>
</DetachDiskResponse>

JSON format

{
	"RequestId":"473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

HTTP status code Error code Error message Description
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. The error message returned because the specified value of the InstanceId parameter does not exist.
404 InvalidDiskId.NotFound The specified disk does not exist. The error message returned because the specified value of the DiskId parameter does not exist.
403 IncorrectDiskStatus The current disk status does not support this operation. The error message returned because the operation is not supported while the disk is in the current state. Ensure that the disk is available and has no overdue payments.
403 DiskNotPortable The specified disk is not a portable disk. The error message returned because the specified disk is not detachable when the Portable parameter is set to false.
403 InstanceLockedForSecurity The instance is locked due to security. The error message returned because the operation is not supported while the resource is locked for security reasons.
403 DependencyViolation The specified disk has not been attached on the specified instance. The error message returned because the operation is not supported while the resource has other dependencies. For example, the specified disk is not attached to the specified instance or the specified security group cannot be deleted while it contains instances.
403 DiskTypeViolation The specified disk is a system disk and cannot support the operation. The error message returned because the specified disk is a system disk and cannot be detached from its associated instance.
403 IncorrectInstanceStatus The current status of the resource does not support this operation. The error message returned because the operation is not supported while the instance is in the current state.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later. If the problem persists, submit a ticket.
400 InvalidParameter The input parameter is mandatory for processing this request is empty. The error message returned because the required parameter is not specified.
403 UserNotInTheWhiteList The user is not in disk white list. The error message returned because you are not authorized to use the specified disk.
400 InvalidRegionId.MalFormed The specified RegionId is not valid The error message returned because the specified RegionId parameter is invalid.
404 InvalidDisk.AlreadyDetached The specified disk has been detached. The error message returned because the specified disk has been detached from the instance.
400 InvalidOperation.InstanceTypeNotSupport The instance type of the specified instance does not support hot detach disk. The error message returned because the instance to which the disk is attached does not support the hot swapping of disks.
500 InternalError The request processing has failed due to some unknown error, exception or failure. The error message returned because an unknown error has occurred.

For a list of error codes, visit the API Error Center.