Can we move an image in Azure to a different location (region) using UI/Command or through any other way?

501 Views Asked by At

I have an image,say in "UK South". I want to move it to say "East US", how can I do it ? Is there an AZ CLI command, some option on UI or any other way ? I already used "az image copy" but getting error.

1

There are 1 best solutions below

2
Joy Wang On

If so, you could follow the steps below.

1.Create a storage account in the portal located in East US in the target resource group.

2.Navigate to the source image in the portal -> Create VM, after creating the VM, navigate to the VM -> Disks -> copy the OS disk name.

3.Make sure you have installed the Az powershell module, then use the commands below to copy the disk to the storage as a .vhd file.

#Source Disk
$rgName ="xxxxx"
$location ="UK South"
$diskName ="<diskname copied in step 2>"

#Dest Blob
$destrgName ="xxxx"
$destlocation ="East US"
$deststorageAccountName ="<storage account name in step 1>"
$destdiskName ="destDisk.vhd" 
    
#Grant the read access for the disk
$sas =Grant-AzDiskAccess -ResourceGroupName $rgName -DiskName $diskName -DurationInSecond 3600 -Access Read

$saKey =Get-AzStorageAccountKey -ResourceGroupName $destrgName -Name $deststorageAccountName
$storageContext =New-AzStorageContext –StorageAccountName $deststorageAccountName -StorageAccountKey $saKey[0].Value

#Create a new container vhds2 in the storage account
New-AzStorageContainer -Context $storageContext -Name vhds2

#Start copy, my disk size is 30GB, just takes several minutes
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer vhds2 -DestContext $storageContext -DestBlob $destdiskName

After a while, check the copy status, if the Status is Success, it means the copy completed.

Get-AzureStorageBlobCopyState -Context $storageContext -Blob $destdiskName -Container vhds2 

4.After doing the steps above, you already have the .vhd file in the blob, then you can create an image directly in the portal from the blob URL.

enter image description here