全部產品
Search
文件中心

Elastic Compute Service:AttachDisk

更新時間:Sep 14, 2026

為一台ECS執行個體掛載一塊資料磁碟或系統磁碟。

介面說明

呼叫該介面時,您需要注意:

  • 執行個體和磁碟必須在同一個可用區。

  • 磁碟的狀態必須為待掛載(Available)。

  • 掛載資料磁碟時:

    • 目標 ECS 執行個體必須處於執行中(Running)或者已停止(Stopped)狀態。

    • 如果是您單獨購買的磁碟,計費方式必須是按量付費。

    • 從 ECS 執行個體上卸載的系統磁碟作為資料磁碟掛載時,不限制計費方式。

    • 彈性臨時磁碟一旦卸載,只能重新掛載至其原始執行個體。

  • 掛載系統磁碟時:

    • 目標 ECS 執行個體必須是卸載該系統磁碟時的來源執行個體。

    • 目標 ECS 執行個體必須處於已停止(Stopped)狀態。

    • 您必須設定執行個體登入憑證。

    • 彈性臨時磁碟不支援掛載為系統磁碟。

    • 更多關於掛載系統磁碟的資訊,請參閱卸載或掛載系統磁碟。

  • 查詢 ECS 執行個體資訊時,如果返回資料中包含{"OperationLocks": {"LockReason" : "security"}},則禁止一切操作。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

下表是API對應的授權資訊,可以在RAM權限原則語句的Action元素中使用,用來給RAM使用者或RAM角色授予調用此API的許可權。具體說明如下:

  • 操作:是指具體的許可權點。

  • 存取層級:是指每個操作的存取層級,取值為寫入(Write)、讀取(Read)或列出(List)。

  • 資源類型:是指操作中支援授權的資源類型。具體說明如下:

    • 對於必選的資源類型,用前面加 * 表示。

    • 對於不支援資源級授權的操作,用全部資源表示。

  • 條件關鍵字:是指雲產品自身定義的條件關鍵字。

  • 關聯操作:是指成功執行操作所需要的其他許可權。操作者必須同時具備關聯操作的許可權,操作才能成功。

操作

存取層級

資源類型

條件關鍵字

關聯操作

ecs:AttachDisk

update

*Disk

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

*Instance

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

  • ecs:LoginAsNonRoot
  • ecs:PasswordCustomized
無

請求參數

名稱

類型

必填

描述

樣本值

InstanceId

string

是

待掛載 ECS 執行個體的 ID。

i-bp1dq5lozx5f4pmd****

DiskId

string

是

待掛載的磁碟 ID。磁碟(DiskId)和執行個體(InstanceId)必須在同一個可用區。

說明

支援掛載資料磁碟和系統磁碟,相關約束條件請參閱上文介面說明部分。

d-bp1j4l5axzdy6ftk****

Device

string

否

磁碟裝置名稱。

說明

該參數即將被棄用,為提高相容性,建議您盡量使用其他參數識別磁碟。

testDeviceName

DeleteWithInstance

boolean

否

釋放執行個體時,該磁碟是否隨執行個體一起釋放。取值範圍:

  • true:釋放。

  • false:不釋放。磁碟會轉換成按量付費資料磁碟而被保留下來。

預設值:false。

設定該參數時,您需要注意:

  • 將DeleteWithInstance設為false後,一旦 ECS 執行個體被安全性控制,即OperationLocks中標記了"LockReason" : "security",釋放 ECS 執行個體時會忽略磁碟的該屬性,被同時釋放。

  • 若您需要掛載的目標磁碟為彈性臨時磁碟,則必須將DeleteWithInstance參數設定為true。

  • 開啟多重掛載特性的雲端硬碟,不支援設定該參數。

false

Bootable

boolean

否

是否作為系統磁碟掛載。取值範圍:

  • true:是。

  • false:否。

預設值:false。

說明

設定為Bootable=true時,目標 ECS 執行個體必須處於無系統磁碟狀態。

false

Password

string

否

掛載系統磁碟時,設定執行個體的使用者名稱密碼,僅對 administrator 和 root 使用者名稱生效,其他使用者名稱不生效。長度為 8 至 30 個字元,必須同時包含大小寫英文字母、數字和特殊符號中的三類字元。特殊符號可以是:

