Move a VM from Azure Service Manager to Azure Resource Manager

Move a VM from Azure Service Manager to Azure Resource Manager

Q. How can I move a VM from Azure Service Manager to Azure Resource Manager?

A. Microsoft have a tool available at https://blogs.msdn.microsoft.com/tomholl/2016/07/16/migrating-azure-iaas-solutions-from-asm-to-arm-using-migaz/ which enables you to select the resources in ASM that you wish to migrate and it creates a JSON template that represents a "new" version of those objects in ARM. It also creates a BlobCopy.ps1 file which will copy the page blobs containing the VHDs used by the VMs to the newly created storage accounts. It's a great idea and is easy to use. There is also the asm2arm solution at https://github.com/fullscale180/asm2arm and the native platform solution documented at https://azure.microsoft.com/en-us/blog/iaas-migration-classic-resource-manager/.

If you wanted to do this manually using PowerShell you could manually copy the VHDs from the ASM storage account to an ARM storage account using Azure Storage Explorer (http://storageexplorer.com/) or an Azure server-side copy (http://windowsitpro.com/azure/copy-content-one-azure-storage-account-another and http://windowsitpro.com/azure/retrieve-storage-context-arm).

Once the VHD has been copied to an ARM storage account a new VM can be created on an ARM virtual network using the copied VHD files. For example (assumes OS disk is <vmname>-OS.vhd and data disk is <vmname>-Data.vhd (change as required):

#Resource Group name, VM size and name for new VM
$rgname = 'RGSCUSInfra'
$vmsize = 'Standard_A2'
$vmname = 'savazudc01'
#Network to connect to
$virtnetname = 'VNet115'
# Storage account (assumed to be in same Resource Group as the target for VM)
$stoname = 'sascusgrsinfra'
#location to create new VM
$loc = 'SouthCentralUS' 

#Get the storage account
$stoaccount = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname;

# Create VM Object
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize

# Setup Networking
$vnet = Get-AzureRmVirtualNetwork -Name $virtnetname -ResourceGroupName $rgname
$subnetId = $vnet.Subnets[0].Id #Attach the VM to the first subnet

$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $vmname) -ResourceGroupName $rgname `
-Location $loc -SubnetId $subnetId # if wanted static IP and DNS add -PrivateIpAddress 10.7.115.13 -DnsServer 10.7.115.13 

# Add NIC to VM
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

$osDiskName = $vmname+'_osDisk'
$osDiskCaching = 'ReadWrite'
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/vhds/"+$vmname+"-OS.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -Windows -Caching $osDiskCaching

#Add a data disk
$dataDiskVhdUri = "https://$stoname.blob.core.windows.net/vhds/"+$vmname+"-Data.vhd"
$dataDiskName = $vmname+'_dataDisk'
$vm = Add-AzureRmVMDataDisk -VM $vm -Name $dataDiskName -Caching None -CreateOption Attach -DiskSizeInGB 1023 -VhdUri $dataDiskVhdUri

# Create Virtual Machine
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish