Download an Azure VM to Hyper-V

Posted on July 13, 2016 by Aidan Finn in Microsoft Azure, Virtualization with 0 Comments

tool-keyboard-hero-img

In this article I will show you how to download a virtual machine from Microsoft Azure and get it running on a local or on-premises Hyper-V host/cluster.

Background

It seems like everyone wants to know how to migrate virtual machines into Azure. The answer is to use Azure Site Recovery. I have been working with Azure customers for over two years, and until very recently, no one had asked me, “How do I download a virtual machine from Azure?” I suspected that I knew the answer, so I went online to confirm my suspicion. In this post, I will show you how to get your virtual machine downloaded and running on Hyper-V.

What We Are Really Downloading

The first thing you need is to understand the anatomy of a (Azure) virtual machine. This process is not going to download a whole virtual machine; instead we will download the disks that make up that virtual machine. The remaining data is metadata, which is pretty meaningless to us. The metadata is a machine specification that we will recreate locally using Hyper-V Manager, Failover Cluster Manager, or System Center Virtual Machine Manager. We will attach the downloaded disks, which contain the OS, programs, settings, and data, to the blank virtual machine. This process takes what we value from the machine and gets it back running where we want it.

Tip: Log into the virtual machine in Azure and note any settings that you need to preserve, such as data drive letters.

Download the Disks

The following process requires that the virtual machine is powered down until you are ready to start it up on your Hyper-V host, so make sure you schedule the migration for an agreed maintenance window. You will need to log into the Azure Portal at http://portal.azure.com.

I am going to show you two native ways to complete the process. The first uses the Azure Portal and cannot be automatically scheduled or automated:

  1. Find the virtual machine in the Portal.
  2. Stop the virtual machine.
  3. Browse to Settings > Disks.
  4. Identify the blob name of each virtual disk from the storage account blob URL.
  5. Browse to the Storage Account that is used to store the virtual machine files.
  6. Click Blobs and go into the container that stores the virtual hard disks (probably called vhds).
  7. Click each disk in turn and select the Download action. Download the VHD file to a safe location. You will transfer this file to your hosts(s) later on.

Note: I was experiencing a bug when viewing blob properties in the Azure Portal at the time of writing this article and clicking Download didn’t cause a download to occur. You could use the classic management portal at https://manage.windowsazure.com to download disks from Azure V1 or Service Management machines.

Viewing the disks of the Azure virtual machine [Image credit: Aidan Finn]

Viewing the disks of the Azure virtual machine [Image credit: Aidan Finn]

Tip: Save the disks directly to where you are going to store your virtual machine. It takes a long time to copy 127 GB (or larger) disks to USB or via 1 GbE networking in order to move files from your PC to a server.

Sponsored

An alternative is to use PowerShell to stop the virtual machine and download the files. This approach lends itself to scheduling and automation. I will use ARM cmdlets to download the disks of an Azure V2 machine. Make sure you have the latest version of the Azure PowerShell cmdlets installed. (You probably will need a reboot after an installation.) Get the URL of each virtual hard disk using the Azure Portal (as above). Then switch to PowerShell:

If you have access to more than one subscription, then list the subscriptions with:

Copy the SubscriptionID from the required subscription and use it to set your desired subscription:

Shut down the virtual machine:

Wait for the virtual machine to stop. Then run the following command for each virtual hard disk. Note that I have stored the storage account path of the blob in a variable and am saving the disk to C:\Temp\Azure on my PC:

Downloading Azure virtual machine disk using PowerShell [Image credit: Aidan Finn]

Downloading Azure virtual machine disk using PowerShell [Image credit: Aidan Finn]

At this point you should go find something else to do. In my example, I used an unmodified Windows Server 2012 R2 machine and was downloading it over a shared 100 Mbps Internet connection, getting between 50-65 Mpbs at my PC. It took around 1 hour 39 minutes to download the single 127 GB VHD file.

Add the Machine to Hyper-V

Use your Hyper-V management tool of choice to create a Generation 1 virtual machine without any virtual hard disks on your Hyper-V host or cluster. Try to match the CPU and memory configuration that the Azure virtual machine used. This process will recreate the metadata of the virtual machine for a Hyper-V host/cluster.

Create a new virtual machine with no disks [Image credit: Aidan Finn]

Create a new virtual machine with no disks [Image credit: Aidan Finn]

Make sure you noted the storage location of the virtual machine. In my example, I have used Failover Cluster Manager to create a highly available virtual machine that is stored on a Storage Spaces JBOD at C:\ClusterStorage\CSV\PetriDL. I then created a folder in the PetriDL folder called Virtual Hard Disks. Once the disk load is completed, copy the disk files to the Virtual Hard Disks folder. In my example, I end up with C:\ClusterStorage\CSV\PetriDL\Virtual Hard Disks\PetriDL.vhd.

Here you have a choice to make:

  • You can continue to use a VHD file.
  • You can opt to convert the VHD file to the VHDX format for better resilience and performance.

You can use the Edit Disk action in Hyper-V Manager to convert the disk between VHD and VHDX formats.

When the disk(s) is ready, edit the settings of the virtual machine. Attach the disks to the virtual machine as follows:

  • The OS disk should be added to IDE controller.
  • Data disks should be added to a SCSI controller.
Sponsored

Here is a list of things you will need to look at or do:

  • Install the latest version of the Hyper-V integration components.
  • Fix any data volume letters to match what they were in Azure.
  • Configure Windows to automatically manage the paging file, which Azure placed on the now-missing D: or temp drive.
  • Windows product key and activation – Azure used a KMS.
  • Verify that services are up and running.
  • Install any management/security software and configure backup.
  • Reboot the virtual machine and verify that everything is OK.
Sponsored

Tagged with , , , ,