DetachDisk

Updated at:

Detaches a pay-as-you-go data disk or system disk from an ECS instance.

Operation description

When you call this operation, take note of the following items:

  • This operation is asynchronous. After a successful call, wait about one minute for the detachment to complete.

  • If the instance to which the disk is attached is locked for security reasons, the OperationLocks parameter cannot contain the "LockReason" : "security" lock state.

  • Once an elastic ephemeral disk is detached, it can only be reattached to its original instance.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:DetachDisk

update

*Disk

acs:ecs:{#regionId}:{#accountId}:disk/{#diskId}

*Instance

acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

Yes

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

i-bp67acfmxazb4p****

DiskId

string

Yes

The ID of the disk to be detached.

  • The disk must be attached to an instance and be in the In Use (In_use) state.

  • When you detach a data disk, the instance to which the disk is attached must be in the Running (Running) or Stopped (Stopped) state.

  • When you detach a system disk, the instance to which the disk is attached must be in the Stopped (Stopped) state.

d-bp67acfmxazb4p****

DeleteWithInstance

boolean

No

Specifies the automatic release attribute when you detach a system disk or data disk. It specifies whether the system disk or data disk is released when the ECS instance is released.

Valid values:

  • true: The disk is released.

  • false: The disk is not released. The disk is retained and converted into a pay-as-you-go data disk.

Default value: true.

Note:

  • This parameter cannot be configured for disks that have the multi-attach attribute enabled.

  • If you detach a data disk, the default value is false.

  • If the disk to be detached is an elastic ephemeral disk, you must set the DeleteWithInstance parameter to true.

false

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Success response

JSON format

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

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter The input parameter is mandatory for processing this request is empty. A required parameter is not specified.
400 InvalidRegionId.MalFormed The specified RegionId is not valid.
400 InvalidOperation.InstanceTypeNotSupport The instance type of the specified instance does not support hot detach disk. The instance to which the disk is attached does not support hot-plugging of disks.
400 DisksDetachingOnEcsExceeded The number of disks detaching on the instance exceeds the limit. The number of disks being unmounted on the instance exceeds the limit
400 InvalidInstanceId.Malformed The specified parameter InstanceId is not valid. The specified InstanceId parameter is invalid.
500 InternalError The request processing has failed due to an internal error and you may retry later or contact support with the request ID.
403 IncorrectDiskStatus The current disk status does not support this operation.
403 DiskNotPortable The specified disk is not a portable disk.
403 InstanceLockedForSecurity The instance is locked due to security. The operation is not supported while the instance is locked for security reasons.
403 DependencyViolation The specified disk has not been attached on the specified instance.
403 DiskTypeViolation The specified disk is a system disk and cannot support the operation. The specified disk is a system disk and cannot be detached.
403 IncorrectInstanceStatus The current status of the resource does not support this operation.
403 UserNotInTheWhiteList The user is not in disk white list. You are not authorized to manage the disk. Try again when you are authorized.
403 InvalidInstance.ImageCategory The system disk cannot be detached because it was created from a marketplace image. Please use a system disk created from a custom or public image.
403 DeleteWithInstance.Conflict Multi attach disk cannot be set to DeleteWithInstance attribute. Disks for which the multi-attach feature is enabled do not support the DeleteWithInstance attribute.
403 InvalidOperation.DiskCategoryUnsupported The DetachDisk operation is not supported for elastic ephemeral disk. The DetachDisk operation is not supported for elastic ephemeral disk.
403 InvalidParameter.DeleteWithInstance The DeleteWithInstance for the elastic ephemeral disk must be set to true. The DeleteWithInstance for the elastic ephemeral disk must be set to true.
403 InvalidOperation.DiskDetachingFromThisEcs The specified disk is detaching from this ecs. The disk is being unmounted from the current instance.
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. The specified instanceId is invalid.
404 InvalidDiskId.NotFound The specified disk does not exist. The specified disk does not exist. Check whether the disk ID is correct.
404 InvalidDisk.AlreadyDetached The specified disk has been detached.
404 InvalidDiskId.OperationNotSupported The operation is not supported due to base image not exist.
503 LimitedOperation.ServiceUnavailable The service is currently unavailable. Please try again later. The service is currently unavailable. Please try again later.
429 Throttling The request was denied due to request throttling. Please retry later.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.