()`~!@#$%^&*-_+=|{}[]:;'<>,.?/

其中,Windows 執行個體不能以斜線號(/)為密碼首字元。

說明

如果傳入Password參數,建議您使用 HTTPS 協定傳送請求,避免密碼外洩。

EcsV587!

KeyPairName

string

否

掛載系統磁碟時,為 Linux 系統 ECS 執行個體繫結的 SSH 金鑰對的名稱。

  • Windows Server 系統:不支援 SSH 金鑰對。即使填寫了該參數,只執行Password的設定。

  • Linux 系統:密碼登入方式會被初始化成禁止。

KeyPairTestName

Force

boolean

否

是否為強制掛載請求。取值範圍:

  • true:是。

  • false:否。

預設值:false。

說明

當前僅 ESSD 同城冗餘類型(cloud_regional_disk_auto)支援設定該欄位為 true。

false

返回參數

名稱

類型

描述

樣本值

object

RequestId

string

請求 ID。

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

樣本

正常返回樣本

JSON格式

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

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 InvalidDevice.Malformed The specified device is not valid.
400 IncorrectInstanceStatus The current status of the resource does not support this operation. 目前執行個體狀態不支援此類操作。
400 InvalidParameter The input parameter is mandatory for processing this request is empty. 目前的請求參數不合法,請重試。
400 InvalidRegionId.MalFormed The specified RegionId is not valid.
400 InvalidOperation.InstanceTypeNotSupport The instance type of the specified instance does not support hot attach disk. 磁碟掛載的執行個體不支援磁碟熱插拔操作。
400 DiskCategory.OperationNotSupported The operation is not supported to the specified disk due to its disk category. 目前磁碟類型不支援此操作。
400 InvalidDisk.DiskNotBootable The specified disk is not a bootable disk. It cannot be attached as a system disk.
400 InvalidInstance.NotOriginInstance The specified disk can not attached to other instance as system disk.
400 InvalidParameterForce.DiskCategoryNotSupported The specified disk category does not support force attach operation. 指定的磁碟類型不支援強制掛載操作。
400 InvalidParameterForce.PrepaidDiskNotSupported The prepaid disk does not support force attach operation. 預付費磁碟不支援強制掛載操作。
400 InvalidParameterForce.MultiAttachDiskNotSupported The multi attach disk does not support force attach operation. 多重掛載磁碟不支援強制掛載操作。
400 InvalidParameterForce.RegionNotSupported The specified region does not support force attach operation. 該地域不支援強制掛載操作。
400 OperationConflict.DisksAttachingParallellyExceed The number of disks attaching parallelly exceeds the limit. 平行掛載的磁碟數量超過限制。
400 InvalidInstanceType.NotSupported The specified instanceType is not supported by the image architecture. 不支援指定的 InstanceType。
400 InvalidOperation.EncryptedDiskUnsupported The specified encrypted disk is not supported for this operation.
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 InstanceDiskLimitExceeded The number of disks attached to the instance has exceeded the limit.
403 InvalidDevice.InUse The specified device has been occupied.
403 DiskNotPortable The specified disk is not a portable disk.
403 InstanceLockedForSecurity The instance is locked due to security. 磁碟掛載的執行個體因安全原因被鎖定。
403 ResourcesNotInSameZone The specified instance and disk are not in the same zone.
403 InstanceExpiredOrInArrears The specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode).
403 DiskInArrears The specified operation is denied because the disk has overdue payments. Please settle the outstanding balance.
403 DiskError IncorrectDiskStatus.
403 DiskId.ValueNotSupported The specified parameter diskid is not supported. 指定的區塊儲存類型不支援此操作。
403 DiskId.StatusNotSupported The specified disk status is not supported. 目前磁碟的狀態不支援此操作。
403 IncorrectInstanceStatus.NotSupportESSD The operation is not supported in this status. Please reboot the instance.
403 IncorrectDiskStatus The operation is not supported in this status. 目前的磁碟不支援此操作,請您確認磁碟處於正常使用狀態,以及是否欠費。
403 UserNotInTheWhiteList The user is not in disk white list. 使用者不在共用區塊儲存白名單中,請您提交工單申請白名單。
403 InvalidParameter.KMSKeyId.CMKNotEnabled The CMK needs to be enabled.
403 InvalidParameter.KMSKeyId.CMKUnauthorized The CMK has not authorized the ECS service to perform the KMS TagResource and UntagResource operations. Please verify the authorization and try again.
403 InvalidParameter.KMSKeyId.KMSUnauthorized ECS service does not have permission to access your KMS key. Please verify that the specified KMS key has authorized the ECS service.
403 DependencyViolation.WindowsInstance The instance image is Windows. SSH key pair login is not supported.
403 InvalidInstanceType.NotSupportDiskCategory The instanceType of the specified instance does not support this disk category. 指定的執行個體規格(InstanceType)不支援目前執行個體的雲端硬碟類別。請嘗試更換其他執行個體規格。關於執行個體規格支援的雲端硬碟類型,請參見執行個體規格族文件。
403 InvalidInstanceType.NotSupportPL0 The instanceType of the specified instance does not support PL0 of cloud_essd.
403 InvalidInstanceType.NvmeRequired The instanceType of the specified instance requires nvme protocol. 指定執行個體的規格要求使用 NVMe 通訊協定。
403 InvalidInstanceType.NvmeUnsupported The instanceType of the specified instance does not support nvme protocol. 指定執行個體的規格不支援 NVMe 通訊協定。
403 InvalidInstanceType.NotSupportMultiAttachDisk The instanceType of the specified instance does not support multi attach disk. 指定的執行個體規格不支援掛載啟用多重掛載特性的雲端硬碟。
403 DiskAttachedNumberExceeded The attaching times of the specified disk exceeded. 指定的雲端硬碟所掛載的執行個體數量已達上限。
403 InvalidOperation.CanNotAttachMultiAttachDiskAsSystemDisk Multi attach disk can not be attached as system disk. 啟用多重掛載特性的雲端硬碟不支援作為系統磁碟使用。
403 DeleteWithInstance.Conflict Multi attach disk cannot be set to DeleteWithInstance attribute. 指定的磁碟不是可卸載磁碟,不支援隨執行個體釋放。
403 InvalidParameter.DeleteWithInstance The DeleteWithInstance for the elastic ephemeral disk must be set to true. 彈性臨時磁碟的 DeleteWithInstance 屬性必須設定為 true。
403 InvalidOperation.OtherInstanceUnsupported The elastic ephemeral disk can only be attached to the instance it was last mounted on. Please check the disk system tag to get the last associated instance.
403 InvalidInstance.ZoneConflict The force attach operation is not supported when both the current and target instances are in the same zone. 強制掛載要求目前執行個體與目標執行個體處於不同可用區。
403 InvalidParameter.AllEmpty The current operation requires either a password or a keyPairName to must be provided. Please ensure that at least one of them is not empty. 您沒有輸入任何參數,請輸入必要的參數。
403 InvalidOperation.DiskQueueNumberNotEnough The number of disk queues on the instance is not enough. 執行個體上的磁碟佇列數不足。
403 InvalidOperation.DiskAttachModeUnsupported The instance type does not support the disk attach mode. 目前執行個體規格不支援磁碟的掛載模式。
403 OperationDenied.HpnZoneMismatch Instance and disk must be in the same HPN zone for restricted HPN zones. 對於部分受限的 HPN 區域,執行個體與磁碟必須位於同一 HPN 區域內才可執行掛載操作。
403 OperationDenied.UnsupportedEncryptedDisk The instance type does not support attaching encrypted disks. 執行個體的規格不支援掛載加密磁碟。
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. 指定的執行個體不存在,請您檢查執行個體 ID 是否正確。
404 InvalidDiskId.NotFound The specified disk does not exist. 指定的磁碟不存在。請您檢查磁碟 ID 是否正確。
404 InvalidDisk.InUse The specified disk has been occupied.
404 DiskAttachedNumberExceeded The attaching times of the specified disk exceeded.
404 InvalidKMSKeyId.NotFound The specified KMSKeyId does not exist. Please verify that the key ID is correct and that the key resides in the current region.

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情。