共用方式為


使用 Azure Marketplace 映像來建立 Azure 本地 VM 映像

適用於:Azure Local 2311.2 和更新版本

本文說明如何使用來自 Azure Marketplace 的來源映像,為 Azure 本機建立虛擬機器 (VM) 映像。 您可以使用 Azure 入口網站 或 Azure CLI 建立 VM 映射,然後使用這些 VM 映射在 Azure 本機上建立 Arc VM。

必要條件

開始之前,請確定下列必要條件已完成。

從 Azure Marketplace 新增 VM 映像

您可以從 Azure Marketplace 映射建立 VM 映射,然後使用此映射在 Azure 本機實例上部署 VM。

請遵循下列步驟,使用 Azure CLI 建立 VM 映射。

登入並設定訂用帳戶

  1. 連接到 Azure Local 環境中的機器

  2. 登入。 類型:

    az login --use-device-code
    
  3. 設定您的訂用帳戶。

    az account set --subscription <Subscription ID>
    

設定一些參數

  1. 為您的訂用帳戶、資源群組、位置、映像的OS類型設定參數。 將中的 < > 參數取代為適當的值。

    $subscription = "<Subscription ID>"
    $resource_group = "<Resource group>"
    $mktplaceImage = "<Marketplace image name>"
    $customLocationName = "<Custom location name>"
    $customLocationID = (az customlocation show --resource-group $resource_group --name "<custom_location_name_for_Azure_Local>" --query id -o tsv)
    $location = "<Location for your Azure Local>"
    $osType = "<OS of source image>"
    

    下表會說明這些參數:

    參數 描述
    subscription 與您的 Azure 本機相關聯的訂用帳戶。
    resource-group 您將此映像與您的 Azure 本地資源群組相關聯。
    name Azure Local 的市集映像名稱。
    customLocation Azure Local 的自訂位置資源識別碼。
    location 您的 Azure 本地配置的位置。 例如,可以是 eastus
    os-type 與來源映像相關聯的操作系統。 這可以是 Windows 或 Linux。

    以下是範例輸出:

    PS C:\Users\azcli> $subscription = "<Subscription ID>"
    PS C:\Users\azcli> $resource_group = "mylocal-rg"
    PS C:\Users\azcli> $mktplaceImage= "mylocal-marketplaceimage"
    PS C:\Users\azcli> $customLocationName = "mylocal-cl"
    PS C:\Users\azcli> $customerLocationID /subscriptions$subscription/resourcegroups/$resource_group/providers/microsoft.extendedlocation/customlocations/$customLocationName
    PS C:\Users\azcli> $location = "eastus"
    PS C:\Users\azcli> $ostype = "Windows"
    

從市集映像建立 VM 映像

  1. 設定其他參數,以指定您想要建立的預定 VM 映像。 您必須包含市集圖像的優惠方案、發行者、SKU 和版本。 將 中的 <> 參數取代為適當的值:

    $publisher = "<Publisher name>"
    $offer = "<OS offer>"
    $sku = "<Image SKU>"
    

    使用下表來尋找可用的市集映像及其屬性值:

    名稱 發行者 提供 SKU(庫存單位)
    Windows 11 企業版 多使用者模式 + Microsoft 365 微軟Windows桌面 office-365 win11-23h2-avd-m365
    win11-24h2-avd-m365
    Windows 10 企業版 多會話 + Microsoft 365 Microsoft Windows 桌面 office-365 win10-21h2-avd-m365
    Windows 11 專業版 微軟 Windows 桌面 windows-11 win11-23h2-pro
    Windows 11 企業版 微軟 Windows 桌面 windows-11 win11-22h2-ent
    win11-23h2-ent
    win11-24h2-ent
    Windows 11 企業版的多重工作階段 微軟 Windows 桌面 windows-11 win11-22h2-avd
    win11-23h2-avd
    win11-24h2-avd
    Windows 10 專業版 微軟 Windows 桌面 windows-10 win10-22h2-pro-g2
    Windows 10 企業版 微軟 Windows Desktop windows-10 win10-22h2-ent-g2
    Windows 10 企業版的多重工作階段 微軟Windows桌面 windows-10 win10-22h2-avd
    Windows Server 2025 Datacenter:Azure Edition microsoftwindowsserver windowsserver 2025-datacenter-azure-edition-smalldisk
    2025-datacenter-azure-edition-core
    2025-資料中心-Azure版
    Windows Server 2022 Datacenter:Azure Edition microsoftwindowsserver windowsserver 2022-Datacenter Azure 版 Hotpatch (熱修補)
    2022-datacenter-azure-edition-core
    2022-datacenter-azure-edition
    Windows Server 2019 microsoftwindowsserver windowsserver 2019-datacenter-gensecond
    2019-datacenter-core-g2
    SQL Server 2022 Enterprise 在 Windows Server 2022 上 microsoftsqlserver sql2022-ws2022 enterprise-gen2
    standard-gen2

    如果您想要建立 Windows Server 2019 Datacenter 映射,您會有下列參數:

    $publisher = "microsoftwindowsserver" 
    $offer = "windowsserver" 
    $sku = "2019-datacenter-gensecond"
    
  2. 從指定的市集映射開始建立 VM 映射:

    az stack-hci-vm image create --resource-group $resource_group --custom-location $customLocationID --name $mktplaceImage --os-type $ostype --offer $offer --publisher $publisher --sku $sku 
    

