ImportImage

更新時間:
Copy as MD

匯入一份您的本機鏡像檔案到雲伺服器ECS,作為自訂鏡像出現在對應地域中。後續您可以使用匯入的鏡像建立ECS實例(RunInstances),或者更換實例的系統盤(ReplaceSystemDisk)。

介面說明

介面說明

調用該介面時,您需要注意:

  • 您必須提前上傳鏡像檔案到物件儲存 OSS。具體操作,請參見上傳檔案

  • 為避免部分伺服器、虛擬機器或者雲主機的作業系統在匯入自訂鏡像後,建立的 ECS 實例無法啟動,您需要在匯入鏡像前檢查是否需要在來源伺服器中安裝 virtio 驅動程式。具體操作,請參見安裝 virtio 驅動程式

  • 首次匯入鏡像時,您必須提前透過存取控制 RAM 授權 ECS 存取您的 OSS Bucket,否則會報錯NoSetRoletoECSServiceAccountInvalidOperation.CloudBoxImageImportRoleRequired。分為以下兩種場景情況:

    • 不透過雲盒匯入鏡像檔案:您可以透過 RAM 管理主控台一鍵完成授權操作,具體的授權頁面,請參見雲資源存取授權。您也可以手動完成授權操作,部分操作中策略與權限如下所示。具體操作,請參見帳號存取控制

      1. 建立角色AliyunECSImageImportDefaultRole(必須是這個名稱,否則匯入鏡像會失敗),角色的策略為:

        {
        	"Statement": [
        	{
        		"Action": "sts:AssumeRole",
        		"Effect": "Allow",
        		"Principal": {
        		"Service": [
        			"ecs.aliyuncs.com"
        		]
        		}
        	}
        ],
        	"Version": "1"
        }
        
      2. 在該角色下,新增系統策略AliyunECSImageImportRolePolicy。您也可以建立自訂策略,權限必須包含:

        {
        	"Version": "1",
        	"Statement": [
        	{
        		"Action": [
        				"oss:GetObject",
        				"oss:GetBucketLocation",
        				"oss:GetBucketInfo"
        	],
        			"Resource": "*",
        			"Effect": "Allow"
        			}
        	]
        }
        
        
    • 透過雲盒匯入鏡像檔案:您可以透過 RAM 管理主控台一鍵完成授權操作,具體的授權頁面,請參見雲資源存取授權。您也可以手動完成授權操作,部分操作中策略與權限如下所示。具體操作,請參見帳號存取控制

      1. 建立角色AliyunECSCloudBoxImageImportDefaultRole(必須是這個名稱,否則匯入鏡像會失敗),角色的策略為:

        {
        	"Statement": [
        	{
        		"Action": "sts:AssumeRole",
        		"Effect": "Allow",
        		"Principal": {
        		"Service": [
        			"ecs.aliyuncs.com"
        		]
        		}
        	}
        ],
        	"Version": "1"
        }
        
      2. 在該角色下,新增系統策略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 StreamAnolisAlmaLinuxUOSKylinRocky 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程式碼範例。

調試

授權資訊

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

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

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

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

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

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

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

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

操作

存取層級

資源類型

條件關鍵字

關聯操作

ecs:ImportImage

update

*Image

