When I saw this new option I thought well could be interesting, prep some disks in advance and upload later the disk. Looks quicker than staging the vhd first. There are two ways you can bring an on-premises VHD to Azure as a managed disks:
- Stage the VHD into a storage account before converting it into a managed disk.
- Attach an empty managed disk to a virtual machine and do copy.
Both these ways have disadvantage.The first option requires extra storage account to manage while the second option has extra cost of running virtual machine. Direct-upload addresses both these issues and provides a simplified workflow by allowing copy of an on-premises VHD directly as a managed disk. You can use it to upload to Standard HDD, Standard SSD, and Premium SSD managed disks of all the supported sizes. With this new option Migration could speed up and it seems less work.
Now days Microsoft want to do a lot in the Azure CLI, Working with this and personally I like the Azure CLI to do quick things but for testing and building I like the PowerShell options. So in this blog post I show you how to do upload your VHD to a managed Azure disk.
Starting this I noticed the weirdness of PowerShell I did not have the proper options, It seems I run some older versions of the Azure Az module.
SO running new Azure options with PowerShell make sure you run the latest version. This is not needed in the Azure CLI.
I had version 2.7.0 running and I needed 2.8.0 Do a uninstall of the old version
Uninstall-AllModules -TargetModule Az -Version 2.7.0 –Force
Or if you have a lot of old versions running uninstall them all.
$versions = (Get-InstalledModule Az -AllVersions | Select-Object Version)
$versions[0..($versions.Length-2)] | foreach { Uninstall-AllModules -TargetModule Az -Version ($_.Version) -Force }
And of course you can run this in the Azure CLI with the following command
az disk create -n mydiskname1 -g disk1 -l westeurope --for-upload --upload-size-bytes 10737418752 --sku standard_lrs
But where is the fun on doing this, Right.
For creating a Managed disk in the GUI there are only a few steps but then you need to add this to a Virtual machine and copy over the data. time consuming
Lets create a powershell script that will pick the right disk size and upload the VHD to Azure as a Managed disk.
First we need to see what size my VHD file is to make sure the disk has enough disk space.
$vhdSizeBytes = (Get-Item "I:\Hyperv-old\MVPMGTDC01\mvpdc0120161023143512.vhd").length
So I need a disk size of 136367309312
Our next step is create a proper disk configuration. with placement in the correct region and resource group.
#Provide the Azure region where Managed Disk will be located.
$Location = “westeurope”
#Provide the name of your resource group where Managed Disks will be created.
$ResourceGroupName =”rsguploaddisk001”
#Provide the name of the Managed Disk
$DiskName = “mvpdc01-Disk01”
New-AzResourceGroup -Name $ResourceGroupName -Location $location
$diskconfig = New-AzDiskConfig -SkuName ‘Standard_LRS’ -OsType ‘Windows’ -UploadSizeInBytes $vhdSizeBytes -Location $location -CreateOption ‘Upload’
$diskconfig
Now that the configuration is set we can actual create a new Disk.
New-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName -Disk $diskconfig
Now that the disk is created we can see this in the Azure portal also.
The details of the just created disk.
Comparing the disk configuration this is now empty and the Disk state is ReadyToUpload.
At this point we don’t have access to the disk and we can’t upload the original disk to the Azure Managed disk. Therefore we need to grand access to this disk. This is done in a time frame like 24 hours or shorter it depends on the time that is needed for the upload.
basic default is 24 hours = 86400 seconds but when done we revoke the access.
$diskSas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $DiskName -DurationInSecond 86400 -Access ‘Write’
And in the Portal you can see the Ready status is changed to Active Upload.
When looking at the details of the disk in PowerShell we see the disk state of active upload.
$disk = Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName
$disk
Our next step is copy the VHD to the Azure Disk
AzCopy.exe copy "I:\Hyperv-old\MVPMGTDC01\mvpdc0120161023143512.vhd" $diskSas.AccessSAS –blob-type PageBlob
As I did not place any restrictions to the upload It will use my full bandwidth of Internet, this means a full 1Gbps connection.
Now that the Upload is completed we can revoke the access
Revoke-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $DiskName
As you can see the disk state is now unattached and we can create a VM with this disk.
The Disk type can’t be changed at this point but can be changed when the VM is deployed.
Machine is quickly build and depending on the machine type you can change the disk type to SSD
Follow Me on Twitter @ClusterMVP
Follow My blog https://robertsmit.wordpress.com
Linkedin Profile Robert Smit MVP Linkedin profile
Google : Robert Smit MVP profile
One thought on “Migrate VHD Disks to Azure Disks – Direct-upload to Azure managed disks #Azure #Upload #Disk #Migrate #VHD #storage #MVPBuzz #WIMVP”