question

Khanick-6045 avatar image
Khanick-6045 asked ·

Upload VHD to Azure

Hello,

I have a VM created on Hyper-V, the file is vhd, i would like to load this vhd to Azure. I found couples articles on internet about uploading VHD to Azure, but they were saturated too many details and took to different links.
Has anyone successful done this task? Any good advice, links can be shared?

Thank you in advance.

Nick

azure-virtual-machines
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If the response did help in answering your query, please mark the response as "Answered", so that it helps other users visiting the forum.

0 Votes 0 · ·
karishmatiwari-msft avatar image
karishmatiwari-msft answered ·

Hello,

Please refer to the following document on Uploading VHD to Azure and let me know if you have any questions:

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/prepare-for-upload-vhd-image

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

daverendon avatar image
daverendon answered ·

Here´s a quick script to move your vhd and provision the VM


  1. Create a resource group

  2. Execute: Connect-AzAccount

  3. Run the script - modify the parameters as needed

Source: https://github.com/daveRendon/Moving-VHD-to-Azure-with-PowerShell-and-create-VM-image/blob/master/src/moving-vhd-to-Azure-create-vm-image.ps1


 $subscriptionName = "Your Subscription Name"
 $subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
 $tenantId ="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
 $resourceGroupName = 'DRendon'
 $location = 'EastUS'
 $vhdName = 'kemp360central-v1.25.vhd'
 $imageName = 'kempcentral25'
 $containerName = "kempcentraldrtestcontainer"
 $storageAccountName = "kempcentraldrtest"
     
 Select-AzureRmSubscription -SubscriptionId $subscriptionId
      
 : #Select your default subscription on ARM

 Get-AzureRmSubscription -SubscriptionId $subscriptionId -TenantId $tenantId | Set-AzureRmContext
      
 [//]: # create new storage account

 $storageAccount = New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -SkuName Standard_LRS -Location $location
 $ctx = $storageAccount.Context
      
 [//]: # create container
     
 new-azurestoragecontainer -Name $containerName -Context $ctx -Permission blob
      
 [//]: # set the local path from the vhd
 $localPath = 'C:\Users\daver\Downloads\kemp360central\kemp360central-v1.25.vhd'
      
      
 [//]: # set the url of the image and move the vhd, also use the -overwrite option since process might fail sporadically
 [//]: # -overwrite solves the error Add-AzureRmVhd : The pipeline was not run because a pipeline is already running.
 [//]: # Pipelines cannot be run concurrently
 $urlOfUploadedImageVhd = ('https://' + $storageAccountName + '.blob.core.windows.net/' + $containerName  + '/' + $vhdName)
 Add-AzureRmVhd -ResourceGroupName $resourceGroupName -Destination $urlOfUploadedImageVhd `
 -LocalFilePath $localPath -OverWrite
      
 [//]: # Create a managed image from the uploaded VHD
 $imageConfig = New-AzureRmImageConfig -Location $location
     
 [//]: # set the managed disk from the image
 $imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsType Windows -OsState Generalized `
     -BlobUri $urlOfUploadedImageVhd
     
 $image = New-AzureRmImage -ImageName $imageName -ResourceGroupName $resourceGroupName -Image $imageConfig






Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.