將映像版本匯出至受控磁碟

適用於: ✔️ Linux VM ✔️ Windows VM ✔️ 彈性擴展集 ✔️ 統一擴展集

您可以從儲存在 Azure Compute Gallery 的映像版本 (先前稱為共用映像庫)中,將映像版本的 OS 或資料磁碟匯出為受控磁碟。

CLI

使用 az sig image-version list,列出資源庫中的映像版本。 在此範例中,我們正在尋找屬於 myGallery 資源庫中 myImageDefinition 映像定義一部分的所有映像版本。

az sig image-version list \
   --resource-group myResourceGroup\
   --gallery-name myGallery \
   --gallery-image-definition myImageDefinition \
   -o table

source 變數設定為映像版本的識別碼,然後使用 az disk create 來建立受控磁碟。

在此範例中,我們會匯出映像版本的 OS 磁碟,以在名為 myResourceGroup 的資源群組中,於 EastUS 區域中,建立名為 myManagedOSDisk 的受控磁碟。

source="/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<galleryName>/images/<galleryImageDefinition>/versions/<imageVersion>"

az disk create --resource-group myResourceGroup --location EastUS --name myManagedOSDisk --gallery-image-reference $source 

如果您想要從映像版本匯出資料磁碟,請新增 --gallery-image-reference-lun 以指定要匯出之資料磁碟的 LUN 位置。

在此範例中,我們會匯出映像版本 LUN 0 的資料磁碟,以在名為 myResourceGroup 的資源群組中,於 EastUS 區域中 建立名為 myManagedDataDisk 的受控磁碟。

source="/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/galleries/<galleryName>/images/<galleryImageDefinition>/versions/<imageVersion>"

az disk create --resource-group myResourceGroup --location EastUS --name myManagedDataDisk --gallery-image-reference $source --gallery-image-reference-lun 0

PowerShell

使用 get-AzResource 列出資源庫中的映像版本

Get-AzResource `
   -ResourceType Microsoft.Compute/galleries/images/versions | `
   Format-Table -Property Name,ResourceId,ResourceGroupName

一旦您擁有所需的所有資訊,就可以使用 Get-AzGalleryImageVersion 來取得您想要使用的來源映像版本,並將它指派給變數。 在此範例中,我們會在 myResourceGroup 資源群組的 myGallery 來源資源庫中,取得 myImageDefinition 定義的 1.0.0 映像版本。

$sourceImgVer = Get-AzGalleryImageVersion `
   -GalleryImageDefinitionName myImageDefinition `
   -GalleryName myGallery `
   -ResourceGroupName myResourceGroup `
   -Name 1.0.0

source 變數設定為映像版本的識別碼之後,請使用 New-AzDiskConfig 來建立磁碟組態,然後使用 New-AzDisk 來建立磁碟。

在此範例中,我們會匯出映像版本的 OS 磁碟,以在名為 myResourceGroup 的資源群組中,於 EastUS 區域中,建立名為 myManagedOSDisk 的受控磁碟。

建立磁碟組態。

$diskConfig = New-AzDiskConfig `
   -Location EastUS `
   -CreateOption FromImage `
   -GalleryImageReference @{Id = $sourceImgVer.Id}

建立磁碟。

New-AzDisk -Disk $diskConfig `
   -ResourceGroupName myResourceGroup `
   -DiskName myManagedOSDisk

如果您想要匯出映像版本上的資料磁碟,請將 LUN 識別碼新增至磁碟組態,以指定要匯出之資料磁碟的 LUN 位置。

在此範例中,我們會匯出映像版本 LUN 0 的資料磁碟,以在名為 myResourceGroup 的資源群組中,於 EastUS 區域中 建立名為 myManagedDataDisk 的受控磁碟。

建立磁碟組態。

$diskConfig = New-AzDiskConfig `
   -Location EastUS `
   -CreateOption FromImage `
   -GalleryImageReference @{Id = $sourceImgVer.Id; Lun=0}

建立磁碟。

New-AzDisk -Disk $diskConfig `
   -ResourceGroupName myResourceGroup `
   -DiskName myManagedDataDisk

下一步

您也可以從受控磁碟建立映像版本