共用方式為


在 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 儲存體 帳戶中的自定義映像,您有下列額外的必要條件:

    • 您應該會在 Azure 儲存體 帳戶中載入 VHD。 瞭解如何在 Azure 儲存體 帳戶中上傳 VHD 映像。
    • 如果使用 VHDX:
      • VHDX 映像必須是第 2 代類型且已啟用安全開機。
      • VHDX 映像必須使用 來準備 sysprep /generalize /shutdown /oobe。 如需詳細資訊,請參閱 Sysprep 命令行選項
  • 如果使用用戶端連線到 Azure Stack HCI 叢集,請參閱 透過 Azure CLI 用戶端連線到 Azure Stack HCI。

  • 請確定您在用於映像的記憶體帳戶上具有 記憶體 Blob 資料參與者 角色。 如需詳細資訊,請參閱指派 Azure 角色以存取 Blob 資料

  • 請確定您將 VHD 或 VHDX 上傳為分頁 Blob 映像至記憶體帳戶。 只有分頁 Blob 映像支援透過記憶體帳戶建立 VM 映像。

從 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 的指示。
注意:請確定路徑中的所有 Ampersand 都會以雙引號逸出,而且整個路徑字串會包裝在單引號內。
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 叢集的自定義位置識別碼。 執行以下命令:

    $customLocationID=(az customlocation show --resource-group $resource_group --name "<custom location name for HCI cluster>" --query id -o tsv)
    
  2. 從指定的市集映像開始建立 VM 映像。 請務必指定 Marketplace 映像的供應專案、發行者、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>

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

檢視 VM 映像內容

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

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

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

  2. 設定下列參數。

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

    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>"
    $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 = "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>

下一步