从现有 VHD 创建 VM:预览门户

2024-03-16

现在有人知道如何在新的 Azure 门户中从现有 VHD 创建 VM 吗?

我可以在manage.windowsazure.com 中找到很多有关如何执行此操作的信息,但在portal.azure.com 中没有找到任何有关此功能的信息。


从字面上看,这不能在门户中完成。您将必须使用 powershell。

  1. 创建一个存储帐户。例如在门户中。

  2. 将 VHD 上传到 azure。为此,请在登录后在 powershell 中运行以下行Login-AzureRmAccount(更改 和硬盘上 vhd 路径之间的参数):

    Add-AzurermVhd -Destination "https://<StorageAccountName>.blob.core.windows.net/<containerName>/<vhdname>.vhd" -LocalFilePath "D:\Virtual Machines\myharddisk.vhd" -ResourceGroupName "<ResourceGroupName" -Overwrite
    
  3. 创建 ARM 模板。 你可以做的事情有多种可能性。 例如,从以下位置选择一个模板Azure 快速入门模板 https://github.com/Azure/azure-quickstart-templates, 例如101 https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image

我所做的是:

  • 在 Visual Studio 2015 中创建了一个新项目。
  • 选择以下项目:Cloud->Azure Resource Group
  • 选择以下模板:Windows 虚拟机

  • 更改了一些参数并删除了所有不需要的内容。 它现在所做的是:使用上传的vhd作为硬盘创建Windows虚拟机。 它现在使用参数 json 文件,并且还必须在 WindowsVirtualMachine.json 中设置一些变量 这当然可以重构。但目前它会做需要做的事情。

对于此示例,您必须具有以下目录结构(就像 Visual Studio 创建它一样)

ProjectDirectory/Scripts/Deploy-AzureResourceGroup.ps1
ProjectDirectory/Templates/WindowsVirtualMachine.json
ProjectDirectory/Templates/WindowsVirtualMachine.parameters.json

部署-AzureResourceGroup.ps1

#Requires -Version 3.0
#Requires -Module AzureRM.Resources
#Requires -Module Azure.Storage

Param(
    [string] [Parameter(Mandatory=$true)] $ResourceGroupLocation,
    [string] $ResourceGroupName = 'CreateImage',    
    [string] $TemplateFile = '..\Templates\WindowsVirtualMachine.json',
    [string] $TemplateParametersFile = '..\Templates\WindowsVirtualMachine.parameters.json'
)

Import-Module Azure -ErrorAction SilentlyContinue

try {
    [Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("VSAzureTools-$UI$($host.name)".replace(" ","_"), "2.8")
} catch { }

Set-StrictMode -Version 3

$OptionalParameters = New-Object -TypeName Hashtable
$TemplateFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateFile)
$TemplateParametersFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateParametersFile)


# Create or update the resource group using the specified template file and template parameters file
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop 

New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
                                   -ResourceGroupName $ResourceGroupName `
                                   -TemplateFile $TemplateFile `
                                   -TemplateParameterFile $TemplateParametersFile `
                                   @OptionalParameters `
                                   -Force -Verbose

WindowsVirtualMachine.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {    
    "dnsNameForPublicIP": {
      "type": "string",
      "minLength": 1,
      "metadata": {
        "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine."
      }
    }   
  },
  "variables": {
    "OSDiskName": "<vhdNameWithoutExtension>",
    "vhdStorageContainerName": "<containerName>",
    "storageAccountName": "<StorageAccountName>",
    "nicName": "myVMNic",
    "addressPrefix": "10.0.0.0/16",
    "subnetName": "Subnet",
    "subnetPrefix": "10.0.0.0/24",
    "vhdStorageType": "Standard_LRS",
    "publicIPAddressName": "myPublicIP",
    "publicIPAddressType": "Dynamic",
    "vhdStorageName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]",
    "vmName": "MyWindowsVM",
    "vmSize": "Standard_A2",
    "virtualNetworkName": "MyVNET",
    "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
    "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('vhdStorageName')]",
      "apiVersion": "2015-06-15",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "StorageAccount"
      },
      "properties": {
        "accountType": "[variables('vhdStorageType')]"
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('publicIPAddressName')]",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "PublicIPAddress"
      },
      "properties": {
        "publicIPAllocationMethod": "[variables('publicIPAddressType')]",
        "dnsSettings": {
          "domainNameLabel": "[parameters('dnsNameForPublicIP')]"
        }
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[variables('virtualNetworkName')]",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "VirtualNetwork"
      },
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('addressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('subnetName')]",
            "properties": {
              "addressPrefix": "[variables('subnetPrefix')]"
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[variables('nicName')]",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "NetworkInterface"
      },
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
              },
              "subnet": {
                "id": "[variables('subnetRef')]"
              }
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[variables('vmName')]",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "VirtualMachine"
      },
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', variables('vhdStorageName'))]",
        "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[variables('vmSize')]"
        },       
        "storageProfile": {         
          "osDisk": {
            "name": "osdisk",
            "osType": "Windows",
            "vhd": {
              "uri": "[concat('http://', variables('storageAccountName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]"
            },
            "caching": "ReadWrite",
            "createOption": "Attach"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        }   
      }      
    }
  ]
}

WindowsVirtualMachine.parameters.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {       
        "dnsNameForPublicIP": {
            "value": "<someUniqueNameForYourDnsName>"
        }
    }
}
  1. 执行powershell脚本 打开 Powershell 命令并执行 ps1 脚本。您只需传递要创建虚拟机的位置,例如:(您应该已经使用以下命令登录Login-AzureRmAccount)

    在运行之前更改两个 json 文件中的参数!
    .\Deploy-AzureResourceGroup.ps1 "West Europe"

