To migrate and upload VHD files to Azure Cloud Storage, you'll need to create a storage account. This can be done through the Azure portal by selecting "Create a resource" and then searching for "storage account".
Your storage account will need to be in the same region as the virtual machine you want to upload the VHD file to. This is because Azure doesn't support cross-region uploads.
The VHD file size limit for Azure Cloud Storage is 1 TB. This is a significant increase from the 1 MB limit of the Azure portal upload tool, making it a more practical option for larger files.
You can upload your VHD file to Azure Cloud Storage using the Azure CLI or PowerShell. These tools provide a more efficient way to upload large files compared to the Azure portal.
Prerequisites
To upload a VHD to Azure, you'll need to meet some prerequisites. You'll require an Azure subscription, which you can obtain for free if you don't already have one.
You can open an Azure account and get credits to try out paid Azure services, and even after they're used up, you can keep the account and use free Azure services like Websites. Your credit card won't be charged unless you explicitly change your settings.
To manage your Azure subscription, you'll need the Microsoft Azure PowerShell module installed and configured to use your subscription. You can download the module from Microsoft Azure Downloads.
You'll also need a supported Windows operating system stored in a .vhd file and attached to a virtual machine. You can use tools like Hyper-V to create a virtual machine and install the operating system.
Here are the specific requirements for the Azure subscription:
- Open an Azure account for free
- Activate MSDN subscriber benefits
- Get credits to use for paid Azure services
Note that the VHDX format is not supported in Microsoft Azure, so you may need to convert the disk to VHD format using Hyper-V Manager or the Convert-VHD cmdlet.
Azure Storage
To upload a VHD file to Azure, you need a storage account. This account will serve as a place to upload the .vhd file.
You can either create a new storage account or use an existing one. If you're creating a new account, the process is straightforward.
Here's a step-by-step guide to creating a storage account and uploading your VHD file:
- Create a new container in your Azure storage account to store the VHD file.
- Grab the URL needed to upload your VHD disk from the container.
- Upload the VHD file using the Azure portal or Azure PowerShell.
You can place the .vhd file anywhere within your blob storage when uploading it.
Subscription Access
To access your Azure subscription, you'll need to establish a secure connection between your computer and your subscription in Azure. This can be done using the Microsoft Azure Active Directory method or the certificate method.
You can use Azure PowerShell to connect to your subscription, which is a great way to manage your Azure resources. To do this, you'll need to run the command to connect to your subscription.
If you're using Microsoft Entra ID to enforce upload restrictions, you'll need to assign RBAC permissions to grant access to the disk and generate a writeable SAS. This will allow you to upload a VHD from your local machine to a new Azure managed disk using Add-AzVHD.
VHDX files with a logical sector size of 512k aren't supported, so be sure to check the file size before attempting to upload it.
Optional Grant Access
If you're using Microsoft Entra ID to enforce upload restrictions, you'll need to assign RBAC permissions to grant access to the disk. This is because Add-AzVHD only succeeds if attempted by a user that has the appropriate RBAC role or necessary permissions.
You can assign RBAC permissions to grant access to the disk by adding DataAccessAuthMode 'AzureActiveDirectory' to the end of your Add-AzVhd command. This will ensure that the upload is successful.
VHDX files with a logical sector size of 512k aren't supported, so be sure to check the file format before attempting to upload.
Here's a quick rundown of the RBAC permissions you'll need to assign:
By assigning the correct RBAC permissions, you'll be able to grant access to the disk and successfully upload your VHD.
Create or Get Info from Storage Account
You need a storage account in Azure to upload your VHD file. To get started, you'll want to create a new storage account or retrieve information from an existing one.
For a new storage account, you can use the Azure portal or the Azure PowerShell module. In the portal, navigate to "Storage accounts" and click "+ Create" to create a new account. Alternatively, in PowerShell, you can use the New-AzStorageAccount cmdlet to create a new account.
If you're working with an existing storage account, you can retrieve its information using the Get-AzStorageAccount cmdlet in PowerShell.
Here's a brief overview of the storage account types you can create:
Remember to choose the correct storage account type based on your VHD file's requirements.
Uploading and Attaching
Uploading a VHD to Azure can be done in several ways, but the most common method is using the AzCopy v10 tool. You can use AzCopy to upload your local VHD or VHDX file to a managed disk by specifying the SAS URI you generated.
To upload a VHD or VHDX file, you'll need to create a SAS for your empty managed disk. This will give you the necessary permissions to upload your file. The upload process has the same throughput as the equivalent standard HDD, with speeds ranging from 60 MiB/s for a size equating to S4 to 500 MiB/s for a size equating to S70.
Once the upload is complete, you'll need to revoke the SAS to change the state of the managed disk and allow you to attach it to a VM. You can do this through the Azure portal or using the AzCopy v10 tool.
There are also other ways to upload a VHD to Azure, including using the Azure-RM PowerShell module. With this method, you'll need to install the module on your workstation and use the Add-AzureRmVhd cmdlet to upload your VHD disk.
To attach the uploaded VHD disk to a VM, you'll need to open the Virtual Machine blade and select "Disks" to attach the uploaded disk. If you want to create a new VM based on the uploaded VHD disk, you'll need to create an Azure Image first.
Here are the steps to create an Azure Image:
- Open the Virtual Machine blade and select "Disks"
- Attach the uploaded disk
- Create an Azure Image by clicking "Create Image"
- Set the VM image as a source image for the new VM
Alternatively, you can use the Azure portal to upload a VHD disk by clicking "Upload". You can also use the Add-AzureVhd cmdlet to upload a VHD file, specifying the destination blob storage URL and the local file path.
Here are the parameters for the Add-AzureVhd cmdlet:
- Destination: the blob storage URL
- LocalFilePath: the local file path of the VHD file
Note that the upload process may take some time, depending on the size of your VHD disk. Once the upload is complete, you can confirm that the VHD file exists in your Azure storage.
Frequently Asked Questions
Is VHDX supported in Azure?
VHDX is not supported in Azure, but you can convert it to a compatible fixed VHD format before uploading.
Sources
- https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
- https://www.starwindsoftware.com/blog/migrate-on-premises-vhd-files-to-azure/
- https://github.com/Huachao/azure-content/blob/master/articles/virtual-machines/virtual-machines-create-upload-vhd-windows-server.md
- https://arlanblogs.medium.com/move-an-on-prem-hyper-v-vm-to-azure-specialized-vhd-aaaca981c29e
- https://regroove.ca/stellark/2021/02/24/upload-a-vhd-to-azure-and-create-a-virtual-machine/
Featured Images: pexels.com