How to attach the managed disk from East US to VM created in West US

M, RAKESH 111 Reputation points
2022-03-03T06:34:57.9+00:00

How to attach the managed disk from East US to VM created in West US. I also need to swap the OS disk from the snapshot created from VM in east US.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,152 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
572 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sreeju Nair 11,611 Reputation points
    2022-03-03T06:43:29.13+00:00

    You can copy the managed Disk from East US to West US. The following powershell Script will do the task for you.

    $sourceRG = <sourceResourceGroupHere>  
    $sourceDiskName = <sourceDiskNameHere>  
    $targetDiskName = <targetDiskNameHere>  
    $targetRG = <targetResourceGroupHere>  
    $targetLocate = <yourTargetLocationHere>  
    #Expected value for OS is either "Windows" or "Linux"  
    $targetOS = <yourOSTypeHere>  
      
    $sourceDisk = Get-AzDisk -ResourceGroupName $sourceRG -DiskName $sourceDiskName  
      
    # Adding the sizeInBytes with the 512 offset, and the -Upload flag  
    $targetDiskconfig = New-AzDiskConfig -SkuName 'Standard_LRS' -osType $targetOS -UploadSizeInBytes $($sourceDisk.DiskSizeBytes+512) -Location $targetLocate -CreateOption 'Upload'  
      
    $targetDisk = New-AzDisk -ResourceGroupName $targetRG -DiskName $targetDiskName -Disk $targetDiskconfig  
      
    $sourceDiskSas = Grant-AzDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDiskName -DurationInSecond 86400 -Access 'Read'  
      
    $targetDiskSas = Grant-AzDiskAccess -ResourceGroupName $targetRG -DiskName $targetDiskName -DurationInSecond 86400 -Access 'Write'  
      
    azcopy copy $sourceDiskSas.AccessSAS $targetDiskSas.AccessSAS --blob-type PageBlob  
      
    Revoke-AzDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDiskName  
      
    Revoke-AzDiskAccess -ResourceGroupName $targetRG -DiskName $targetDiskName  
    

    Refer:
    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell#copy-a-managed-disk
    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized#create-the-new-vm
    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/attach-disk-ps

    1 person found this answer helpful.
    0 comments No comments