以下是範例輸出:

PS C:\Users\azcli> az stack-hci-vm image create --custom-location $cl --name $mktplaceImage --os-type $ostype --resource-group $rg --publisher $publisher --offer $offer --sku $sku 
{ 
  "extendedLocation": { 
    "name": “/subscriptions/<Subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.ExtendedLocation/customLocations/mylocal-cl", 
    "type": "CustomLocation" 
  }, 
  "id": "/subscriptions/<Subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/marketplacegalleryimages/myhci-marketplaceimage", 
\ 
  "location": "eastus", 
  "name": "myhci-marketplaceimage", 
  "properties": { 
    "cloudInitDataSource": null, 
    "containerId": null, 
    "hyperVGeneration": null, 
    "identifier": { 
      "offer": "windowsserver", 
      "publisher": "microsoftwindowsserver", 
      "sku": "2019-datacenter-gensecond" 
    }, 
    "osType": "Windows", 
    "provisioningState": "Succeeded", 
    "status": { 
      "downloadStatus": { 
        "downloadSizeInMb": 10832 
      }, 
      "errorCode": "", 
      "errorMessage": "", 
      "progressPercentage": 100, 
      "provisioningStatus": { 
        "operationId": "13efc468-7473-429f-911b-858c1e6fc1d5*B11A62EE76B08EF194F8293CDD40F7BC71BFB93255D5A99DD11B4167690752D9", 
        "status": "Succeeded" 
      } 
    }, 
    "version": { 
      "name": "17763.6293.240905", 
      "properties": { 
        "storageProfile": { 
          "osDiskImage": { 
            "sizeInMb": 130050 
          } 
        } 
      } 

    } 
  }, 
  "resourceGroup": "mylocal-rg", 
  "systemData": { 
    "createdAt": "2024-09-23T18:53:13.734389+00:00", 
    "createdBy": "guspinto@contoso.com", 
    "createdByType": "User", 
    "lastModifiedAt": "2024-09-23T19:06:07.532276+00:00", 
    "lastModifiedBy": "319f651f-7ddb-4fc6-9857-7aef9250bd05", 
    "lastModifiedByType": "Application" 
  }, 

  "tags": null, 
  "type": "microsoft.azurestackhci/marketplacegalleryimages" 
} 

如需此 CLI 命令的詳細資訊,請參閱 az stack-hci-vm 映射

列出虛擬機器映像

您必須檢視 VM 映射清單,以選擇要管理的映像。

