Share via


使用特製化映像版本建立 VM

適用於: ✔️ Linux VM ✔️ Windows VM

從儲存在 Azure Compute Gallery (先前稱為共用映像庫) 中的特殊映像版本建立 VM。 如果您想要使用通用映像版本建立 VM,請參閱從通用映像版本建立 VM

本文說明如何從特製化映像建立 VM:

重要

當您使用特製化映像來建立新的 VM 時,新的 VM 會保留原始 VM 的電腦名稱。 也會保留其他電腦特定資訊,例如 CMID。 這項重複的資訊可能會導致問題。 複製 VM 時,請留意您的應用程式會依賴哪些類型的電腦特定資訊。

從內部資源庫建立 VM。

使用 az sig image-definition list 來列出資源庫中的映像定義,以查看定義的名稱和識別碼。

resourceGroup=myGalleryRG
gallery=myGallery
az sig image-definition list \
   --resource-group $resourceGroup \
   --gallery-name $gallery \
   --query "[].[name, id]" \
   --output tsv

使用 az vm create 建立 VM,並使用 --specialized 參數來指出映像是特製化映像。

使用 --image 的映像定義識別碼,從可用的最新映像版本建立 VM。 您也可以藉由提供 --image 的映像版本識別碼,從特定版本建立 VM。

在此範例中,我們會從最新版本的 myImageDefinition 映像建立 VM。

az group create --name myResourceGroup --location eastus
az vm create --resource-group myResourceGroup \
    --name myVM \
    --image "/subscriptions/<Subscription ID>/resourceGroups/myGalleryRG/providers/Microsoft.Compute/galleries/myGallery/images/myImageDefinition" \
    --specialized

RBAC - 在組織內

如果資源庫所在的訂用帳戶位於相同的租用戶,則可使用透過 RBAC 共用的映象,透過 CLI 和 PowerShell 建立 VM。

您需要所要使用的映象 imageID,並確保映像已複寫到所要建立 VM 的區域。


image="/subscriptions/<Subscription ID>/resourceGroups/myGalleryRG/providers/Microsoft.Compute/galleries/myGallery/images/myImageDefinition"
vmResourceGroup='myResourceGroup'
location='westus'
vmName='myVM'

az group create --name $vmResourceGroup --location $location

az vm create\
   --resource-group $vmResourceGroup \
   --name $vmName \
   --image $image \
   --specialized

RBAC - 來自其他租用戶或組織

如果所要使用的映像儲存在非相同租用戶 (目錄) 的資源庫,則您必須登入每個租用戶以驗證您具有存取權。

您需要所要使用的映象 imageID,並確保映像已複寫到所要建立 VM 的區域。 您也需要來源資源庫的 tenantID 和所要建立 VM 的 tenantID

您必須登入儲存映像的租用戶,取得存取權丈,然後登入所要建立 VM 的租用戶。 這是 Azure 驗證您具有映像存取權的方式。

tenant1='<ID for tenant 1>'
tenant2='<ID for tenant 2>'

az account clear
az login --tenant $tenant1
az account get-access-token 
az login --tenant $tenant2
az account get-access-token

使用 az vm create 建立 VM,並使用 --specialized 參數來指出映像是特製化映像。


imageid=""/subscriptions/<Subscription ID>/resourceGroups/myGalleryRG/providers/Microsoft.Compute/galleries/myGallery/images/myImageDefinition""
resourcegroup="myResourceGroup"
location="West US 3"
name='myVM'

az group create --name $resourcegroup --location $location
az vm create --resource-group $resourcegroup \
    --name $name \
    --image $image \
    --specialized

重要

Microsoft 不支援社群資源庫中的映像。

報告社群映像的問題

使用社群提交的虛擬機器映像有數個風險。 映像可能包含惡意程式碼、安全性弱點或違反某人智慧財產權。 為了協助建立安全可靠的社群體驗,您可在發現這些問題時報告映像。

報告社群資源庫問題的最簡單方式是使用入口網站,這會預設填入報告的諮詢:

  • 針對連結問題或映像定義中欄位的其他資訊,請選取 [報告社群映像]
  • 如果映像版本包含惡意程式碼或特定映像版本發生其他問題,請在映像版本表格的 [報告版本] 資料行下選取 [報告]

