使用 Azure 市场 映像创建 Azure Stack HCI VM 映像

适用于:Azure Stack HCI 版本 23H2

本文介绍如何使用 Azure 市场中的源映像为 Azure Stack HCI 创建虚拟机 (VM) 映像。 可以使用 Azure 门户或 Azure CLI 创建 VM 映像,然后使用这些 VM 映像在 Azure Stack HCI 上创建 Arc VM。

先决条件

在开始之前,请确保满足以下先决条件。

  • 请确保查看并 完成先决条件

  • 你有权访问已部署的 Azure Stack HCI 系统,该系统具有 Arc 资源网桥和自定义位置。

    • 转到 Azure Stack HCI 系统资源中的 “概述 > 服务器 ”页。 验证 Azure Arc 是否显示为 “已连接”。 还应看到群集的自定义位置和 Arc 资源网桥。

      Azure Stack HCI 群集资源中“概述”页的屏幕截图,其中显示 Azure Arc 已连接。

从 Azure 市场添加 VM 映像

从Azure 市场映像开始创建 VM 映像,然后使用此映像在 Azure Stack HCI 群集上部署 VM。

按照以下步骤使用 Azure CLI 创建 VM 映像。

登录并设置订阅

  1. 连接到 Azure Stack HCI 系统上的服务器。

  2. 登录。 键入:

    az login --use-device-code
    
  3. 设置订阅。

    az account set --subscription <Subscription ID>
    

设置一些参数

  1. 为映像的订阅、资源组、位置和 OS 类型设置参数。 请将 < > 中的参数替换为适当的值。

    $subscription = "<Subscription ID>"
    $resource_group = "<Resource group>"
    $customLocationName = "<Custom location name>"
    $customLocationID
    /subscriptions/<Subscription ID>/resourcegroups/$resource_group/providers/microsoft.extendedlocation/customlocations/$customLocationName
    $location = "<Location for your Azure Stack HCI cluster>"
    $osType = "<OS of source image>"
    

    下表介绍了这些参数:

    参数 说明
    subscription 与你的 Azure Stack HCI 群集关联的订阅。
    resource-group 与此映像关联的 Azure Stack HCI 群集的资源组。
    location Azure Stack HCI 群集的位置。 例如,它可以是 eastus
    os-type 与源映像关联的操作系统。 这可以是 Windows 或 Linux。

    下面是示例输出:

    PS C:\Users\azcli> $subscription = "<Subscription ID>"
    PS C:\Users\azcli> $resource_group = "myhci-rg"
    PS C:\Users\azcli> $customLocationName = "myhci-cl"
    PS C:\Users\azcli> $location = "eastus"
    PS C:\Users\azcli> $ostype = "Windows"
    

从市场映像创建 VM 映像

  1. 选择一个自定义位置来部署 VM 映像。 该自定义位置应该对应于 Azure Stack HCI 群集的自定义位置。 获取 Azure Stack HCI 群集的自定义位置 ID。 运行以下命令:

    $customLocationID=(az customlocation show --resource-group $resource_group --name "<custom location name for Azure Stack HCI cluster>" --query id -o tsv)
    
  2. 从指定的市场映像开始创建 VM 映像。 确保指定该市场映像的产品/服务、发布者、SKU 和版本。 使用下表查找可用的市场映像及其属性值:

    名称 Publisher 产品/服务 SKU 版本号
    Windows 11 企业版多会话 + Microsoft 365 应用版版本 21H2- Gen2 microsoftwindowsdesktop office-365 win10-21h2-avd-m365-g2 19044.3570.231010
    Windows 10 企业版多会话版本 21H2 + Microsoft 365 应用版-Gen2 microsoftwindowsdesktop office-365 win11-21h2-avd-m365 22000.2538.231010
    Windows 10 企业版多会话版本 21H2- Gen2 microsoftwindowsdesktop windows-10 win10-21h2-avd-g2 19044.3570.231001
    Windows 11 企业版多会话版本 21H2- Gen2 microsoftwindowsdesktop windows-11 win11-21h2-avd 22000.2538.231001
    Windows 11 企业版多会话版本 22H2 - Gen2 microsoftwindowsdesktop windows-11 win11-22h2-avd 22621.2428.231001
    Windows 11版本 22H2 企业版多会话 + Microsoft 365 应用版 (预览版) - Gen2 microsoftwindowsdesktop windows11preview win11-22h2-avd-m365 22621.382.220810
    Windows Server 2022 Datacenter:Azure Edition - Gen2 microsoftwindowsserver windowsserver 2022-datacenter-azure-edition 20348.2031.231006
    Windows Server 2022 Datacenter:Azure Edition Core - Gen2 microsoftwindowsserver windowsserver 2022-datacenter-azure-edition-core 20348.2031.231006
    Windows Server 2022 Datacenter:Azure Edition 热补丁 - Gen2 microsoftwindowsserver windowsserver 2022-datacenter-azure-edition-hotpatch 20348.2031.231006
    az stack-hci-vm image create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --name "<VM image name>" --os-type $ostype --offer "windowsserver" --publisher "<Publisher name>" --sku "<SKU>" --version "<Version number>" --storage-path-id $storagepathid
    

    将针对 VM 映像启动一个部署作业。

    在此示例中,存储路径是使用 --storage-path-id 标志指定的,并确保工作负载数据 (包括 VM、VM 映像、非 OS 数据磁盘) 放置在指定的存储路径中。

    如果未指定标志,则工作负荷数据会自动放置在高可用性存储路径中。

