Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Migrate On-Premises VHD files to Azure

  • February 8, 2018
  • 9 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.

In this article, I will describe how to upload a vhd file that contains some data. So I will attach this uploaded vhd to an existing Azure Virtual Machine using the following process:

  • Convert the vhdx file to vhd
  • Upload the vhd file to Azure
  • Attach this uploaded vhd disk to a VM

I will use the Azure Portal and Windows PowerShell to perform these tasks.

Please note that this guide can be used to import a simple VHD disk containing data, or to import a Virtual Machine image. In both cases, you must upload the VHD disk to Azure and then:

  • Attach the disk to an existing VM
  • or create an Azure Image based on the uploaded VHD disk. Then, you can create a new Virtual Machine using this image. If you want to upload a VM to Azure, you must sysprep the OS as a prerequisite. Once you have finished the customization, navigate to c:\windows\system32\sysprep and run sysprep.exe. Run the system preparation with the following settings:

system preparation with the following setting

Creating the VHD disk

Let’s start by creating a VHD disk. In this example, I will create a local VHD file using the disk management utility. Click “Action” and select “Create VHD”:

create and attach virtual hard disk

I selected VHDX to describe how to convert a VHDX disk to VHD format. Wait until the VHDX disk is successfully created.

convert a VHDX disk to VHD format

Next, you can initialize the disk and format the partition. Open the Windows Explorer and confirm that you can create an item on the disk.

сreating the VHD disk - initialize

In my case, I will copy and paste the SCCM executable.

сreating the VHD disk - SCCM executable

When you are ready to import you VHDX to Azure, you can detach the disk. First, select “Offline” and then “Detach VHD”:

import VHDX to Azure

Converting the VHD disk

Before uploading the VHDX to Azure, you must convert the disk to the VHD format. Azure does not support VHDX disks, so you must run the following PowerShell command to perform this task:

converting the VHD disk - PowerShell console

convertthe VHD disk - PowerShell console - Administrator

Note:

  1. Open the PowerShell console as “Administrator”
  2. The Hyper-V Virtual Machine Management Windows Service must be running.

Hyper-V Virtual Machine Management

I can confirm that the VHD file has been successfully created:

successfully creating VHD file

Uploading the VHD disk

For the next steps, you must have Azure-RM PowerShell module installed on your workstation because we will use the Add-AzureRmVhd cmdlet. This cmdlet uploads a virtual hard disk from an on-premises virtual machine to a blob in a cloud storage account in Azure. Open the PowerShell console, and connect to your Azure subscription:

PowerShell console - Administrator - Add Azure RmVhd

Now, we need to create a container and grab the URL needed to upload our VHD disk. Open your Storage Account, and navigate to “Containers” and click “+ Container” to create the container:

azure - storage account - uploading VHD disk

You can get the URL from the Azure portal when you go into the Storage Account:

  • Blobs
  • Container
  • Containers Properties

azure - storage account - blobs - container - containers properties

I did this through the Azure Resource Manager (ARM) Portal but you also can retrieve this information with PowerShell by creating an Azure Storage Context:

Azure Resource Manager (ARM) Portal

Now, you can easily build the URL properties:

Azure Resource Manager (ARM) Portal - URL properties

OK, we are ready to import the VHD file to Azure. Use the following commands:

import the VHD file to Azure - commands

Depending on the size of your VHD disk, you must wait a moment…

depending the size of VHD disk

Once the upload is done, I can confirm that the VHD file exists in my Azure storage.

VHD file - Azure storage

For those of you who prefer to use the Azure portal, you can upload the VHD disk by clicking “Upload”:

Azure portal - uploading the VHD disk

Attaching the VHD disk or Creating a new VM

To finish, open the Virtual Machine blade, and select “Disks” to attach the uploaded disk:

Virtual Machine blade - attaching VHD disk

If you want to create a new VM based on the uploaded VHD disk, you will need first, to create an Azure Image:

creation a new VM - creation an Azure Image

Do not be mistaken by clicking “Add data disk”. Here, we want to create the OS disk, not the data disk!

To finish, set the VM image as a source image for the new VM. So set the source image using the ID of the managed VM image:

$vm = Set-AzureRmVMSourceImage -VM $vm -Id $image.Id

If you need more information, you can read the following documentation: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/upload-generalized-managed

Conclusion

You can easily upload your VHDX and VHD disks from on-premises to Azure using PowerShell and the Azure Portal. Sometimes, you must use PowerShell because some features are not implemented in the portal.

Before a full migration of your Virtual Machines, moving individual Virtual Machine can be interesting in order to test if your workload works as expected in Azure.

Thanks for reading!

Hey! Found Nicolas’s insights useful? Looking for a cost-effective, high-performance, and easy-to-use hyperconverged platform?
Taras Shved
Taras Shved StarWind HCI Appliance Product Manager
Look no further! StarWind HCI Appliance (HCA) is a plug-and-play solution that combines compute, storage, networking, and virtualization software into a single easy-to-use hyperconverged platform. It's designed to significantly trim your IT costs and save valuable time. Interested in learning more? Book your StarWind HCA demo now to see it in action!