将自定义 VM 添加到 Azure StackAdd a custom VM to Azure Stack

适用于:Azure Stack 集成系统和 Azure Stack 开发工具包Applies to: Azure Stack integrated systems and Azure Stack Development Kit

在 Azure Stack 中,可将虚拟机 (VM) 自定义映像添加到市场供用户使用。In Azure Stack, you can add your custom virtual machine (VM) image to the marketplace and make it available to your users. 可以使用 Azure Stack 的 Azure 资源管理器模板添加 VM 映像。Images are added by using Azure Resource Manager templates for Azure Stack. 还可以使用管理员门户或 Windows PowerShell 将 VM 映像作为市场项添加到 Azure 市场 UI。You can also add VM images to the Azure Marketplace UI as a marketplace item using the administrator portal or Windows PowerShell. 可以使用来自 Azure 市场的映像,也可以使用你自己的自定义 VM 映像。Use either an image from the Azure Marketplace, or your own custom VM image.

通用化 VM 映像Generalize the VM image

WindowsWindows

创建自定义的通用化 VHD。Create a custom generalized VHD. 如果 VHD 来自 Azure 外部,请遵循上传通用化 VHD 并使用它在 Azure 中创建新 VM 中的步骤,正确地对 VHD 执行 Sysprep 并使其通用化。If the VHD is from outside Azure, follow the steps in Upload a generalized VHD and use it to create new VMs in Azure to correctly Sysprep your VHD and make it generalized.

如果 VHD 来自 Azure,请先根据使用 Sysprep 将源 VM 通用化中的说明操作,然后将 VHD 移植到 Azure Stack。If the VHD is from Azure, follow the instructions in Generalize the source VM by using Sysprep before porting it to Azure Stack.

LinuxLinux

如果 VHD 来自 Azure 外部,请根据相应的说明将 VHD 通用化:If the VHD is from outside Azure, follow the appropriate instructions to generalize the VHD:

如果 VHD 来自 Azure,请根据以下说明将 VHD 通用化:If the VHD is from Azure, follow these instructions to generalize the VHD:

  1. 停止 waagent 服务:Stop the waagent service:

    # sudo waagent -force -deprovision
    # export HISTSIZE=0
    # logout
    
  2. 关闭 VM 并下载 VHD。Shut down the VM and download the VHD. 如果要从 Azure 导入 VHD,可以使用磁盘导出来执行此操作,如从 Azure 下载 Windows VHD 中所述。If you are bringing your VHD from Azure, you can do this using disk export, as shown in Download a Windows VHD from Azure.

请注意哪些 Azure Linux 代理版本适用于 Azure Stack,此处有具体的说明Keep in mind the Azure Linux Agent versions that work with Azure Stack as documented here. 确保已执行 Sysprep 的映像包含与 Azure Stack 兼容的 Azure Linux 代理版本。Make sure that the sysprepped image has an Azure Linux agent version that is compatible with Azure Stack.

同时适用于 Windows 和 Linux 的通用步骤Common steps for both Windows and Linux

在上传映像之前,必须考虑以下因素:Before you upload the image, it's important to consider the following:

  • Azure Stack 仅支持采用固定磁盘 VHD 格式的第一代 VM。Azure Stack only supports generating one (1) VM in the fixed disk VHD format. 固定格式在文件中将逻辑磁盘以线性方式布局,使磁盘偏移量 X 存储在 Blob 偏移量 X 的位置。在 Blob 末尾有一小段脚注,描述了 VHD 的属性。The fixed-format structures the logical disk linearly within the file, so that disk offset X is stored at blob offset X. A small footer at the end of the blob describes the properties of the VHD. 若要确认磁盘是否为固定格式,请使用 Get-VHD PowerShell cmdlet。To confirm if your disk is fixed, use the Get-VHD PowerShell cmdlet.

  • Azure Stack 不支持动态磁盘 VHD。Azure Stack does not support dynamic disk VHDs. 重设附加到 VM 的动态磁盘的大小会导致 VM 处于故障状态。Resizing a dynamic disk that's attached to a VM will leave the VM in a failed state. 若要解决此问题,请删除 VM,但不删除 VM 的磁盘(存储帐户中的 VHD Blob)。To mitigate this issue, delete the VM without deleting the VM's disk, a VHD blob in a storage account. 然后将 VHD 从动态磁盘转换为固定磁盘,接着重新创建 VM。Then, convert the VHD from a dynamic disk to a fixed disk and re-create the VM.