請遵循下列步驟,使用 Azure CLI 列出 VM 映射。

  1. 以系統管理員身分執行 PowerShell。

  2. 設定部分參數。

    $subscription = "<Subscription ID associated with your Azure Local>"
    $resource_group = "<Resource group name for your Azure Local>"
    
  3. 列出與您的 Azure 本地相關聯的所有虛擬機映像。 執行以下命令:

    az stack-hci-vm image list --subscription $subscription --resource-group $resource_group
    

    視所使用的命令而定,將會列出與您的 Azure 本地環境相關的一組對應圖像。

    • 如果您只指定訂用帳戶,命令會列出訂用帳戶中的所有映像。
    • 如果您同時指定訂用帳戶和資源群組,命令會列出資源群組中的所有映像。

    這些映像包括:

    • 來自市集映像的虛擬機映像。
    • 位於您的 Azure 存儲帳戶中的自訂映像,或位於系統的本地共用或已連接到您系統的用戶端上的自訂映像。

以下是範例輸出。

PS C:\Users\azcli> az stack-hci-vm image list --subscription "<Subscription ID>" --resource-group "myhci-rg"
Command group 'stack-hci-vm' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
[
  {
    "extendedLocation": {
      "name": "/subscriptions/<Subscription ID>/resourcegroups/myhci-rg/providers/microsoft.extendedlocation/customlocations/myhci-cl",
      "type": "CustomLocation"
    },
    "id": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/microsoft.azurestackhci/marketplacegalleryimages/w
inServer2022Az-01",
    "location": "eastus",
    "name": "winServer2022Az-01",
    "properties": {
      "hyperVGeneration": "V2",
      "identifier": {
        "offer": "windowsserver",
        "publisher": "microsoftwindowsserver",
        "sku": "2022-datacenter-azure-edition-core"
      },
      "imagePath": null,
      "osType": "Windows",
      "provisioningState": "Succeeded",
      "status": {
        "downloadStatus": {
          "downloadSizeInMB": 6710
        },
        "progressPercentage": 100,
        "provisioningStatus": {
          "operationId": "19742d69-4a00-4086-8f17-4dc1f7ee6681*E1E9889F0D1840B93150BD74D428EAE483CB67B0904F9A198C161AD471F670ED",
          "status": "Succeeded"
        }
      },
      "storagepathId": null,
      "version": {
        "name": "20348.2031.231006",
        "properties": {
          "storageProfile": {
            "osDiskImage": {
              "sizeInMB": 130050
            }
          }
        }
      }
    },
    "resourceGroup": "mylocal-rg",
    "systemData": {
      "createdAt": "2023-10-30T21:44:53.020512+00:00",
      "createdBy": "guspinto@contoso.com",
      "createdByType": "User",
      "lastModifiedAt": "2023-10-30T22:08:25.495995+00:00",
      "lastModifiedBy": "319f651f-7ddb-4fc6-9857-7aef9250bd05",
      "lastModifiedByType": "Application"
    },
    "tags": {},
    "type": "microsoft.azurestackhci/marketplacegalleryimages"
  }
]
PS C:\Users\azcli>

如需此 CLI 命令的詳細資訊,請參閱 az stack-hci-vm image list

檢視 VM 映像屬性

您可能想要先檢視 VM 映像檔案的屬性,然後再使用該映像檔案來建立 VM。 請遵循下列步驟來檢視影像屬性:

請遵循下列步驟,使用 Azure CLI 來檢視映像的屬性:

  1. 以系統管理員身分執行 PowerShell。

  2. 設定下列參數。

    $subscription = "<Subscription ID>"
    $resource_group = "<Azure Local resource group>"
    $mktplaceImage = "<Marketplace image name>"
    
  3. 您可以透過兩種不同的方式檢視影像屬性:指定識別碼或指定名稱和資源群組。 指定 Marketplace 映射識別符時,請執行下列步驟:

    1. 設定下列參數。

      $mktplaceImageID = "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/galleryimages/mylocal-marketplaceimage"
      
    2. 執行下列命令以檢視屬性。

      az stack-hci-vm image show --ids $mktplaceImageID

      以下是此指令的範例輸出:

      PS C:\Users\azcli> az stack-hci-vm image show --ids $mktplaceImageID
      Command group 'stack-hci-vm' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
      {
        "extendedLocation": {
          "name": "/subscriptions/<Subscription ID>/resourcegroups/myhci-rg/providers/microsoft.extendedlocation/customlocations/mylocal-cl",
          "type": "CustomLocation"
        },
        "id": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/galleryimages/mylocal-marketplaceimage",
        "location": "eastus",
        "name": "mylocal-marketplaceimage",
        "properties": {
          "containerName": null,
          "hyperVGeneration": null,
          "identifier": null,
          "imagePath": null,
          "osType": "Windows",
          "provisioningState": "Succeeded",
          "status": null,
          "version": null
        },
        "resourceGroup": "mylocal-rg",
        "systemData": {
          "createdAt": "2022-08-05T20:52:38.579764+00:00",
          "createdBy": "guspinto@microsoft.com",
          "createdByType": "User",
          "lastModifiedAt": "2022-08-05T20:52:38.579764+00:00",
          "lastModifiedBy": "guspinto@microsoft.com",
          "lastModifiedByType": "User"
        },
        "tags": null,
        "type": "microsoft.azurestackhci/galleryimages"
      }
      PS C:\Users\azcli> 
      

