Download an Azure VM to Hyper-V
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.
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:
- Find the virtual machine in the Portal.
- Stop the virtual machine.
- Browse to Settings > Disks.
- Identify the blob name of each virtual disk from the storage account blob URL.
- Browse to the Storage Account that is used to store the virtual machine files.
- Click Blobs and go into the container that stores the virtual hard disks (probably called vhds).
- 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.
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:
Select-AzureRmSubscription –SubscriptionId 1ab23456-1234-1a23-abcd-a123abc12345
Shut down the virtual machine:
Stop-AzureRmVM -ResourceGroupName PetriDL -Name PetriDL
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:
Save-AzureRmVhd -ResourceGroupName PetriDL -SourceUri $vhdpath -LocalFilePath "C:\Temp\Azure\petridl.vhd"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.
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.
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.
More in Virtualization
What is a Virtual Machine?
Jun 27, 2022 | Rabia Noureen
Broadcom to Acquire Virtualization Company VMware for $61 Billion
May 27, 2022 | Rabia Noureen
Microsoft Lifts Windows 11 Update Block As Oracle Releases VirtualBox Fix
Mar 14, 2022 | Rabia Noureen
What is a Virtual Server?
Dec 29, 2021 | Jason Wynn
Guide: How to Install Windows 11 in a Virtual Machine
Jul 8, 2021 | Michael Reinders
Microsoft Rebrands Windows Virtual Desktops, Adds New Features
Jun 7, 2021 | Brad Sams
Most popular on petri