以 Azure Stack 操作员的身份使用门户添加 VM 映像Add a VM image as an Azure Stack operator using the portal

  1. 映像必须能够通过 Blob 存储 URI 进行引用。Images must be able to be referenced by a blob storage URI. 以 VHD(不是 VHDX)格式准备 Windows 或 Linux 操作系统映像,然后将映像上传到 Azure 或 Azure Stack 中的存储帐户。Prepare a Windows or Linux operating system image in VHD format (not VHDX), and then upload the image to a storage account in Azure or Azure Stack.

    • 如果 VHD 位于 Azure 中,且你在联网的 Azure Stack 上运行,可以使用 Azcopy 等工具直接在 Azure 与 Azure Stack 存储帐户之间传输 VHD。If the VHD is in Azure, you can use a tool such as Azcopy to directly transfer the VHD between an Azure and your Azure Stack storage account if you are running on a connected Azure Stack.

    • 在离线的 Azure Stack 上,如果 VHD 位于 Azure 中,则需要将 VHD 下载到可以连接 Azure 和 Azure Stack 的计算机上。On a disconnected Azure Stack, if your VHD is in Azure, you will need to download the VHD to a machine that has connectivity to both Azure and Azure Stack. 然后,先从 Azure 将 VHD 复制到此计算机,再使用任何可跨 Azure 与 Azure Stack 使用的通用存储数据传输工具,将 VHD 传输到 Azure Stack。Then you copy the VHD to this machine from Azure before you transfer the VHD to Azure Stack using any of the common storage data transfer tools that can be used across Azure and Azure Stack.

  2. 可以遵循此示例将 VHD 上传到 Azure Stack 管理员门户中的存储帐户。You can follow this example to upload a VHD to a storage account in the Azure Stack Administrator portal.

  3. 记下在其中上传映像的 Blob 存储 URI。Make a note of the blob storage URI where you upload the image. Blob 存储 URI 的格式如下: <storageAccount>/<blobContainer>/<targetVHDName> .vhd。The blob storage URI has the following format: <storageAccount>/<blobContainer>/<targetVHDName>.vhd.

  4. 若要使 Blob 可供匿名访问,请转到已在其中上传了 VM 映像 VHD 的存储帐户 Blob 容器。To make the blob anonymously accessible, go to the storage account blob container where the VM image VHD was uploaded. 选择“Blob” ,然后选择“访问策略” 。Select Blob, and then select Access policy. 也可生成容器的共享访问签名,然后将其作为 Blob URI 的一部分包括进去。Optionally, you can generate a shared access signature for the container, and include it as part of the blob URI. 此步骤确保 blob 可用。This step makes sure the blob is available to be used. 如果 blob 不可匿名访问,则 VM 映像创建将处于失败状态。If the blob isn't anonymously accessible, the VM image will be created in a failed state.

    转到存储帐户 Blob

    将 Blob 访问权限设置为公共

  5. 以操作员身份登录到 Azure Stack。Sign in to Azure Stack as operator. 在菜单中的计算 > “添加”下,选择“所有服务” > “映像”。In the menu, select All services > Images under Compute > Add.

  6. 在“创建映像”下, 输入名称、订阅、资源组、位置、OS 磁盘、OS 类型、存储 Blob URI、帐户类型和主机缓存。Under Create image, enter the Name, Subscription, Resource Group, Location, OS disk, OS type, storage blob URI, Account type, and Host caching. 然后选择“创建”,开始创建 VM 映像。 Then, select Create to begin creating the VM image.

    开始创建映像

    成功创建映像后,VM 映像状态会更改为“已成功”。 When the image is successfully created, the VM image status changes to Succeeded.

  7. 添加映像时,它仅适用于基于 Azure 资源管理器的模板和 PowerShell 部署。When you add an image, it is only available for Azure Resource Manager-based templates and PowerShell deployments. 若要将映像作为市场项提供给用户,请使用创建和发布市场项一文中的步骤发布市场项To make an image available to your users as a marketplace item, publish the marketplace item using the steps in the article Create and publish a Marketplace item. 请务必记下“发布者”、“套餐”、“SKU”和“版本”的值。 Make sure you note the Publisher, Offer, SKU, and Version values. 在自定义 .azpkg 中编辑资源管理器模板和 Manifest.json 时,需要用到这些值。You will need them when you edit the resource manager template and Manifest.json in your custom .azpkg.

以 Azure Stack 操作员的身份使用门户删除 VM 映像Remove the VM image as an Azure Stack operator using the portal

  1. 打开 Azure Stack 管理员门户Open the Azure Stack administrator portal.

  2. 如果 VM 映像有关联的市场项,请选择“市场管理”,然后选择要删除的 VM 市场项。 If the VM image has an associated Marketplace item, select Marketplace management, and then select the VM marketplace item you want to delete.

  3. 如果 VM 映像没有关联的市场项,请导航到“所有服务”>“计算”>“VM 映像”,然后选择 VM 映像旁边的省略号 ( ... )。 If the VM image does not have an associated Marketplace item, navigate to All services > Compute > VM Images, and then select the ellipsis (...) next to the VM image.

  4. 选择“删除” 。Select Delete.

