使用本地共享中的映像创建 Azure Stack HCI VM 映像

适用于:Azure Stack HCI 版本 23H2

本文介绍如何使用群集上的本地共享中的源映像为 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 Stack HCI 上的本地共享中的自定义映像,需要满足以下附加先决条件:

    • 应该事先将一个 VHD/VHDX 上传到 Azure Stack HCI 群集上的本地共享。
    • VHDX 映像必须是“第 2 代”类型并已启用安全启动。
    • 必须使用 sysprep /generalize /shutdown /oobe 准备 VHDX 映像。 有关详细信息,请参阅 Sysprep 命令行选项
    • 该映像应该驻留在对群集中的所有服务器可用的群集共享卷上。 支持 Windows 和 Linux 操作系统。

从本地共享中的映像添加 VM 映像

从群集本地共享中的映像开始创建 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>"
    $imageName = <VM image name>
    $imageSourcePath = <path to the source image>
    $osType = "<OS of source image>"
    

    下表介绍了这些参数:

    参数 说明
    subscription 与此映像关联的 Azure Stack HCI 群集的资源组。
    resource_group 与此映像关联的 Azure Stack HCI 群集的资源组。
    location Azure Stack HCI 群集的位置。 例如,它可以是 eastus
    image-path 从本地共享中的映像开始创建的 VM 映像的名称。
    注意:Azure 将拒绝所有包含关键字“Windows”的名称。
    name 群集上源库映像(仅限 VHDX)的路径。 例如 C:\OSImages\winos.vhdx。 请查看源映像的先决条件。
    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:\ClusterStorage\Volume1> $imageName = "myhci-localimage"
    PS C:\ClusterStorage\Volume1> $imageSourcePath = "C:\ClusterStorage\Volume1\Windows_K8s_17763.2928.220505-1621_202205101158.vhdx"
    

从本地共享中的映像创建 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. 从 Azure Stack HCI 群集上的本地共享中的指定映像开始创建 VM 映像。

    az stack-hci-vm image create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --image-path $ImageSourcePath --name $ImageName --os-type $osType --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> az stack-hci-vm image create --subscription $subscription --resource-group $resource_group --custom-location $customLocationID --location $location --image-path $ImageSourcePath --name $ImageName --os-type $osType --storage-path-id $storagepathid
type="CustomLocation" --location $Location --name $mktplaceImage --os-type $osType --image-path $mktImageSourcePath
Command group 'azurestackhci' 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-localimage",
  "location": "eastus",
  "name": "myhci-localimage",
  "properties": {
    "identifier": null,
    "imagePath": null,
    "osType": "Windows",
    "provisioningState": "Succeeded",
    "status": {
      "downloadStatus": {},
      "progressPercentage": 100,
      "provisioningStatus": {
        "operationId": "82f58893-b252-43db-97a9-258f6f7831d9*43114797B86E6D2B28C4B52B02302C81C889DABDD9D890F993665E223A5947C3",
        "status": "Succeeded"
      }
    },
    "storagepathId": "/subscriptions/<Subscription ID>/resourceGroups/myhci-rg/providers/Microsoft.AzureStackHCI/storagecontainers/myhci-storagepath",
    "version": {
      "name": null,
      "properties": {
        "storageProfile": {
          "osDiskImage": {}
        }
      }
    }
  },
  "resourceGroup": "myhci-rg",
  "systemData": {
    "createdAt": "2023-11-02T06:15:10.450908+00:00",
    "createdBy": "guspinto@contoso.com",
    "createdByType": "User",
    "lastModifiedAt": "2023-11-02T06:15:56.689323+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>

后续步骤