通过 Azure CLI 从 Azure 计算库映像创建 Azure 本地 VM
发布时间:2026-09-27 | 浏览:1
访问此页面需要授权。 可以尝试 登录 或 更改目录 。
访问此页面需要授权。 可以尝试 更改目录 。
适用于:Azure 本地的超融合部署
本文介绍如何使用 Azure 计算库中的源映像创建由 Azure Arc 启用的 Azure 本地虚拟机(VM)。 可以使用本文中的说明在 Azure CLI 上创建 VM 映像,然后使用这些 VM 映像创建 Azure 本地 VM。
查看并 完成 Azure 本地 VM 先决条件 。
确保您的镜像使用 Azure Arc 连接的计算机代理 支持的操作系统。 注释 并非 Azure Arc 支持的服务器页面上列出的所有操作系统,都支持在 Azure 本地启用 Arc(来宾管理)。 来宾管理需要 Hyper-V 套接字(HV 套接字)支持,这将进一步限制支持的 OS 集。
并非 Azure Arc 支持的服务器页面上列出的所有操作系统,都支持在 Azure 本地启用 Arc(来宾管理)。 来宾管理需要 Hyper-V 套接字(HV 套接字)支持,这将进一步限制支持的 OS 集。
对于 Azure 图库中的自定义映像,请确保满足以下额外先决条件: 在 Azure 计算画廊中加载了一个虚拟硬盘(VHD)。 了解如何 创建映像定义和映像版本 。 如果使用虚拟硬盘 v2 (VHDX): VHDX 映像是第 2 代类型且已启用安全启动。 VHDX 镜像已使用 sysprep /generalize /shutdown /oobe 。 有关详细信息,请参阅 Sysprep 命令行选项 。
在 Azure 计算画廊中加载了一个虚拟硬盘(VHD)。 了解如何 创建映像定义和映像版本 。
如果使用虚拟硬盘 v2 (VHDX): VHDX 映像是第 2 代类型且已启用安全启动。 VHDX 镜像已使用 sysprep /generalize /shutdown /oobe 。 有关详细信息,请参阅 Sysprep 命令行选项 。
VHDX 映像是第 2 代类型且已启用安全启动。
VHDX 镜像已使用 sysprep /generalize /shutdown /oobe 。 有关详细信息,请参阅 Sysprep 命令行选项 。
从 Azure 计算图库添加 VM 映像
按照以下步骤使用 Azure CLI 创建 Azure 本地 VM 映像。
连接到 Azure 本地实例上的计算机。
连接到 Azure 本地实例上的计算机。
登录并输入以下命令: az login --use-device-code
设置订阅。 az account set --subscription <Subscription ID>
若要将 Azure 计算库映像传输到 Azure 本地兼容的映像,需要将 Azure 计算库映像版本导出到托管磁盘。
若要将 Azure 计算库映像下载到资源组,请按照 将映像版本导出到托管磁盘 中的步骤进行作。 记下托管磁盘的名称。
导出作必须在包含 Azure 计算库映像版本的 源订阅 和 源资源组 中执行。
选择 库映像所在的资源组 (源订阅), 而不是 Azure 本地的目标资源组。
生成的托管磁盘将保留在源订阅中。 Azure 本地稍后将通过 SAS URL 访问它。
尝试在目标 Azure 本地资源组中创建托管磁盘会失败,因为映像版本不存在。
使用以下命令获取托管磁盘的共享访问签名 (SAS) 令牌: # Variables to get SAS URL for the managed disk $resource_group = "<Resource Group Name>" $diskName = "<myDiskName>" # Replace 'myDiskName' with your actual disk name $sasExpiryDuration = 100000 # Duration in seconds for SAS URL validity az disk grant-access --resource-group $resource_group --name $diskName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv
使用以下命令获取托管磁盘的共享访问签名 (SAS) 令牌:
在创建 Azure 本地 VM 映像之前,需要设置一些参数。
设置订阅、资源组、位置、本地共享中映像的路径,以及映像的 OS 类型。 请将 < > 中的参数替换为适当的值。 $subscription = "<Subscription ID>" $resource_group = "<Resource group>" $location = "<Location for your Azure Local>" $osType = "<OS of source image>" $imageName = "<VM image name>" $customLocationID = "<Custom Location ID>" $imageSourcePath = '"<SAS URL path to the source image>"' 下表描述了参数: 参数 DESCRIPTION subscription 与库映像关联的 Azure 本地订阅。 resource_group 与图库映像关联的资源组为 Azure Local。 location Azure 本地实例的位置。 例如, eastus 。 imageName 以本地共享中的映像为基础创建的 VM 映像名称。 注意:Azure 将拒绝所有包含关键字“Windows”的名称。 os-type 与源映像关联的操作系统。 例如,Windows 或 Linux。 customLocationID Azure 本地实例的自定义位置 ID。 imageSourcePath 图库映像的托管磁盘 SAS URL 路径。 下面是示例输出: PS C:\Users\azcli> $subscription = "<Subscription ID>" PS C:\Users\azcli> $resource_group = "mylocal-rg" PS C:\Users\azcli> $location = "eastus" PS C:\Users\azcli> $osType = "Windows" PS C:\Users\azcli> $imageName = "mylocal-computegalleryimage" PS C:\Users\azcli> $customLocationID = "/subscriptions/$subscription/resourcegroups/$resource_group/providers/microsoft.extendedlocation/customlocations/$customLocationName" PS C:\Users\azcli> $imageSourcePath = '"https://EXAMPLE.blob.storage.azure.net/EXAMPLE/abcd<sas-token>"'
设置订阅、资源组、位置、本地共享中映像的路径,以及映像的 OS 类型。 请将 < > 中的参数替换为适当的值。
创建 Azure 本地 VM 映像
若要创建 Azure 本地 VM 映像,请执行以下步骤:
选择一个自定义位置来部署 VM 映像。 自定义位置应与 Azure Local 的自定义位置相对应。 获取 Azure 本地的自定义位置 ID。 运行下面的命令: $customLocationID=(az customlocation show --resource-group $resource_group --name "<custom location name for your Azure Local>" --query id -o tsv)
选择一个自定义位置来部署 VM 映像。 自定义位置应与 Azure Local 的自定义位置相对应。 获取 Azure 本地的自定义位置 ID。 运行下面的命令:
从指定的图库映像开始创建 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 部署任务将启动虚拟机映像,需耗时数分钟才能完成。 映像下载时间取决于映像大小和可供下载的网络带宽。 下面是示例输出: { "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/galleryImages/mylocal-image", "location": "eastus", "name": "mylocal-image", "properties": { "cloudInitDataSource": null, "containerId": "/subscriptions/<Subscription ID>/resourceGroups/mylocal-rg/providers/Microsoft.AzureStackHCI/storageContainers/mylocal-storagepath", "hyperVGeneration": null, "identifier": null, "imagePath": null, "osType": "Windows", "provisioningState": "Succeeded", "sourceVirtualMachineId": null, "status": { "downloadStatus": { "downloadSizeInMb": 11482 }, "errorCode": "", "errorMessage": "", "progressPercentage": 100, "provisioningStatus": { "operationId": "00000000-0000-0000-0000-000000000000*0000000000000000000000000000000000000000000000000000000000000000", "status": "Succeeded" } }, "version": { "name": null, "properties": { "storageProfile": { "osDiskImage": { "sizeInMb": 130050 } } } }, "vmImageRepositoryCredentials": null }, "resourceGroup": "mylocal-rg", "systemData": { "createdAt": "2025-05-21T00:44:16.385633+00:00", "createdBy": "guspinto@contoso.com", "createdByType": "User", "lastModifiedAt": "2025-05-21T00:48:34.016113+00:00", "lastModifiedBy": "00000000-0000-0000-0000-000000000000", "lastModifiedByType": "Application" }, "tags": null, "type": "microsoft.azurestackhci/galleryimages" }
从指定的图库映像开始创建 VM 映像。 请确保为图像指定产品/服务、发布者、版本和库存单位(SKU)。
部署任务将启动虚拟机映像,需耗时数分钟才能完成。 映像下载时间取决于映像大小和可供下载的网络带宽。
若要避免与磁盘相关的成本,请确保删除用于使用以下命令创建此映像的托管磁盘: az disk delete --name $diskName --resource-group $resourceGroupName
若要避免与磁盘相关的成本,请确保删除用于使用以下命令创建此映像的托管磁盘:
通过 Azure CLI 和 Azure 门户管理 Azure 本地 VM 映像
想要尝试使用 Ask Learn 阐明或指导你完成本主题?
Last updated on 2026-09-15