日志记录应该告诉您虚拟机已成功创建。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从现有 VHD 创建 VM:预览门户 的相关文章

随机推荐

  • Marshmallow PermissionHelper 的 Android Robolectric 单元测试

    我想学习 Robolectric 以便将其用于 Android Marshmallow 应用程序的单元测试 我写了一个PermissionHelper使用一些方法可以使权限处理更容易一些 为了开始对该类进行单元测试 我尝试测试最简单的方法
  • 如何使用 Perl 将带有 -- 的 SQL 注释转换为 #?

    UPDATE 这就是有效的方法 fgrep ircl include sql 我有各种带有 注释的 SQL 文件 我们迁移到最新版本的 MySQL 但它讨厌这些注释 我想用 替换 我正在寻找一种递归的 就地替换的单行代码 这就是我所拥有的
  • pyparsing 和换行符

    我刚开始pyparsing我有换行问题 我的语法是 from pyparsing import newline LineEnd Literal n leaveWhitespace minus Literal plus Literal lpa
  • 将字符串解析为整数抛出 NullpointerException

    Hy 我想将字符串解析为整数 字符串类似于系列的格式 SXXEXXX 守则 应该增加情节 喜欢 S01E01 gt S01E02 另 S01E100 gt S01E101 Code String s episodes get episode
  • pip:从特定目录卸载包

    我使用以下命令将包安装到特定的本地目录中pip install t
  • Three.js 与实例 - 如果没有 FrustumCulling = false 则无法使其工作

    我正在使用 Three js 和实例化 如这个例子 https threejs org examples webgl buffergeometry instancing html 但我遇到了其他人报告的同样问题 对象被随机剪切并不断从相机中
  • 导航时片段生命周期重叠

    我有一个Activity具有多个应用程序Fragments通过使用导航组件进行切换 当我在两个片段之间切换时onCreate and onDestroy 方法似乎有重叠 因此 当片段访问相同的全局对象时 我很难编写初始化和清理片段的代码 导
  • 与杰克逊一起收集未知财产

    我正在使用 Jackson 从 JSON 创建 Java 对象 假设我有一个像这样的 JSON 字符串 a a b b c c 还有一个像这样的 pojo JsonIgnoreProperties ignoreUnknown true pu
  • 获取视图的边距

    如何从活动中获取视图的边距值 视图可以是任何类型 经过一番搜索后 我找到了填充视图的方法 但在 Margin 上找不到任何内容 有人可以帮忙吗 我尝试过这样的事情 ViewGroup LayoutParams vlp view getLay
  • slickgrid 标题的 Colspan 和 rowspan

    我只是想知道是否有一种方法可以为标题提供 colspan rowspan 并具有多个标题行 网格提供了一个辅助标题行 您可以用它来做任何您需要做的事情 检查here https github com mleibman SlickGrid w
  • 数据流中的值错误:GCS 位置无效:无

    我正在尝试从 GCS 存储桶加载数据并将内容发布到 pubsub 和 bigquery 这些是我的管道选项 options PipelineOptions project project temp location gs dataflow
  • 在 angularjs 中格式化日期和时区

    使用 angularjs 1 2 26 我无法将日期输入格式化为所需的时区 这是一个示例 http plnkr co edit CxCqoR3Awcl1NFrCZYjx p preview http plnkr co edit CxCqoR
  • 播放路由语法以忽略 slug 的一部分

    我们想要的基本上是这样的 foo controllers FooController foo 然而这不起作用 我们找到了以下解决方法 foo ignore controllers FooController foo ignore 但这使得该
  • Docker 存储库服务器向 HTTPS 客户端发出 HTTP 响应

    我使用适用于 Windows 的 Docker 工具箱 并且正在尝试参考此文档运行私有 docker 注册表https docs docker com registry deploying https docs docker com reg
  • Windows 安全自定义登录验证

    我正在创建一个 Xaml C 应用程序 我希望它能够弹出登录提示 我想知道是否可以使用 CredUIPromptForWindowsCredentials 显示 Windows 安全对话框 获取输入的用户名和密码 执行自定义验证 如果验证成
  • 10 月 Azure SDK 在插入带有尾随空格的字符串时损坏

    有没有人解决这个问题 使用存储模拟器并将行插入表存储时 如果字段末尾有空格 则行插入会失败 两周前就已经指出了这一点 但我仍然没有看到微软对此的任何更新 有谁知道修复方法吗 微软论坛链接 http social msdn microsoft
  • 如何使用javascript获取html中的元素背景图像

    我想获取使用 css 或元素背景属性设置的所有 html 页面元素的背景图像 我怎样才能使用javascript做到这一点 The getStyle 下面的函数取自http www quirksmode org dom getstyles
  • 重写规则以返回某些 URL 的状态 200

    我希望具有特定路径的 URL 自动返回 200 状态响应 我已尝试以下操作 但当我尝试启动 Apache 时出现错误 第一个错误 RewriteCond 错误的标志分隔符 RewriteEngine On RewriteCond THE R
  • 在 XSL 中创建空格 ( )

    我尝试通过以下方式在 XSL 文档中创建自动间距 td td
  • 从现有 VHD 创建 VM:预览门户

    现在有人知道如何在新的 Azure 门户中从现有 VHD 创建 VM 吗 我可以在manage windowsazure com 中找到很多有关如何执行此操作的信息 但在portal azure com 中没有找到任何有关此功能的信息 从字