Upload a VHD to Storage Using AzCopy

What’s the best way to upload a VHD to Azure Storage? This question comes up on a regular basis and I decided that it was time to share an example that uses PowerShell and AzCopy to upload a VHD to Azure Blob Storage. As you go through this post, remember that a VHD must be uploaded as a Page Blob for it to be usable as a Virtual Machine (VM) image.

Before we can upload a VHD to Azure, we need to create a Storage Account.

$ResourceGroupName = "vhdStorage"
$Location = "centralUS"

New-AzureRmResourceGroup -Name $ResourceGroupName `
                         -Location $Location

$StorageAccountName = "briseboisvhds"

New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName `
                          -Name $StorageAccountName `
                          -Type Standard_LRS `
                          -Location $Location

Now that we have a Storage Account, let’s get our Storage Account Key.

Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName`
                             -Name $StorageAccountName

Use AzCopy command-line utility to upload the VHD to a new blob container. In this example, we are uploading it to a container names ‘vhds’.

$ContainerName = "vhds"

$AzCopyPath = "AzCopy"
$Source = "C:\Users\brise\Downloads"
$Destination ="https://$storageAccountName.blob.core.windows.net/$ContainerName"
$DestKey = "rchmOXyOu...gkdpSFtVgCWQBsWOdtHQ=="
$Files = "WindowsServerTechnicalPreview4.vhd"

& $AzCopyPath "/Source:$Source", `
              "/Dest:$Destination", `
              "/DestKey:$DestKey", `
              "/Pattern:$Files", `
              "/BlobType:page", `
              "/S", `
              "/Y"  

Finished 1 of total 1 file(s).
[2016/02/17 13:08:54] Transfer summary:
-----------------
Total files transferred: 1
Transfer successfully:   1
Transfer skipped:        0
Transfer failed:         0
Elapsed time:            00.00:02:48

At this point, we’re ready to start working with our newly uploaded VHD.

More About AzCopy

AzCopy is a command-line utility designed for copying data to and from Microsoft Azure Blob, File, and Table storage. With AzCopy, you can migrate your data from the file system to Azure Storage, or vice versa, using simple commands and with optimal performance. You can also copy data from one object to another within your storage account, or between storage accounts.

Transfer data with the AzCopy Command-Line Utility is an excellent resource that provides a bunch of excellent samples.

Download the latest version of AzCopy

Trackbacks and Pingbacks:

  1. Dew Drop – February 18, 2016 (#2191) | Morning Dew - February 18, 2016

    […] Upload a VHD to Azure Storage Using AzCopy (Alexandre Brisebois) […]

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.