Jaa


Migrating VMs from Hyper-V to Windows Azure – 20 Key Scenarios with Windows Azure Infrastructure Services

Get started with Hyper-V and Windows Server 2012

One of the first questions that IT Pros have when considering using Windows Azure to host some (or all) of their company’s computing infrastructure is, “How do I move an existing virtual machine to the cloud?”

“I was just about to ask that!”

I bet you were.

So, how does one take a virtual machine and duplicate it up “in the cloud”?  In this article – a part of our 20 Key Scenarios with Windows Azure Infrastructure Services series - I am going outline the process for you, and hopefully leave you with some useful resources and other things to consider.

The steps are pretty basic:

  1. Create a place to store your hard disk in Windows Azure
  2. Prepare your virtual hard disk
  3. Upload your virtual hard disk
  4. Create your machine in Windows Azure

This is makes a pretty good outline for what we need to cover here, so let’s go with it.  But before we do, I need to encourage you to set up your local machine’s PowerShell to authenticate with, connect to, allow you to manage your Windows Azure subscription and objects using PowerShell.  To do this, read and follow the steps in my article: Configuring PowerShell for Windows Azure.

 

Create a place to store your hard disk in Windows Azure

Once you have your Windows Azure subscription (and if you don’t yet have one, you can START A FREE TRIAL HERE), you’ll need to create a storage account that will host your .vhd file. The steps for doing this are well documented in the article, “Creating and Uploading a Virtual Hard Disk that Contains the Windows Server Operating System”.  The section specifically regarding the creation of a storage account can be found here. (NOTE: Some of the steps in this article are out-dated, but the creation of the storage account is still documented correctly.

You can also create your storage account using Windows PowerShell.  Assuming you’ve configured your local machine’s PowerShell to connect to your Windows Azure subscription, you can run a command like this:

New-AzureStorageAccount -Location "West US" -StorageAccountName krtempstorageaccount

NOTE: The name of your storage account must be a 3-24 letter name made up of lowercase letters and numbers only.  It must also be globally unique, because it will be used in URLs such as “https://krtempstorageaccount.blob.core.windows.net/”

Prepare your virtual hard disk

If you are going to upload a machine to the cloud, your hard disk file has to be configured a certain way.  It must be a .VHD file (not a VHDX file, must be between 20MB and 2TB in size, and must be a fixed-size virtual disk

Also, if you’re going to use this hard disk as an image from which multiple machines will be created, then you’ll want to make sure to either sysprep the machine first before shutting down and uploading the hard disk, or creating the machine in Windows Azure and doing the sysprep and then “capture” the stopped machine as an image. 

image

 

Upload your virtual hard disk

Now that you have your hard disk ready to upload, you have a couple of ways of getting it up to the cloud:

The CSUPLOAD tool is a part of the Windows Azure SDK, which will require you to first install that SDK.  As I’m more of an IT Pro than a developer, I’m going to choose to use PowerShell.

Assuming…

  1. I’ve already configured PowerShell to connect to my Windows Azure subscription,
  2. I have a .VHD file named “dos20.vhd” sitting in my local C:\Scripts folder, and
  3. I’ve already created a storage account called “krtempstorageaccount”,

(Yes, the name of that disk is a little telling. It’s a hard disk that has MS-DOS on it.  It’s nice and small, so the upload doesn’t take as long for demonstration purposes.)

I can use the following script to set up variables, add (upload) the VHD into storage, and then add that storage as a useable Azure disk:

# Storage Account
$storageAccountName = "krtempstorageaccount"

# Source VHD
$vhdsource = 'C:\Scripts\Dos20.vhd'

# Upload Location
$vhddestination= 'https://'
+ $storageAccountName + '.blob.core.windows.net/vhds/dos20.vhd'

Add-AzureVhd -LocalFilePath $vhdsource -Destination $vhddestination

Add-AzureDisk -OS Windows -MediaLocation $destosvhd -DiskName 'dos20'

And it’s just that easy.  Now when I have a disk configured as an OS disk up in storage named “dos20” that I can use as the basis for a virtual machine.

 

Create your machine in Windows Azure

Of course once your machine’s disk is up in your storage account, you’ll want to use it.  Here’s how I created a machine using the “dos20” disk that I just uploaded.

I can create my machine in the Windows Azure Administration Portal, or I can use PowerShell.

Using the Windows Azure Administration Portal:  

Logged in to your Windows Azure subscription, click “New+” at the bottom left, and choose to create a new machine from the Gallery…

image

Once there, select MY DISKS on the left, and you should see the disk(s) you’ve uploaded…

image

Select your disk, and complete the wizard.  Once completed, your machine will be provisioned and will start running.

image

Using the Windows PowerShell:  

Here is a simplistic use of the New-AzureVMConfig and New-AzureVM cmdlets, that does the very same thing as our Admin Console example (all one line):

New-AzureVMConfig -Name KRDOS20 -DiskName 'dos20' -InstanceSize 'Small' | New-AzureVM -ServiceName "krdosservice" -Location "West US"

Note: the service name must be unique. You can verify that a name is unique by using the Test-AzureName cmdlet prior to actually creating new cloud services or cloud storage.

 

Other Considerations

“Hey Kevin – Can I upload a new-style .VHDX file into Windows Azure?”

Not at this time, no.  Currently Windows Azure only supports fixed-size .VHD files as the basis for storage disks or virtual machines running in Windows Azure.

“You mention ‘storage disks’. Does this mean I can just create .VHDs and populate them with stuff, and then use them as attached disks to Windows Azure virtual machines?”

Absolutely.  Once you have that disk in a Windows Azure storage account, you’ll see it as a disk you can either use as a machine’s OS disk, or attach to an existing VM as an attached disk.  (But it can’t be both at the same time!)

“I’m running VMware machines. Can I run them in Windows Azure?”

No.  They’ll first need to be converted.  The good news is, it’s easy to do with the free Microsoft Virtual Machine Converter.

“Can I use tools such as System Center 2012Virtual Machine Manager or App Controller to copy virtual machines up to Windows Azure?”

Yes!  If you have virtual machines managed by VMM, you can easily save them to a library and then copy them to Windows Azure.  You’ll do all of that through the management of clouds using App Controller.  To connect App Controller to your Windows Azure subscription, read my blog article: Step-by-Step: Connecting System Center 2012 App Controller to Windows Azure.  Once that’s in place, follow the instructions in my other blog article: Creating Azure Virtual Machines with App Controller.

---

Was this useful? Have you started your FREE TRIAL yet? Have you been keeping up with the series? Give us your comments in the blog comments, please!

Comments

  • Anonymous
    June 05, 2013
    Better question...  Can I use Windows Server 2012 Hyper-V replication, to replicate a local machine to the cloud for disaster recovery failover?

  • Anonymous
    June 05, 2013
    No.  We did announced a capability coming to Windows Azure called Recovery Manager, which will allow you to manage replication between hosts using a cloud service.  It even lets you create and automate recovery plans.  But it doesn't move your VMs into cloud storage directly.  For that, you could use DPM or products like StorSimple.