.net - 从自定义镜像创建 Azure VM

标签 .net azure virtual-machine azure-storage azure-resource-manager

我有一个存储在 Azure 中的镜像,我想从中启动多个虚拟机。我创建了一个模板,它将为我创建必要的资源,除了创建虚拟机之外,所有这些资源都会成功。

使用 CreateOption.FromImage 运行部署大约 40 分钟,直到出现错误:

'OS Provisioning for VM 'vmName' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image

CreateOption.FromImage 更改为 CreateOption.Attach 会立即出现以下错误:

Cannot attach an existing OS disk if the VM is created from a platform or user image.

我想通过模板实现什么:

  1. 指向主图像
  2. 提供母版副本所需的目的地
  3. 将主镜像复制到目标位置
  4. 创建虚拟机
  5. 将副本附加到虚拟机

下面是我用来部署的模板的虚拟机部分:

{
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[parameters('vmName')]",
  "location": "[resourceGroup().location]",
  "tags": {
    "displayName": "VirtualMachine"
  },
  "dependsOn": [
    "[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
  ],
  "properties": {
    "osProfile": {
      "computerName": "[parameters('vmName')]",
      "adminUsername": "[parameters('adminUsername')]",
      "adminPassword": "[parameters('adminPassword')]"
    },
    "hardwareProfile": {
      "vmSize": "[variables('vmSize')]"
    },
    "storageProfile": {
      "osDisk": {
        "name": "[parameters('OSDiskName')]",
        "osType": "windows",
        "caching": "ReadWrite",
        "createOption": "FromImage",
        "image": {
          "uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/', parameters('sourceStorageContainerName'), '/', parameters('sourceVHDName'), '.vhd')]"
        },
        "vhd": {
          "uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/', parameters('vhdStorageContainerName'), '/', parameters('OSDiskName'), '.vhd')]"
        }
      }
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
        }
      ]
    }
  }
}

最佳答案

'OS Provisioning for VM 'vmName' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image

如果您使用未经过系统准备的镜像来创建虚拟机,可能会导致错误,因此请确保您的镜像经过系统准备。

enter image description here

Cannot attach an existing OS disk if the VM is created from a platform or user image.

当您指定 CreateOption to Attach 时(它将从专用磁盘创建虚拟机),请勿指定 SourceImageUri 参数。欲了解更多信息,请查看this documentation中的“-CreateOption” .

关于.net - 从自定义镜像创建 Azure VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41272627/

相关文章:

c# - 替换 C# 字符串中的多个字符

c# - 如何从.Net代码获取IP地址

c# - 加载 DLL 的多个实例 (C#/.NET)

networking - Virtualbox 限制网络带宽

usb - 如何识别Linux主机上运行的Virtualbox中的USB设备?

c# - 为什么没有 Nullable<T>.Equals(T value) 方法?

.net - Azure WebJobs 有很多 QueueTrigger 不好的做法吗?

c# - Azure 上的 Cyber​​Source

visual-studio-2010 - 如何从域外的虚拟机对域中的SQL Server数据库进行身份验证?

azure - 如何在 Azure Cosmos DB 中导入图形数据库的数据?