使用 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 存储帐户中的自定义映像,需要满足以下额外先决条件:

    • 应在 Azure 存储帐户中加载一个 VHD。 了解如何在 Azure 存储帐户中上传 VHD 映像
    • 如果使用 VHDX:
      • VHDX 映像必须是“第 2 代”类型并已启用安全启动。
      • 必须使用 sysprep /generalize /shutdown /oobe 准备 VHDX 映像。 有关详细信息,请参阅 Sysprep 命令行选项

从 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>"
$location = "<Location for your Azure Stack HCI cluster>"
$osType = "<OS of source image>"
$imageName = "<VM image name>"
$imageSourcePath = "<path to the source image in the Storage account>"

下表介绍了这些参数:

参数 说明
subscription 与此映像关联的 Azure Stack HCI 群集的资源组。
resource_group 与此映像关联的 Azure Stack HCI 群集的资源组。
location Azure Stack HCI 群集的位置。 例如,它可以是 eastus
imageName 从本地共享中的映像开始创建的 VM 映像的名称。
注意:Azure 将拒绝所有包含关键字“Windows”的名称。
imageSourcePath 存储帐户中映像的 Blob SAS URL 的路径。 有关详细信息,请参阅有关如何获取存储帐户中映像的 Blob SAS URL 的说明。
注意:请确保使用双引号转义路径中的所有 & 字符,并将整个路径字符串括在单引号中。
os-type 与源映像关联的操作系统。 这可以是 Windows 或 Linux。

下面是示例输出:

PS C:\Users\azcli> $subscription = "<Subscription ID>"
PS C:\Users\azcli> $resource_group = "myhci-rg"
PS C:\Users\azcli> $location = "eastus"
PS C:\Users\azcli> $osType = "Windows"
PS C:\Users\azcli> $imageName = "myhci-storacctimage"
PS C:\Users\azcli> $imageSourcePath = 'https://vmimagevhdsa1.blob.core.windows.net/vhdcontainer/Windows_InsiderPreview_ServerStandard_en-us_VHDX_25131.vhdx?sp=r"&"st=2022-08-05T18:41:41Z"&"se=2022-08-06T02:41:41Z"&"spr=https"&"sv=2021-06-08"&"sr=b"&"sig=X7A98cQm%2FmNRaHmTbs9b4OWVv%2F9Q%2FJkWDBHVPyAc8jo%3D'

从 Azure 存储帐户中的映像创建 VM 映像

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

    $customLocationID=(az customlocation show --resource-group $resource_group --name "<custom location name for HCI cluster>" --query id -o tsv)
    
  2. 从指定的市场映像开始创建 VM 映像。 确保指定该市场映像的产品/服务、发布者、SKU 和版本。

    az stack-hci-vm image create --subscription $subscription --resource-group $resource_Group --custom-location $customLocationID --location $location --name $imageName --os-type $osType --image-path $imageSourcePath --storage-path-id $storagepathid
    

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

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

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

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

下面是示例输出:

PS > $customLocationID=(az customlocation show --resource-group $resource_group --name "myhci-cl" --query id -o tsv)
PS C:\Users\azcli> az stack-hci-vm image create --subscription $subscription --resource-group $resource_Group --custom-location $customLocationID --location $location --name $imageName --os-type $osType --image-path $imageSourcePath --storage-path-id $storagepathid
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-storacctimage",
  "location": "eastus",
  "name": "windos",
  "properties": {
    "identifier": null,
    "imagePath": null,
    "osType": "Windows",
    "provisioningState": "Succeeded",
    "status": {
      "downloadStatus": {
        "downloadSizeInMB": 7876
      },
        "progressPercentage": 100,
      "provisioningStatus": {
        "operationId": "cdc9c9a8-03a1-4fb6-8738-7a8550c87fd1*31CE1EA001C4B3E38EE29B78ED1FD47CCCECF78B4CEA9E9A85C0BAEA5F6D80CA",
        "status": "Succeeded"
      }
    },
    "storagepathId": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/storagecontainers/myhci-storagepath",
    "version": null
  },
  "resourceGroup": "myhci-rg",
  "systemData": {
    "createdAt": "2023-11-03T20:17:10.971662+00:00",
    "createdBy": "guspinto@contoso.com",
    "createdByType": "User",
    "lastModifiedAt": "2023-11-03T21:08:01.190475+00:00",
    "lastModifiedBy": "319f651f-7ddb-4fc6-9857-7aef9250bd05",
    "lastModifiedByType": "Application"
  },
  "tags": null,
  "type": "microsoft.azurestackhci/galleryimages"
}
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 映像

如果由于某种原因下载失败或不再需要该映像,可能需要删除 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>

后续步骤