映像部署需要几分钟才能完成。 下载映像所需的时间取决于市场映像的大小,以及下载时可用的网络带宽。

下面是示例输出:

PS C:\Users\azcli> $customLocationID=(az customlocation show --resource-group $resource_group --name "myhci-cl" --query id -o tsv)
PS C:\Users\azcli> $customLocationID
/subscriptions/<Subscription ID>/resourcegroups/myhci-rg/providers/microsoft.extendedlocation/customlocations/myhci-cl
PS C:\Users\azcli> az stack-hci-vm image create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --name "myhci-marketplaceimage" --os-type $ostype --offer "windowsserver" --publisher "microsoftwindowsserver" --sku "2022-datacenter-azure-edition-core" --version "20348.2031.231006" --storage-path-id $storagepathid
{
  "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/myhci-marketplaceimage",
  "location": "eastus",
  "name": "myhci-marketplaceimage",
  "properties": {
    "identifier": {
      "offer": "windowsserver",
      "publisher": "microsoftwindowsserver",
      "sku": "2022-datacenter-azure-edition-core"
    },
    "imagePath": null,
    "osType": "Windows",
    "provisioningState": "Succeeded",
    "status": {
      "downloadStatus": {
        "downloadSizeInMB": 6750
      },
      "progressPercentage": 98,
      "provisioningStatus": {
        "operationId": "13be90e0-a780-45bf-a84a-ae91b6e5e468*A380D53083FF6B0A3A157ED7DFD00D33F6B3D40D5559D11AEAED6AD68F7F1A4A",
        "status": "Succeeded"
      }
    },
    "storagepathId": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/storagecontainers/myhci-storagepath",
    "version": {
      "name": "20348.2031.231006",
      "properties": {
        "storageProfile": {
          "osDiskImage": {
            "sizeInMB": 130050
          }
        }
      }
    }
  },
  "resourceGroup": "myhci-rg",
  "systemData": {
    "createdAt": "2023-10-27T21:43:15.920502+00:00",
    "createdBy": "guspinto@contoso.com",
    "createdByType": "User",
    "lastModifiedAt": "2023-10-27T22:06:15.092321+00:00",
    "lastModifiedBy": "319f651f-7ddb-4fc6-9857-7aef9250bd05",
    "lastModifiedByType": "Application"
  },
  "tags": null,
  "type": "microsoft.azurestackhci/marketplacegalleryimages"
}

PS C:\Users\azcli>

列出 VM 映像

需要查看 VM 映像列表才能选择要管理的映像。

