How can you move your running (not generalized) Linux VHD to Azure ARM in just a few steps?

1) Prepare your standard Azure management client environment as explained in my previous blog. Keep all the modules up to date.

2) Create a new Resource Group in Azure

3) Inside the Resource Group create a new Storage Account of your choice, prefer Locally Redundant Storage for simple requirements and its pricing advantages.

4) Create a new container in the Storage Account. Copy the already copied running virtual machine, (but not generalized) Linux VHD file from on-premises to the Storage Account container either by using Microsoft Azure Storage Explorer or AZCopy command, of blob type as page blob.
5)  Change the variables below accordingly. Then run the powershell command to create your VM in a new VNET and subnet.

# variables - update these variables according to your needs and current settings
$rgName = "testrg"
 $location = "westus"
## Storage
 $storageName = "teststore"
 $storageType = "Standard_GRS"
## Network
 $nicname = "testnic"
 $subnet1Name = "subnet1"
 $vnetName = "testnet"
 $vnetAddressPrefix = ""
 $vnetSubnetAddressPrefix = ""
## Compute
 $vmName = "testvm"
 $computerName = "testcomputer"
 $vmSize = "Standard_A2"
 $osDiskName = $vmName + "osDisk"
$osDiskUri = ""
# Resource Group
 New-AzureRmResourceGroup -Name $rgName -Location $location
# Storage
 $storageacc = New-AzureRmStorageAccount -ResourceGroupName $rgName -Name $storageName -Type $storageType -Location $location
# Network
 $pip = New-AzureRmPublicIpAddress -Name $nicname -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic
 $subnetconfig = New-AzureRmVirtualNetworkSubnetConfig -Name $subnet1Name -AddressPrefix $vnetSubnetAddressPrefix
 $vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location -AddressPrefix $vnetAddressPrefix -Subnet $subnetconfig
 $nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id
# Compute
## Setup local VM object
 $vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Linux
## Create the VM in Azure
 New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm -Verbose -Debug

Comments (0)

Skip to main content