更新 VM 映像

重要

由於需要進行額外的驗證,最新的更新可能需要一些時間才能顯示在您的 VM 映像上。

當 Azure Marketplace 中有新的更新映像可用時,Azure 本機上的 VM 映射會過時,且應該更新。 更新作業不是影像的原地更新。 您可以查看哪些 VM 映像檔有可用的更新版本,並選擇要更新的映像檔。 更新之後,建立 VM 映射作業會使用新的更新映像。

若要更新 VM 映射,請使用 Azure 入口網站 中的下列步驟。

  1. 若要查看是否有可用的更新,請從清單檢視中選取 VM 映射。

    螢幕快照顯示有 VM 映像更新可供下載。

    概觀 頁面中,如果有新的 VM 映像可以下載,您將會看到橫幅顯示該下載資訊。 若要更新至新的影像,請選取 箭號圖示

    顯示 VM 映像詳細數據中可供下載之新 VM 映像的螢幕快照。

  2. 查看影像詳情,然後選取查看並新建。 根據預設,新映像會使用與上一個映像相同的資源群組和實例詳細數據。

    新映像的名稱會根據上一個映像的名稱遞增。 例如,名為 winServer2022-01 的現有映像會有名為 winServer2022-02 的更新映像。

    此螢幕快照顯示新 VM 映像的 [檢閱和建立] 對話框。

  3. 若要完成作業,請選取 [建立]

    此螢幕快照顯示新 VM 映像的 [建立映像] 對話框。

    建立新的 VM 映射之後,請使用新的映像建立 VM,並確認 VM 是否正常運作。 驗證之後,您可以刪除舊的 VM 映像。

刪除 VM 映像

如果下載因為某些原因而失敗,或不再需要映像,您可能會想要刪除 VM 映射。 請遵循下列步驟來刪除 VM 映像。

  1. 以系統管理員身分執行 PowerShell。

  2. 設定以下參數︰

    $subscription = "<Subscription ID>"
    $resource_group = "<Azure Local resource group>"
    $mktplaceImage = "<Markeplace image name>"    
    
  3. 拿掉現有的 VM 映像。 執行以下命令:

    az stack-hci-vm image delete --subscription $subscription --resource-group $resource_group --name $mktplaceImage --yes
    

您可以刪除映像兩種方式:

  • 指定名稱和資源群組。
  • 指定標識碼。

刪除圖片之後,您可以檢查圖片是否已被移除。 以下是藉由指定名稱和資源群組來刪除映像時的範例輸出。

PS C:\Users\azcli> $subscription = "<Subscription ID>"
PS C:\Users\azcli> $resource_group = "mylocal-rg"
PS C:\Users\azcli> $mktplaceImage = "mymylocal-marketplaceimage"
PS C:\Users\azcli> az stack-hci-vm image delete --name $mktplaceImage --resource-group $resource_group
Command group 'stack-hci-vm' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
Are you sure you want to perform this operation? (y/n): y
PS C:\Users\azcli> az stack-hci-vm image show --name $mktplaceImage --resource-group $resource_group
Command group 'stack-hci-vm' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
ResourceNotFound: The Resource 'Microsoft.AzureStackHCI/marketplacegalleryimages/myhci-marketplaceimage' under resource group 'mylocal-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
PS C:\Users\azcli>

下一步