Moving a virtual machine from Hyper-V to Azure IaaS

Now that Azure IaaS is generally available, many people want to move Virtual Machines from on-premise to Windows Azure.
I will go through the steps needed to move an existing machine to Azure.

 

First of all, the disk has to be a .VHD file. Currently Windows Azure Virtual Machines are not running on .VHDX files.
If you are running on a VHDX disk, you can convert it through Hyper-V manager.

Converting .VHDX disk file to .VHD

Start Hyper-V manager, Right-click the VM and Choose settings

 

Choose to convert, then next.

Choose VHD as disk format

Keep the disk type

Set the name and location of the new VHD file

Finish

Wait for the disk conversion to complete

Preparing disk

 I you want to use the VHD for creating multiple machines in Azure you need to create an image in Azure. For Azure to be able to start a machine created from an image, you will want to run sysprep on it before you upload it.

If you just want to copy a machine to Azure for use as one Azure VM, you don't need to sysprep it.

Getting the VHD uploaded to Azure

For this you need to have an active Azure Subscription, you can get one at https://www.windowsazure.com
Create a storage account and a dedicated container for your VM disks.

First Option on is doing it through Windows Azure Powershell, you can download it from here: https://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx

Second option is through a command in Node.js. This is my preferred option, simply because you can stop it and it will resume when you start it again. This is a big advantage when you are doing an upload that will take several hours to complete.
You may need to move outside of your Wi-Fi reach, network disruption, computer enters sleep mode, or any other issue that will disrupt your transfer during the hours it is running. Having to restart an upload after 6 hours is annoying.

So I will explain how to get the Node.js way to work.
- Install Node.js from https://nodejs.org/
- Run the command: npm install azure-cli -g

Now Node.js is ready to run the upload command

Run:  azure vm disk upload "<local file path>" "https://<storage account>.blob.core.windows.net/<container>/<target VHD name>.vhd" "<storage account key>"

Now you should see something like this

As you can see from this, it has completed 20% of 17GB in a little less than an hour. This is with a quite decent upload line, so do expect your uploads to take some time.

Creating a disk or an image

In this article I will only explain how to create and start the VM through the Windows Azure web portal. It has some shortcomings as you cannot specify a service name when creating the VM. For each VM it will create a new service.
In my next article, I will show some simple scripts to take up and down the machines (saving cost), and also explain how to gather the machines under one service.

Log in to https://windows.azure.com

We expect that the VHD file has been uploaded. You can browse your storage account to verify that.

Now we go into the Virtual Machines tab

 

If you have sysprepped the image on the disk and would like to use it for creating multiple VMs, click on the IMAGES link.

If you have not sysprepped or just want to create one VM, click on the DISKS link

 

Click Create at the bottom of the page, and you will get this dialog

 

Enter a name for the disk

Browse for the URL of the blob that contains the VHD. If you can't find it, and you have verified that it is in the storage container, try again in a minute. It can take a short while for it to show here.

Choose OS and finish

 

Creating the machine

Click +New in the bottom left corner

Choose Compute --> Virtual Machine --> From Gallery

Now the Create Virtual machine wizard opens

 

 

If you choose to create an image, select My Images. I have a disk, so I choose My disks
If the disk or image is not there, just wait, it will soon be there

Choose your disk or image

Next step, you give the machine a name and set the size (and cost) for it.

Next step, you choose Stand-alone Virtual Machine. Give it a DNS name that is unique to the azure services.
Choose affinity group, region or virtual network
Select the subnet you want the VM to be on

The settings on the last tab doesn't really affect our implementation.

Finish the wizard, and the machine will start creating.

You will see several step being executed and at last your computer will show status Running

Select the machine and click Connect at the bottom. You will now be given an RDP connection to the machine and you can use the credentials that were valid on the on-premise machine.