acs:ecs:{#regionId}:{#accountId}:image/*

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

來源自訂鏡像的地域 ID。您可以調用 DescribeRegions 查看最新的阿里雲地域清單。

cn-hangzhou

ImageName

string

鏡像名稱。長度為 2~128 個字元。必須以大小寫字母或中文開頭,不能以aliyunacs:開頭,不能包含http://或者https://。可以包含數字、半形句號(.)、半形冒號(:)、底線(_)或者短橫線(-)。

ImageTestName

Description

string

鏡像的描述資訊。長度為 2~256 個英文或中文字元,不能以http://https://開頭。

TestDescription

Architecture

string

系統架構。取值範圍:

  • i386。

  • x86_64。

  • arm64。

預設值:x86_64。

x86_64

OSType

string

作業系統類型。取值範圍:

  • windows。需要同時設定LicenseType

  • linux。

預設值:linux。

linux

Platform

string

作業系統版本。取值範圍:

  • Aliyun

  • Anolis

  • CentOS

  • Ubuntu

  • CoreOS

  • SUSE

  • Debian

  • OpenSUSE

  • FreeBSD

  • RedHat

  • Kylin

  • UOS

  • Fedora

  • Fedora CoreOS

  • CentOS Stream

  • AlmaLinux

  • Rocky Linux

  • Gentoo

  • Customized Linux

  • Others Linux

  • Windows Server 2022

  • Windows Server 2019

  • Windows Server 2016

  • Windows Server 2012

  • Windows Server 2008

  • Windows Server 2003

  • Other Windows

預設值:Others Linux。

Aliyun

BootMode

string

修改鏡像的啟動模式。取值範圍:

  • BIOS:BIOS 啟動模式。

  • UEFI:UEFI 啟動模式。

預設值:BIOS。如果Architecture=arm64,則該參數預設值為 UEFI,且只能設定為 UEFI。

重要

為了避免使用鏡像不支援的啟動模式導致實例無法正常啟動,請您務必在選擇該參數之前瞭解目標鏡像支援的啟動模式。鏡像啟動模式詳情,請參見鏡像啟動模式

BIOS

RoleName

string

匯入鏡像時,使用的 RAM 角色名稱。

AliyunECSImageImportDefaultRole

LicenseType

string

許可證類型,預設該鏡像在建立實例( RunInstances )時的授權模式。該值僅對 Windows Server 類型鏡像生效。取值範圍:

  • Aliyun:使用阿里雲官方許可。啟動實例後,系統將嘗試自動連接阿里雲 KMS 伺服器進行啟用。該實例的計費中將包含 Windows Server 許可費。

  • BYOL:自帶許可 (Bring Your Own License)。啟動實例後,阿里雲不會對其進行自動啟用。您需使用自有的合法許可金鑰手動啟用。該實例的計費中不會包含 Windows Server 許可費。

預設值:Aliyun。

BYOL

ResourceGroupId

string

匯入鏡像所在的企業資源群組 ID。

rg-bp67acfmxazb4p****

DiskDeviceMapping

array<object>

建立的自訂鏡像資訊清單。

object

建立的自訂鏡像資訊清單。

DiskImSize

integer

自訂鏡像大小。單位:GiB。

該空間由系統盤和資料盤組成,您必須保證系統盤的空間大小大於等於匯入的鏡像檔案大小。取值範圍:

  • N=1 時,表示系統盤,取值範圍:1 GiB~2048 GiB。

  • N=2~17 時,表示資料盤。取值範圍:1 GiB~2048 GiB。

當您將來源鏡像檔案上傳至 OSS 後,可以在 OSS Bucket 中查看鏡像檔案的大小。

說明

該參數即將被棄用,為提高相容性,請盡量使用DiskDeviceMapping.N.DiskImageSize參數。

80

Device

string

指定 DiskDeviceMapping.N.Device 在自訂鏡像中的裝置名稱。

說明

該參數即將停止使用,為提高程式碼相容性,建議您盡量不要使用該參數。

null

OSSBucket

string

鏡像檔案所在的 OSS Bucket。

說明

首次匯入鏡像到該 OSS Bucket 前,請參見本文件的介面說明新增 RAM 授權策略,否則會報錯NoSetRoletoECSServiceAccount

ecsimageos

Format

string

鏡像格式。取值範圍:

  • RAW。

  • VHD。

  • QCOW2。

  • VMDK(邀測中)。

預設值:無,表示阿里雲自動檢測鏡像格式,以檢測格式為準。

QCOW2

OSSObject

string

鏡像上傳至 OSS Bucket 後,儲存在 Bucket 中的鏡像檔案的檔案名稱(key)。

CentOS_5.4_32.raw

DiskImageSize

integer

匯入鏡像後,自訂鏡像的空間大小。

該空間由系統盤和資料盤組成,您必須保證系統盤的空間大小大於等於匯入的鏡像檔案大小。取值範圍:

  • N=1 時,表示系統盤,取值範圍:1 GiB~2048 GiB。

  • N=2~17 時,表示資料盤。取值範圍:1 GiB~2048 GiB。

當您將來源鏡像檔案上傳至 OSS 後,可以在 OSS Bucket 中查看鏡像檔案的大小。

80

Tag

array<object>

鏡像的標籤清單。

object

鏡像的標籤清單。

Key

string

鏡像的標籤鍵。N 的取值範圍:1~20。一旦傳入該值,則不允許為空字串。最多支援 128 個字元,不能以aliyun或者acs:開頭,不能包含http://或者https://

TestKey

Value

string

鏡像的標籤值。N 的取值範圍:1~20。一旦傳入該值,允許為空字串。最多支援 128 個字元,不能以acs:開頭,不能包含http://或者https://

TestValue

DetectionStrategy

string

鏡像檢測策略,不配置此參數時不觸發檢測。僅支援標準(Standard)檢測模式。

說明

目前已支援大部分的 Linux/Windows 版本,關於鏡像檢測項與作業系統限制說明,請參見鏡像檢測概述鏡像檢測作業系統限制

Standard

StorageLocationArn

string

指定雲盒的資源名稱(ARN),用於唯一標識雲端儲存位置。

說明

僅當您需要從 OSS ON 雲盒中匯入鏡像檔案時,才需提供此參數的值。如果您使用的儲存服務不是 OSS ON 雲盒,則無需設定此參數。更多資訊,請參見什麼是 OSS ON 雲盒

正確的 ARN 格式應遵循:arn:acs:cloudbox:{RegionId}:{AliUid}:cloudbox/{CloudBoxId}的模式,其中{RegionId}應替換為雲盒實際所在的地域 ID,{AliUid}是阿里雲帳號(主帳號)ID,而{CloudBoxId}是雲盒 ID。

arn:acs:cloudbox:cn-hangzhou:123456:cloudbox/cb-xx***123

DryRun

boolean

是否只預檢此次請求。取值範圍:

  • true:傳送檢查請求,不會查詢資源狀況。檢查項包括 AccessKey 是否有效、RAM 使用者的授權情況和是否填寫了必需參數。如果檢查不通過,則返回對應錯誤。如果檢查通過,則返回錯誤碼DryRunOperation

  • false:傳送正常請求,通過檢查後返回 2XX HTTP 狀態碼並直接查詢資源狀況。

預設值:false。

false

Features

object

鏡像特性相關屬性。

NvmeSupport

string

鏡像是否支援 NVMe。可能值:

  • supported:支援。表示以該鏡像建立的實例支援 NVMe 協定。

  • unsupported:不支援。表示以該鏡像建立的實例不支援 NVMe 協定。

supported

ImdsSupport

string

鏡像的中繼資料存取模式,可能值:

  • v1:透過該鏡像建立 ECS 實例時,不支援將中繼資料存取模式設定為「僅加固模式」。

  • v2:透過該鏡像建立 ECS 實例時,支援將中繼資料存取模式設定為「僅加固模式」。

預設值: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.

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

變更歷史

更多資訊,參考變更詳情