Updated on 2026-03-19 GMT+08:00

Attaching a Disk to an ECS

Function

This API is used to attach a disk to an ECS.

This API is an asynchronous API. After the attachment request is successfully delivered, a job ID is returned. This does not mean the attachment is complete. You need to call the API by referring to Querying Job Execution Status to query the job status. The SUCCESS status indicates that the attachment is successful.

Debugging

You can debug this API in API Explorer.

Authorization

Each account has all of the permissions required to call all APIs, but IAM users must have the required permissions specifically assigned.
  • If you are using role/policy-based authorization, see the required permissions in Permissions and Supported Actions.
  • If you are using identity policy-based authorization, the permissions listed below are required.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

ecs:cloudServers:attach

write

instance *

  • evs:Encrypted
  • ecs:KmsKeyId
  • ecs:VolumeId

-

evs:volumes:use

URI

POST /v1/{project_id}/cloudservers/{server_id}/attachvolume

Table 1 describes the parameters in the URI.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Definition

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

Constraints

N/A

Range

N/A

Default Value

N/A

server_id

Yes

Definition

Specifies the ECS ID.

Constraints

N/A

Range

N/A

Default Value

N/A

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

volumeAttachment

Yes

Object

Definition

Specifies the ECS attachment information. For details, see Table 3.

Constraints

N/A

Range

N/A

Default Value

N/A

dry_run

No

Boolean

Definition

Specifies whether the system checks the request. If this parameter is set to true, the system checks the request, but no disk will be attached.

Constraints

N/A

Range

  • true: The system checks the request. Check items include mandatory parameters and request format.
    • If the check fails, the system returns an error.
    • If the check is successful, the system returns status code 202.
  • false: The system sends the request without checking the request body.

Default Value

false

Table 3 volumeAttachment field description

Parameter

Mandatory

Type

Description

volumeId

Yes

String

Definition

Specifies the ID of the disk to be attached. The value is in UUID format.

Constraints

N/A

Range

N/A

Default Value

N/A

device

No

String

Definition

Specifies the disk device name.

Constraints

The new disk device name cannot be the same as an existing one.

Range

  • This parameter is mandatory for Xen ECSs. Set the parameter value to /dev/sda for the system disks of such ECSs and to /dev/sdx for data disks, where x is a letter in alphabetical order. For example, if there are two data disks, set the device names of the two data disks to /dev/sdb and /dev/sdc, respectively. If you set a device name starting with /dev/vd, the system uses /dev/sd by default.
  • For KVM ECSs, set the parameter value to /dev/vda for system disks. The device names for data disks of KVM ECSs are optional. If the device names of data disks are required, set them in alphabetical order. For example, if there are two data disks, set the device names of the two data disks to /dev/vdb and /dev/vdc, respectively. If you set a device name starting with /dev/sd, the system uses /dev/vd by default.
  • For ECSs that only support SCSI disks, set the device name of the system disk to /dev/sda and the device names of data disks in alphabetical order, for example, /dev/sdb and /dev/sdc. The system will not change the default device names.

Default Value

N/A

volume_type

No

String

Definition

Specifies the disk type.

Constraints

N/A

Range

The value can be SATA, SAS, GPSSD, SSD, ESSD, GPSSD2, and ESSD2.
  • SATA: common I/O disks (sold out)
  • SAS: high I/O disks
  • GPSSD: general purpose SSDs
  • SSD: ultra-I/O disks
  • ESSD: extreme SSDs
  • GPSSD2: general purpose SSD V2
  • ESSD2: extreme SSD V2

Default Value

N/A

count

No

Integer

Definition

Specifies the number of disks.

Constraints

N/A

Range

N/A

Default Value

N/A

hw:passthrough

No

String

Definition

Specifies the EVS disk device type.

Constraints

N/A

Range

  • true: indicates the SCSI device type, which allows ECS OSs to directly access the underlying storage media. SCSI reservation commands are supported.
  • false: indicates the VBD disk device type, which only supports simple SCSI read/write commands.

Default Value

N/A

Response

Table 4 describes the response parameters.

Table 4 Response parameters

Parameter

Type

Description

job_id

String

Definition

Specifies the job ID returned after a job is delivered. The job ID can be used to query the job execution progress. For details about how to query the job execution status based on job_id, see Job Status Management.

Range

N/A

For details about abnormal responses, see Responses (Jobs).

Example Request

  • Attach a SCSI EVS disk to device /dev/sda.
    POST https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/attachvolume
    
    {
        "volumeAttachment": {
             "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
             "device": "/dev/sda",
             "volume_type": "SSD",
             "count": 5,
             "hw:passthrough": "true"
        },
        "dry_run": false
    }
  • Send a pre-check request for attaching a disk.
    POST https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/attachvolume
    
    {
        "volumeAttachment": {
             "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
             "volume_type": "SSD",
             "count": 1,
             "hw:passthrough": "true"
        },
        "dry_run": true
    }

Example Response

{
    "job_id": "ff80808288d41e1b018990260955686a"
}

Error Codes

See Error Codes.