以 Azure Stack 操作员的身份使用 PowerShell 添加 VM 映像Add a VM image as an Azure Stack operator using PowerShell

  1. 安装适用于 Azure Stack 的 PowerShellInstall PowerShell for Azure Stack.

  2. 以操作员身份登录到 Azure Stack。Sign in to Azure Stack as an operator. 有关说明,请参阅以操作员身份登录到 Azure StackFor instructions, see Sign in to Azure Stack as an operator.

  3. 使用权限提升的提示符打开 PowerShell,并运行:Open PowerShell with an elevated prompt, and run:

     Add-AzsPlatformimage -publisher "<publisher>" `
       -offer "<Offer>" `
       -sku "<SKU>" `
       -version "<#.#.#>" `
       -OSType "<OS type>" `
       -OSUri "<OS URI>"
    

    Add-AzsPlatformimage cmdlet 指定 Azure 资源管理器模板用来引用 VM 映像的值。The Add-AzsPlatformimage cmdlet specifies values used by the Azure Resource Manager templates to reference the VM image. 这些值包括:The values include:

    • publisherpublisher
      例如: CanonicalFor example: Canonical
      VM 映像的发布者名称段,供用户在部署映像时使用。The publisher name segment of the VM image that users use when they deploy the image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • offeroffer
      例如: UbuntuServerFor example: UbuntuServer
      VM 映像的套餐名称段,供用户在部署 VM 映像时使用。The offer name segment of the VM image that users use when they deploy the VM image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • skusku
      例如: 14.04.3-LTSFor example: 14.04.3-LTS
      VM 映像的 SKU 名称段,供用户在部署 VM 映像时使用。The SKU name segment of the VM Image that users use when they deploy the VM image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • versionversion
      例如: 1.0.0For example: 1.0.0
      VM 映像的版本,供用户在部署 VM 映像时使用。The version of the VM Image that users use when they deploy the VM image. 此版本采用 #.#.# 格式。This version is in the format #.#.#. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • osTypeosType
      例如: LinuxFor example: Linux
      映像的 osType 必须为 WindowsLinuxThe osType of the image must be either Windows or Linux.

    • OSUriOSUri
      例如: https://storageaccount.blob.core.chinacloudapi.cn/vhds/Ubuntu1404.vhdFor example: https://storageaccount.blob.core.chinacloudapi.cn/vhds/Ubuntu1404.vhd
      可以指定 osDisk 的 Blob 存储 URI。You can specify a blob storage URI for an osDisk.

      有关详细信息,请参阅 Add-AzsPlatformimageNew-DataDiskObject cmdlet 的 PowerShell 参考。For more information, see the PowerShell reference for the Add-AzsPlatformimage and the New-DataDiskObject cmdlets.

以 Azure Stack 操作员的身份使用 PowerShell 删除 VM 映像Remove a VM image as an Azure Stack operator using PowerShell

不再需要上传的 VM 映像时,可使用以下 cmdlet 从市场中删除它:When you no longer need the VM image that you uploaded, you can delete it from the Marketplace by using the following cmdlet:

  1. 安装适用于 Azure Stack 的 PowerShellInstall PowerShell for Azure Stack.

  2. 以操作员身份登录到 Azure Stack。Sign in to Azure Stack as an operator.

  3. 使用权限提升的提示符打开 PowerShell,并运行:Open PowerShell with an elevated prompt, and run:

    Remove-AzsPlatformImage `
     -publisher "<Publisher>" `
     -offer "<Offer>" `
     -sku "<SKU>" `
     -version "<Version>" `
    

    Remove-AzsPlatformImage cmdlet 指定 Azure 资源管理器模板用来引用 VM 映像的值。The Remove-AzsPlatformImage cmdlet specifies values used by the Azure Resource Manager templates to reference the VM image. 这些值包括:The values include:

    • publisherpublisher
      例如: CanonicalFor example: Canonical
      VM 映像的发布者名称段,供用户在部署映像时使用。The publisher name segment of the VM image that users use when they deploy the image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • offeroffer
      例如: UbuntuServerFor example: UbuntuServer
      VM 映像的套餐名称段,供用户在部署 VM 映像时使用。The offer name segment of the VM image that users use when they deploy the VM image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • skusku
      例如: 14.04.3-LTSFor example: 14.04.3-LTS
      VM 映像的 SKU 名称段,供用户在部署 VM 映像时使用。The SKU name segment of the VM Image that users use when they deploy the VM image. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

    • versionversion
      例如: 1.0.0For example: 1.0.0
      VM 映像的版本,供用户在部署 VM 映像时使用。The version of the VM Image that users use when they deploy the VM image. 此版本采用 #.#.# 格式。This version is in the format #.#.#. 不要在此字段中包含空格或其他特殊字符。Don't include a space or other special characters in this field.

      有关 Remove-AzsPlatformImage cmdlet 的详细信息,请参阅 Azure PowerShell Azure Stack 操作员模块文档For more info about the Remove-AzsPlatformImage cmdlet, see the Azure PowerShell Azure Stack Operator module documentation.

后续步骤Next steps