您也可使用下列連結以報告問題,但不會預先填入表單:

若要使用共用至社群資源庫的映像建立 VM,請為 --image 使用映像的唯一識別碼,其格式如下:

/CommunityGalleries/<community gallery name, like: ContosoImages-1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f>/Images/<image name>/Versions/latest

身為終端使用者,若要取得社群資源庫的公用名稱,您必須使用入口網站。 依序移至 [虛擬機器]>[建立]>[Azure 虛擬機器]>[映像]>[查看所有映像]>[社群映像]>[公開資源庫名稱]

使用 az sig image-definition list-community 列出社群資源庫中可用的所有映像定義。 在此範例中,我們會列出美國西部ContosoImage 資源庫中的所有映像,並依名稱列出建立 VM、OS 和 OS 狀態所需的唯一識別碼。

 az sig image-definition list-community \
   --public-gallery-name "ContosoImages-1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f" \
   --location westus \
   --query [*]."{Name:name,ID:uniqueId,OS:osType,State:osState}" -o table

若要從社群資源庫中的一般化映像建立 VM,請參閱從一般化映像版本建立 VM

使用 az vm create 建立 VM,並使用 --specialized 參數來指出映像是特製化映像。

在此範例中,我們會從最新版本的 myImageDefinition 映像建立 VM。

az group create --name myResourceGroup --location eastus
az vm create --resource-group myResourceGroup \
    --name myVM \
    --image "/CommunityGalleries/ContosoImages-f61bb1d9-3c5a-4ad2-99b5-744030225de6/Images/LinuxSpecializedVersions/latest" \
    --specialized

使用社群映像時,系統會提示您接受法律條款。 訊息如下所示:

To create the VM from community gallery image, you must accept the license agreement and privacy statement: http://contoso.com. (If you want to accept the legal terms by default, please use the option '--accept-term' when creating VM/VMSS) (Y/n): 

重要

Azure Compute Gallery - 直接共用資源庫目前為「預覽」,並遵守 Azure Compute Gallery 的預覽條款

若要在預覽期間將映像發佈至直接共用資源庫,您必須在 https://aka.ms/directsharedgallery-preview 註冊。 所有 Azure 使用者都可以從直接共用資源庫建立 VM。

在預覽期間,您必須建立新的資源庫,並將屬性 sharingProfile.permissions 設定為 Groups。 使用 CLI 建立資源庫時,請使用 --permissions groups 參數。 您無法使用現有的資源庫,目前無法更新此屬性。

若要使用與訂用帳戶或租用戶共用的最新版本映像來建立 VM,您需要下列格式的映像唯一識別碼:

/SharedGalleries/<uniqueID>/Images/<image name>/Versions/latest

若要尋找與您共用的資源庫的 uniqueID,請使用 az sig list-shared。 在此範例中,我們在美國西部區域尋找資源庫。

region=westus
az sig list-shared --location $region --query "[].name" -o tsv

使用資源庫名稱來尋找所有可用的映像。 在此範例中,我們列出「美國西部」中的所有映像,並依名稱列出建立 VM、OS 和 OS 狀態所需的唯一識別碼。

galleryName="1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f-myDirectShared"
 az sig image-definition list-shared \
   --gallery-unique-name $galleryName \
   --location $region \
   --query [*]."{Name:name,ID:uniqueId,OS:osType,State:osState}" -o table

請確認映像的狀態為 Specialized。 如果您想要使用狀態為 Generalized 的映像,請參閱從一般化映像版本建立 VM

使用 az vm create 建立 VM,並使用 --specialized 參數來指出映像是特製化映像。

使用 Id 並附加 /Versions/latest,以使用最新版本作為 `--image`` 的值,藉此建立 VM。

在此範例中,我們會從最新版本的 myImageDefinition 映像建立 VM。

imgDef="/SharedGalleries/1a2b3c4d-1234-abcd-1234-1a2b3c4d5e6f-MYDIRECTSHARED/Images/myDirectDefinition/Versions/latest"
vmResourceGroup=myResourceGroup
location=westus
vmName=myVM

az group create --name $vmResourceGroup --location $location

az vm create\
   --resource-group $vmResourceGroup \
   --name $vmName \
   --image $imgDef \
   --specialized

下一步