Creating a virtual machine from an existing VHD portal: Preview

Anyone now how to create a virtual machine from an existing VHD on a new azure portal?

I can find a lot of information on how to do this in the manage.windowsazure.com file, but it doesnโ€™t give this feature on portal.azure.com.

+5
source share
2 answers

This cannot be done literally on the portal. You will have to use powershell.

  • Create a vault account. For example, on the portal.

  • Load the VHD into the azure. To do this, run the following line in PowerShell after logging in using Login-AzureRmAccount (change the settings between <> and the path to vhd on your hard drive):

     Add-AzurermVhd -Destination "https://<StorageAccountName>.blob.core.windows.net/<containerName>/<vhdname>.vhd" -LocalFilePath "D:\Virtual Machines\myharddisk.vhd" -ResourceGroupName "<ResourceGroupName" -Overwrite 
  • Create an ARM template. Multiple possibilities that you can do. For example, select a template from Azure Quickstart templates, such as 101

What I've done:

  • Created a new project in Visual Studio 2015.
  • Select the following project: Cloud-> Azure Resource Group
  • Select the following template: Windows Virtual Machine

  • Changed some parameters and removed all unnecessary things. Now he does the following: Create a Windows virtual machine using downloaded vhd as a hard disk. Now it uses the parameters of the json file, and also some variables must be set in WindowsVirtualMachine.json. This can be reorganized, of course. but for now he will do what is needed.

For this sample, you should have the following directory structure (like Visual Studio)

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

Deployment-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. Run the powershell script command Open the Powershell command and run the ps1 script. You only need to pass in the location where you want to create vm, for example: (you should already be logged in using Login-AzureRmAccount )

    Before starting a parameter change in both json!
    .\Deploy-AzureResourceGroup.ps1 "West Europe"

The log should indicate that the virtual machine was created successfully.

+5
source

Today (October 2016) it still cannot be done on the new portal.

But for completeness: you can do this on the old portal ( https://manage.windowsazure.com ):

Click "Create" - "Calculate" - "Virtual Machine" - "From Gallery". On the left, either select MY IMAGES or MY DISKS and select the VHD that you want to use. Follow the instructions as usual.

+3
source

Source: https://habr.com/ru/post/1242741/


All Articles