全部產品
Search
文件中心

Elastic Compute Service:AttachDisk - 為執行個體掛載磁碟

更新時間:Apr 04, 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"
}

異常返回樣本

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, can not be attached as 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. 指定的鏡像架構不支援此執行個體規格。
500 InternalError The request processing has failed due to some unknown error, exception or failure. 內部錯誤,請重試。
403 InstanceDiskLimitExceeded The amount of the disk on instance in question reach its limits.
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 as your disk owing fee.
403 DiskError IncorrectDiskStatus.
403 DiskId.ValueNotSupported The specified parameter diskid is not supported. 指定的Block Storage類型不支援此操作。
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. 當前執行個體狀態不支援ESSD類型磁碟的掛載操作
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 needs to be added ECS tag. CMK 未授權
403 InvalidParameter.KMSKeyId.KMSUnauthorized ECS service have no right to access your KMS. ECS 服務無權訪問您的 KMS。
403 DependencyViolation.WindowsInstance The instance image is windows, cannot use ssh key pair to login.
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. 開啟多重掛載特性的雲端硬碟不支援設定 DeleteWithInstance。
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's system tag to get the last associated instance. 彈性臨時盤僅能被掛載到上一次掛載的執行個體,請檢查磁碟的系統 Tag 來擷取上一次的執行個體。
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. 當前操作不允許password和keyPairName同時為空白,確保password或者keyPairName有一個不為空白。
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 KMS key used by the disk does not exist. 磁碟使用的 KMS 密鑰不存在.

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

變更歷史

更多資訊,參考變更詳情