按照以下步骤使用 Azure CLI 列出 VM 映像。

  1. 以管理员身份运行 PowerShell。

  2. 设置一些参数。

    $subscription = "<Subscription ID associated with your cluster>"
    $resource_group = "<Resource group name for your cluster>"
    
  3. 列出与你的群集关联的所有 VM 映像。 运行以下命令:

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

    根据所用的命令,将列出一组与 Azure Stack HCI 群集关联的相应映像。

    • 如果你仅指定订阅,则该命令会列出该订阅中的所有映像。
    • 如果你同时指定订阅和资源组,则该命令会列出该资源组中的所有映像。

    这些映像包括:

    • 市场映像中的 VM 映像。
    • 驻留在你的 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": "myhci-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>

查看 VM 映像属性

在使用映像创建 VM 之前,可能需要先查看 VM 映像的属性。 按照以下步骤查看映像属性:

按照以下步骤使用 Azure CLI 查看映像的属性:

  1. 以管理员身份运行 PowerShell。

  2. 设置以下参数。

    $subscription = "<Subscription ID>"
    $resource_group = "<Cluster resource group>"
    $mktplaceImage = "<Marketplace image name>"
    
  3. 可以通过两种不同的方式查看映像属性:指定 ID,或指定名称和资源组。 指定市场映像 ID 时,请执行以下步骤:

    1. 设置以下参数。

      $mktplaceImageID = "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/galleryimages/myhci-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/myhci-cl",
          "type": "CustomLocation"
        },
        "id": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/galleryimages/myhci-marketplaceimage",
        "location": "eastus",
        "name": "myhci-marketplaceimage",
        "properties": {
          "containerName": null,
          "hyperVGeneration": null,
          "identifier": null,
          "imagePath": null,
          "osType": "Windows",
          "provisioningState": "Succeeded",
          "status": null,
          "version": null
        },
        "resourceGroup": "myhci-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 映像

当 Azure 市场中有新的已更新映像可用时,Azure Stack HCI 群集上的 VM 映像将过时,应进行更新。 更新操作不是映像的就地更新。 相反,可以查看已更新映像可用于哪些 VM 映像,并选择要更新的映像。 更新后,创建 VM 映像操作将使用新的已更新映像。

若要更新 VM 映像,请在 Azure 门户中使用以下步骤。

  1. 要查看更新是否可用,请从列表视图中选择 VM 映像。

    显示虚拟机映像更新可供下载的屏幕截图。

    在“概览”边栏选项卡中,会看到横幅,显示可供下载的新 VM 映像(如果有)。 要更新到新映像,请选择箭头图标。

    在 VM 映像详细信息中显示可供下载的新 VM 映像的屏幕截图。

  2. 查看映像详细信息,然后选择“查看并创建”。 默认情况下,新映像使用与前一个映像相同的资源组和实例详细信息。

    新图像的名称将根据上一个图像的名称递增。 例如,名为 winServer2022-01 的现有映像将具有名为 winServer2022-02 的更新映像。

    显示新 VM 映像的“查看并创建”对话框的屏幕截图。

  3. 要完成操作,请选择“创建”。

    显示新 VM 映像的创建映像对话框的屏幕截图。

    创建新虚拟机映像后,使用新映像创建虚拟机,并验证虚拟机是否正常工作。 验证后,可以删除旧 VM 映像。

    注意

    在本版本中,如果与 VM 映像关联的 VM 正在运行,则不能删除该映像。 停止 VM,然后删除 VM 映像。

删除 VM 映像

如果由于某种原因下载失败或不再需要该映像,可能需要删除 VM 映像。 按照以下步骤删除 VM 映像。

  1. 以管理员身份运行 PowerShell。

  2. 设置以下参数。

    $subscription = "<Subscription ID>"
    $resource_group = "<Cluster resource group>"
    $galleryImageName = "<Gallery image name>"    
    
  3. 删除现有的 VM 映像。 运行以下命令:

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

可以通过两种方式删除映像:

  • 指定名称和资源组。
  • 指定 ID。

删除某个映像后,可以检查该映像是否已删除。 下面是通过指定名称和资源组删除映像后的示例输出。

PS C:\Users\azcli> $subscription = "<Subscription ID>"
PS C:\Users\azcli> $resource_group = "myhci-rg"
PS C:\Users\azcli> $mktplaceImage = "myhci-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 'myhci-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
PS C:\Users\azcli>

后续步骤