ImportImage
匯入一份您的本機鏡像檔案到雲伺服器ECS,作為自訂鏡像出現在對應地域中。後續您可以使用匯入的鏡像建立ECS實例(RunInstances),或者更換實例的系統盤(ReplaceSystemDisk)。
介面說明
介面說明
調用該介面時,您需要注意:
-
您必須提前上傳鏡像檔案到物件儲存 OSS。具體操作,請參見上傳檔案。
-
為避免部分伺服器、虛擬機器或者雲主機的作業系統在匯入自訂鏡像後,建立的 ECS 實例無法啟動,您需要在匯入鏡像前檢查是否需要在來源伺服器中安裝 virtio 驅動程式。具體操作,請參見安裝 virtio 驅動程式。
-
首次匯入鏡像時,您必須提前透過存取控制 RAM 授權 ECS 存取您的 OSS Bucket,否則會報錯
NoSetRoletoECSServiceAccount或InvalidOperation.CloudBoxImageImportRoleRequired。分為以下兩種場景情況:-
不透過雲盒匯入鏡像檔案:您可以透過 RAM 管理主控台一鍵完成授權操作,具體的授權頁面,請參見雲資源存取授權。您也可以手動完成授權操作,部分操作中策略與權限如下所示。具體操作,請參見帳號存取控制。
-
建立角色
AliyunECSImageImportDefaultRole(必須是這個名稱,否則匯入鏡像會失敗),角色的策略為:{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" } -
在該角色下,新增系統策略
AliyunECSImageImportRolePolicy。您也可以建立自訂策略,權限必須包含:{ "Version": "1", "Statement": [ { "Action": [ "oss:GetObject", "oss:GetBucketLocation", "oss:GetBucketInfo" ], "Resource": "*", "Effect": "Allow" } ] }
-
-
透過雲盒匯入鏡像檔案:您可以透過 RAM 管理主控台一鍵完成授權操作,具體的授權頁面,請參見雲資源存取授權。您也可以手動完成授權操作,部分操作中策略與權限如下所示。具體操作,請參見帳號存取控制。
-
建立角色
AliyunECSCloudBoxImageImportDefaultRole(必須是這個名稱,否則匯入鏡像會失敗),角色的策略為:{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" } -
在該角色下,新增系統策略
AliyunECSCloudBoxImageImportRolePolicy。您也可以建立自訂策略,權限必須包含:{ "Version": "1", "Statement": [ { "Action": [ "oss-cloudbox:GetObject", "oss-cloudbox:GetBucketLocation", "oss-cloudbox:GetBucketInfo" ], "Resource": "*", "Effect": "Allow" } ] }
-
-
-
不能刪除正在匯入的鏡像,只能調用 CancelTask 取消匯入鏡像任務。
-
匯入鏡像的地域必須跟鏡像檔案上傳的 OSS Bucket 的地域相同。
-
參數
DiskDeviceMapping.N中 N 的取值範圍為 1~17。N 為 1 時表示系統盤,N 為 2~17 時表示資料盤,當 N 大於 17 時系統會自動忽略。 -
當參數
Architecture取值為arm64,或者參數Platform取值為CentOS Stream、Anolis、AlmaLinux、UOS、Kylin或Rocky Linux時,您需要注意:-
為了使匯入後的鏡像支援配置密碼或者支援修改金鑰對,鏡像必須滿足以下條件:
-
作業系統的核心需要支援
CONFIG_FW_CFG_SYSFS特性。Linux 社群核心 4.6 版本之後預設支援該特性,CentOS 的核心在 3.10.0-826.el7 版本之後預設支援該特性。您可以在該鏡像對應的伺服器內執行grep -nr CONFIG_FW_CFG_SYSFS /boot/config-$(uname -r)命令,如果回顯結果中包含CONFIG_FW_CFG_SYSFS=y資訊,則說明該鏡像中的核心已支援CONFIG_FW_CFG_SYSFS特性。 -
作業系統中已安裝阿里雲最新版本 cloud-init。其中,19.1 版本 cloud-init 必須在 19.1.3 版本及以上,部分低版本作業系統中的 0.7.6a 版本 cloud-init 必須在 0.7.6a15 版本及以上。具體操作,請參見安裝 cloud-init。
-
作業系統需要支援 SHA-512 加密演算法。
-
-
為了使匯入後的鏡像支援擴容雲端硬碟與擴容檔案系統,鏡像必須滿足以下條件:
-
作業系統的核心版本需要高於 3.6 版本。
-
支援 growpart 命令。支援該命令需要安裝
cloud-utils-growpart套件,不同作業系統安裝方式有所不同。具體操作,請參見擴容分割區和檔案系統(Linux)。 -
支援 resize2fs 命令。支援該命令需要安裝
e2fsprogs套件,該套件在作業系統中預設已安裝,如果未安裝您需要自行安裝。 -
作業系統中已安裝阿里雲最新版本 cloud-init。其中,19.1 版本 cloud-init 必須在 19.1.3 版本及以上,部分低版本作業系統中的 0.7.6a 版本 cloud-init 必須在 0.7.6a15 版本及以上。具體操作,請參見安裝 cloud-init。
-
-
-
如果您待匯入的自訂鏡像對應的系統架構為 arm64 時,您需要設定其 RTC 時鐘使用 UTC 時間標準。具體操作,請參見 Linux 時間和時區說明。
-
強烈建議在匯入鏡像時配置鏡像檢測參數,有助於系統幫助最佳化您的鏡像。更多資訊,請參見鏡像檢測概述。
調試
您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。
調試
授權資訊
|
操作 |
存取層級 |
資源類型 |
條件關鍵字 |
關聯操作 |
|
ecs:ImportImage |
update |
*Image
|
無 | 無 |
請求參數
|
名稱 |
類型 |
必填 |
描述 |
樣本值 |
| RegionId |
string |
是 |
來源自訂鏡像的地域 ID。您可以調用 DescribeRegions 查看最新的阿里雲地域清單。 |
cn-hangzhou |
| ImageName |
string |
否 |
鏡像名稱。長度為 2~128 個字元。必須以大小寫字母或中文開頭,不能以 |
ImageTestName |
| Description |
string |
否 |
鏡像的描述資訊。長度為 2~256 個英文或中文字元,不能以 |
TestDescription |
| Architecture |
string |
否 |
系統架構。取值範圍:
預設值:x86_64。 |
x86_64 |
| OSType |
string |
否 |
作業系統類型。取值範圍:
預設值:linux。 |
linux |
| Platform |
string |
否 |
作業系統版本。取值範圍:
預設值:Others Linux。 |
Aliyun |
| BootMode |
string |
否 |
修改鏡像的啟動模式。取值範圍:
預設值:BIOS。如果 重要
為了避免使用鏡像不支援的啟動模式導致實例無法正常啟動,請您務必在選擇該參數之前瞭解目標鏡像支援的啟動模式。鏡像啟動模式詳情,請參見鏡像啟動模式。 |
BIOS |
| RoleName |
string |
否 |
匯入鏡像時,使用的 RAM 角色名稱。 |
AliyunECSImageImportDefaultRole |
| LicenseType |
string |
否 |
許可證類型,預設該鏡像在建立實例( RunInstances )時的授權模式。該值僅對 Windows Server 類型鏡像生效。取值範圍:
預設值:Aliyun。 |
BYOL |
| ResourceGroupId |
string |
否 |
匯入鏡像所在的企業資源群組 ID。 |
rg-bp67acfmxazb4p**** |
| DiskDeviceMapping |
array<object> |
否 |
建立的自訂鏡像資訊清單。 |
|
|
object |
否 |
建立的自訂鏡像資訊清單。 |
||
| DiskImSize |
integer |
否 |
自訂鏡像大小。單位:GiB。 該空間由系統盤和資料盤組成,您必須保證系統盤的空間大小大於等於匯入的鏡像檔案大小。取值範圍:
當您將來源鏡像檔案上傳至 OSS 後,可以在 OSS Bucket 中查看鏡像檔案的大小。 說明
該參數即將被棄用,為提高相容性,請盡量使用 |
80 |
| Device |
string |
否 |
指定 DiskDeviceMapping.N.Device 在自訂鏡像中的裝置名稱。 說明
該參數即將停止使用,為提高程式碼相容性,建議您盡量不要使用該參數。 |
null |
| OSSBucket |
string |
否 |
鏡像檔案所在的 OSS Bucket。 說明
首次匯入鏡像到該 OSS Bucket 前,請參見本文件的介面說明新增 RAM 授權策略,否則會報錯 |
ecsimageos |
| Format |
string |
否 |
鏡像格式。取值範圍:
預設值:無,表示阿里雲自動檢測鏡像格式,以檢測格式為準。 |
QCOW2 |
| OSSObject |
string |
否 |
鏡像上傳至 OSS Bucket 後,儲存在 Bucket 中的鏡像檔案的檔案名稱(key)。 |
CentOS_5.4_32.raw |
| DiskImageSize |
integer |
否 |
匯入鏡像後,自訂鏡像的空間大小。 該空間由系統盤和資料盤組成,您必須保證系統盤的空間大小大於等於匯入的鏡像檔案大小。取值範圍:
當您將來源鏡像檔案上傳至 OSS 後,可以在 OSS Bucket 中查看鏡像檔案的大小。 |
80 |
| Tag |
array<object> |
否 |
鏡像的標籤清單。 |
|
|
object |
否 |
鏡像的標籤清單。 |
||
| Key |
string |
否 |
鏡像的標籤鍵。N 的取值範圍:1~20。一旦傳入該值,則不允許為空字串。最多支援 128 個字元,不能以 |
TestKey |
| Value |
string |
否 |
鏡像的標籤值。N 的取值範圍:1~20。一旦傳入該值,允許為空字串。最多支援 128 個字元,不能以 |
TestValue |
| DetectionStrategy |
string |
否 |
鏡像檢測策略,不配置此參數時不觸發檢測。僅支援標準(Standard)檢測模式。 說明
目前已支援大部分的 Linux/Windows 版本,關於鏡像檢測項與作業系統限制說明,請參見鏡像檢測概述和鏡像檢測作業系統限制。 |
Standard |
| StorageLocationArn |
string |
否 |
指定雲盒的資源名稱(ARN),用於唯一標識雲端儲存位置。 說明
僅當您需要從 OSS ON 雲盒中匯入鏡像檔案時,才需提供此參數的值。如果您使用的儲存服務不是 OSS ON 雲盒,則無需設定此參數。更多資訊,請參見什麼是 OSS ON 雲盒。 正確的 ARN 格式應遵循: |
arn:acs:cloudbox:cn-hangzhou:123456:cloudbox/cb-xx***123 |
| DryRun |
boolean |
否 |
是否只預檢此次請求。取值範圍:
預設值:false。 |
false |
| Features |
object |
否 |
鏡像特性相關屬性。 |
|
| NvmeSupport |
string |
否 |
鏡像是否支援 NVMe。可能值:
|
supported |
| ImdsSupport |
string |
否 |
鏡像的中繼資料存取模式,可能值:
預設值:v1。 |
v2 |
| ClientToken |
string |
否 |
保證請求冪等性。從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元,且不能超過 64 個字元。更多資訊,請參見如何保證冪等性。 |
123e4567-e89b-12d3-a456-426655440000 |
返回參數
|
名稱 |
類型 |
描述 |
樣本值 |
|
object |
|||
| RequestId |
string |
請求 ID。 |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
| ImageId |
string |
鏡像 ID。 |
m-bp67acfmxazb4p**** |
| TaskId |
string |
匯入鏡像任務 ID。 |
t-bp67acfmxazb4p**** |
| RegionId |
string |
地域 ID。 |
cn-hangzhou |
樣本
正常返回樣本
JSON格式
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"ImageId": "m-bp67acfmxazb4p****",
"TaskId": "t-bp67acfmxazb4p****",
"RegionId": "cn-hangzhou"
}
錯誤碼
|
HTTP status code |
錯誤碼 |
錯誤資訊 |
描述 |
|---|---|---|---|
| 400 | UnsupportedSuffix.OSSObject | The specified OSS object suffix is not supported. | |
| 400 | MissingParameter | An input parameter "RegionId" that is mandatory for processing the request is not supplied. | |
| 400 | InvalidImageName.Malformed | The specified Image name is wrongly formed. | |
| 400 | InvalidOSSObject.Malformed | The specified OSS object is wrongly formed. | |
| 400 | InvalidOSSBucket.Malformed | The specified OSS bucket is wrongly formed. | |
| 400 | InvalidOSSObject.Size | The specified OSS object size is zero. | |
| 400 | InvalidDescription.Malformed | The specified Image description is wrongly formed. | |
| 400 | InvalidArchitecture.Malformed | The specified Architecture is wrongly formed. | |
| 400 | InvalidPlatform.Malformed | The specified Platform is wrongly formed. | |
| 400 | InvalidOSType.Malformed | The specified OSType is wrongly formed. | |
| 400 | InvalidImageName.Duplicated | The destination image is exist. | |
| 400 | InvalidImageSize | %s | |
| 400 | InvalidDataDiskSize | The specified DiskDeviceMapping.N.DiskImSize should be in the specified range. | |
| 400 | InvalidImageFormat.Malformed | The specified Image Format is wrongly formed. | |
| 400 | InvalidRegionId.NotFound | The specified RegionId does not exist. | |
| 400 | InvalidRegion.NotSupport | The specified region does not support image import or export. | |
| 400 | InvalidOSSBucket.NotFound | The specified OSS bucket does not exist in this region. | |
| 400 | InvalidOSSObject.NotFound | The specified OSS object does not exist in this region. | |
| 400 | InvalidOSSObject.NeedRestore | The specified OSS object is a archive object, need restore first. | |
| 400 | InvalidOSSBucket.NotMatched | The specified OSS bucket is incorrect, %s. | |
| 400 | InvalidLicenseType.NotSupported | The specified LicenseType is not supported. | |
| 400 | InvalidLicenseType.BYOLOnly | Only BYOL LicenseType is supported for the current platform provided. | |
| 400 | InvalidOSSBucket.FlowLimit | %s | |
| 400 | InvalidImageFormat.RegionNotSupported | The specified image format is not supported in current region. | |
| 400 | InvalidBootMode.Malformed | The specified parameter "BootMode" is malformed. | |
| 400 | InvalidParameter.DetectionStrategy | The specified parameter DetectionStrategy is invalid. | |
| 400 | InvalidBootMode.NotSupport | The specified parameter BootMode is not supported for current image architecture. | |
| 400 | DRYRUN.SUCCESS | This request is a dryrun request with successful result. | |
| 400 | InvalidClientToken.Malformed | The specified parameter clientToken is not valid. | |
| 400 | InvalidParameter.FeaturesImdsSupport | The specified parameter Features.ImdsSupport is not supported. | |
| 400 | Account.Arrearage | Your account has an outstanding payment. | |
| 403 | ImageIsImporting | The specified Image is importing. | |
| 403 | QuotaExceed.Image | The Image Quota exceeds. | |
| 403 | ImportImageFailed | Importing image is failed, Please contact the administrator. | |
| 403 | UserNotInTheWhiteList | The user is not in the white list of importing image. | |
| 403 | NoSetRoletoECSServiceAcount | ECS service account Have no right to access your OSS.please attach a role of access your oss to ECS service account. | |
| 403 | InvalidParameter.Malformed | The specified parameter "DiskDeviceMapping.n.Device " is not valid. | |
| 403 | MissingParameter.DiskDeviceMapping | The specified parameter DiskDeviceMapping is not supplied. | |
| 403 | InvalidOSS.NotAuthorized | The specified OSS bucket or object is not allowed to access. | |
| 403 | InvalidBlockSize.NotSupport | %s | |
| 403 | InvalidImageFormat.Malformed | %s | |
| 403 | ImageCheckUnsupported.WindowsImage | Image check is unsupported for windows image. | |
| 403 | InvalidVHDImage.IncorrectSize | The specified size of the VHD image does not meet the 'header.MaxTableEntries * header.BlockSize' specification. | |
| 403 | InvalidOSSBucket.EncryptUnsupported | Accessing objects from encrypted OSS bucket is not supported. | |
| 403 | InvalidArchitecture.PlatformUnsupported | The OS platform you selected does not support the specified architecture. | |
| 403 | InvalidAccountStatus.OSSDisabled | OSS is disabled due to invalid account status. | |
| 403 | InvalidStorageLocation.NotFound | The specified cloud box storage location %s could not be found. | |
| 403 | InvalidOperation.CloudBoxImageImportRoleRequired | The role for cloud box image import is not set to the ECS service. | |
| 403 | InvalidOperation.CloudBoxImageImportUnsupported | Importing cloud box images is not supported. | |
| 403 | TagKey.Duplication | The TagKey has duplication with others, case-insensitive. | |
| 404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. |
訪問錯誤中心查看更多錯誤碼。
變更歷史
更多資訊,參考變更詳情。