All Products
Search
Document Center

Elastic Compute Service:DetachDisk

Last Updated:Nov 14, 2024

Detaches a pay-as-you-go data disk or a system disk from an Elastic Compute Service (ECS) instance.

Operation description

Take note of the following items:

  • The disk that you want to detach must be attached to an ECS instance and in the In Use (In_use) state.
  • The instance from which you want to detach a data disk must be in the Running (Running) or Stopped (Stopped) state.
  • The instance from which you want to detach a system disk must be in the Stopped state.``
  • If the OperationLocks parameter in the response contains "LockReason" : "security" when you query the instance information, the instance is locked for security reasons and all operations are prohibited on the instance.
  • DetachDisk is an asynchronous operation. After you call the operation to detach a disk from an ECS instance, the disk is detached in approximately 1 minute.
  • If you want to attach an elastic ephemeral disk that you detached from an instance, you can attach the disk only to the instance.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ecs:DetachDiskupdate
*Disk
acs:ecs:{#regionId}:{#accountId}:disk/{#diskId}
*Instance
acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The ID of the ECS instance from which you want to detach the disk.

i-bp67acfmxazb4p****
DiskIdstringYes

The ID of the disk that you want to detach.

d-bp67acfmxazb4p****
DeleteWithInstancebooleanNo

Specifies whether to release the system disk or data disk when the instance from which you want to detach the disk is released. Valid values:

  • true: releases the disk when the instance is released.
  • false: does not release the disk when the instance is released. The disk is retained as a pay-as-you-go data disk.

Default value: true.

Take note of the following items:

  • You cannot specify this parameter for disks for which the multi-attach feature is enabled.
  • If a data disk is to be detached, the default value is false.
  • If you want to detach an elastic ephemeral disk, you must set DeleteWithInstance to true.
false

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The ID of the request.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Sample success responses

JSONformat

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

Error codes

HTTP status codeError codeError messageDescription
400InvalidParameterThe input parameter is mandatory for processing this request is empty.A required parameter is not specified.
400InvalidRegionId.MalFormedThe specified RegionId is not valid.The specified region does not exist.
400InvalidOperation.InstanceTypeNotSupportThe instance type of the specified instance does not support hot detach disk.-
400DisksDetachingOnEcsExceededThe number of disks detaching on the instance exceeds the limit.The number of disks being unmounted on the instance exceeds the limit
403IncorrectDiskStatusThe current disk status does not support this operation.The disk is in a state that does not support the current operation. Make sure that the disk is available and that your account has no overdue payments.
403DiskNotPortableThe specified disk is not a portable disk.The specified disk is not removable.
403InstanceLockedForSecurityThe instance is locked due to security.The operation is not supported while the instance is locked for security reasons.
403DependencyViolationThe specified disk has not been attached on the specified instance.-
403DiskTypeViolationThe specified disk is a system disk and cannot support the operation.The specified disk is a system disk and cannot be detached.
403IncorrectInstanceStatusThe current status of the resource does not support this operation.The resource is in a state that does not support the current operation.
403UserNotInTheWhiteListThe user is not in disk white list.You are not authorized to manage the disk. Try again when you are authorized.
403InvalidInstance.ImageCategoryThe image category of the specified instance does not support detaching system disk.The specified system disk cannot be detached from the instance while the image of the instance is in the current state. Possible cause: The image that was used to create the instance has been deleted.
403DeleteWithInstance.ConflictMulti attach disk cannot be set to DeleteWithInstance attribute.Disks for which the multi-attach feature is enabled do not support the DeleteWithInstance attribute.
403InvalidOperation.DiskCategoryUnsupportedThe DetachDisk operation is not supported for elastic ephemeral disk.The DetachDisk operation is not supported for elastic ephemeral disk.
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.The specified instance does not exist.
404InvalidDiskId.NotFoundThe specified disk does not exist.The specified disk does not exist. Check whether the disk ID is correct.
404InvalidDisk.AlreadyDetachedThe specified disk has been detached.The specified disk has been detached.
404InvalidDiskId.OperationNotSupportedThe operation is not supported due to base image not exist.-
500InternalErrorThe request processing has failed due to some unknown error.An internal error has occurred. Try again later.
500InternalErrorThe request processing has failed due to some unknown error, exception or failure.An internal error has occurred. Try again later.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-09-20The Error code has changedView Change Details
2024-07-24The Error code has changedView Change Details
2024-05-09The Error code has changedView Change Details
2024-04-15The Error code has changedView Change Details
2023-11-24The Error code has changedView Change Details