Migrating Virtual Machine Storage from Standard to Premium in Azure Classic

In Azure you can choose between 3 different types of storage for your virtual machines.

These 3 different types are:

If you need more IOPs or Throughput than the above will provide you can attached multiple disks to a VM and bind them together using storage spaces.

Also bear in mind your VM size dictates if you can you premium storage and also what IOPs rate you will be capped at regardless of how many disks you stripe together.

Now having got all of that out the way as an introduction. You can migrate your Virtual Machines from standard to standard managed disks or premium to premium managed disks but the jump in between is not so fun.

In this particular scenario I had a VM on Azure Classic using Standard Storage and I needed to migrate it to Premium Storage for better performance. To do this I wrote a small powershell scripts that will copy the VHD from one storage account to the next.

Ensure that the VM is powered off in the Azure portal before running this script. Also, remember that you need the Azure classic connection via powershell so you’ll be looking to connecting using Add-AzureAccount or similar.

Here is the powershell script I used:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#List out the VHD's that need to be copied just for reference
#VHD 1 P0 – VM_VHD1.vhd
#VHD 2 P1 - VM_VHD2.vhd

#To login to the Azure Classic Portal
#login - Add-AzureAccount
Add-AzureAccount

# VHD blob to copy #
$blobName = "VM_VHD1.vhd"
$blobName1 = "VM_VHD2.vhd"

# Source Storage Account Information #
$sourceStorageAccountName = "<SOURCE STORAGE ACCOUNT NAME>"
$sourceKey = "<SOURCE STORAGE KEY>"
$sourceContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceKey
$sourceContainer = "<CONTAINER NAME>"

# Destination Storage Account Information #
$destinationStorageAccountName = "<DESTINATION STORAGE ACCOUNT NAME>"
$destinationKey = "<DESTINATION STORAGE KEY>"
$destinationContext = New-AzureStorageContext –StorageAccountName $destinationStorageAccountName -StorageAccountKey $destinationKey

# Create the destination container #
$destinationContainerName = "<CONTAINER NAME>"
New-AzureStorageContainer -Name $destinationContainerName -Context $destinationContext#

# Copy the blob #
$blobCopy = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName -DestContext $destinationContext -SrcBlob $blobName -Context $sourceContext -SrcContainer $sourceContainer
$blobCopy1 = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName -DestContext $destinationContext -SrcBlob $blobName1 -Context $sourceContext -SrcContainer $sourceContainer

#Get Status of the Job as it copies
while(($blobCopy | Get-AzureStorageBlobCopyState).Status -eq "Pending")
{
Start-Sleep -s 10
$blobCopy | Get-AzureStorageBlobCopyState
$blobCopy1 | Get-AzureStorageBlobCopyState
}

#To Cancel a job if you decided you have waited too long
#$blobCopy1 | Stop-AzureStorageBlobCopy
#$blobCopy2 | Stop-AzureStorageBlobCopy

A few notes:

To get your storage key you go here:

The copy process does take some time so be patient.

Leave a Reply

Your email address will not be published.