Exporting an Azure VM to a VHD and storing it in a storage account is a straightforward process that can be completed in a few steps.
To start, you'll need to create a new storage account in the Azure portal. This will provide a secure location to store your exported VHD file.
You can create a new storage account by clicking on the "Resource Groups" tab and then selecting "Storage Accounts" from the dropdown menu.
The process of exporting an Azure VM to a VHD file involves using Azure CLI commands. The first command you'll need to run is az vm export.
Prerequisites and Setup
To export an Azure VM to a VHD file, you'll need to meet some prerequisites. You must have an active Azure subscription, which provides access to the Azure portal and necessary resources.
You'll also need a Storage Account to store your VM images, ensuring sufficient storage capacity and correct configuration for your use case. A virtual machine (VM) with the desired software installed and configured is also required.
To prepare the VM as a template, you must run Sysprep and select 'Enter System Out-of-Box Experience (OOBE)' for System Cleanup Action, check the 'Generalize' option, and choose 'Shutdown' for Shutdown Options.
Here are the specific prerequisites you'll need to meet:
- Azure Subscription: Active Azure subscription
- Storage Account: Sufficient storage capacity and correct configuration
- VM to use as a template: Operating system and desired software installed and configured
- Sysprep and Generalize: Run Sysprep with specific options
Hyper-V Setup
To set up Hyper-V, you'll first need to export your VM to a Virtual Hard Drive (VHD). This can be done by converting your VHDX file to VHD using the command "Convert-VHD -Path “C:\path\to\exported.vhdx” -DestinationPath “C:\path\to\exported.vhd” -VHDType Fixed".
Next, you'll need to upload the VHD file to Azure Blob Storage. This is a crucial step in the migration process, so make sure to get it right.
To confirm, here are the steps to export your VM:
- Export VM to Virtual Hard Drive (VHD)
- Convert from VHDX to VHD (if necessary)
- Upload the VHD file to Azure Blob Storage
- Create a Managed Image from VHD in Azure
By following these steps, you'll be able to create a Managed Image from your VHD file, which can then be used to create new virtual machines in Azure.
Create Required Resources
To create the resources you need for your Azure setup, you'll want to start by ensuring you have an active Azure subscription. This provides you access to the Azure portal and all the necessary resources for creating and managing VM images.
You'll also need a Storage Account, which will be the location where your VM images will be stored. Make sure you have sufficient storage capacity and the correct configuration for your use case.
It's also essential to have a virtual machine (VM) that you want to use as a template for your image. This VM should have the operating system and all desired software installed and configured according to your requirements.
To prepare your VM for imaging, you'll need to run Sysprep on it. This tool removes all unique identifiers and prepares the VM to be a template.
Here are the specific steps to follow:
- Azure Subscription: Ensure you have an active Azure subscription.
- Storage Account: Create a Storage Account with sufficient storage capacity and correct configuration.
- VM to use as a template: Identify a virtual machine that you want to use as a template for your image.
- Sysprep and Generalize: Run Sysprep on the VM, selecting 'Enter System Out-of-Box Experience (OOBE)' for System Cleanup Action, checking the 'Generalize' option, and choosing 'Shutdown' for Shutdown Options.
Capturing the Source Image
To capture the image of the source VM, you'll need to click on its operating system disk in the Disks section. This will allow you to proceed with the next step of creating a hard disk from the snapshot.
The snapshot export process may take several hours, depending on the size of the disk and your network bandwidth. Ensure you have sufficient storage space for the download.
You can use Azure File Explorer or a web browser to download the image. Azure File Explorer is an Azure explorer that you can install to transfer data to Azure. Using a web browser, you can log in to Azure, navigate to the container, and use the file upload method.
However, this method is not very efficient for large transfers. For a more efficient transfer, you can use the AzCopy command. No installation is required; you simply need to run the executable.
The AzCopy command is straightforward and takes the source file as a parameter and the destination container with a Shared Access Signature (SAS). A Shared Access Signature is a secure way to grant limited access to Azure resources without sharing the account keys.
Destination Tenant Setup
To transfer your custom image to the destination tenant, you'll need to create a storage account and download your created image. This process may take several hours depending on the size of the disk and your network bandwidth, so make sure you have sufficient storage space for the download.
You can use Azure File Explorer or a web browser to transfer the data, but keep in mind that the web browser method is not very efficient for large transfers.
To download the image using Azure File Explorer, you'll need to install it and use it to transfer data to Azure. Alternatively, you can log in to Azure, navigate to the container, and use the file upload method.
To download the image using a web browser, log in to Azure, navigate to the container, and use the file upload method. However, this method is not very efficient for large transfers.
To use the AzCopy command, you'll need to run the executable. On Windows, open a PowerShell command, navigate to the folder where you have placed the AzCopy command executable, and then execute it.
The AzCopy command is straightforward and takes the source file as a parameter and the destination container with a Shared Access Signature (SAS). To generate a SAS, go to the storage account, select "container" as Allowed resource types, and click on "Generate SAS and connection string".
The SAS token generated will be used to grant limited access to Azure resources. Please note that the snapshot downloaded from Azure should have the VHD extension. If it doesn't, you can simply rename your file locally and add the VHD extension before performing the transfer.
Here are the methods to download the image:
- Using Azure File Explorer
- Using a web browser
Note that the web browser method is not very efficient for large transfers.
File Transfer and Storage
After you've created a VM, you'll need to transfer the .VHD file to your storage space. This is a crucial step in the process.
Locate the .VHD file, as it's the file you'll be transferring. You can do this by pinpointing it on your system. Once you've found it, you can transfer it to your storage space.
The .VHD file is the one that contains the VM's data, so make sure you're transferring the correct file.
Sources
- https://www.starwindsoftware.com/starwind-v2v-converter
- https://www.agdiwo.com/en/azure-vm-image-management/
- https://medium.com/@morsi.masmoudi/complete-guide-to-cloning-and-moving-a-vm-from-one-azure-tenant-to-another-8fa65dd6955a
- https://serverfault.com/questions/957262/is-it-possible-and-how-to-download-an-azure-vm-to-local-machine
- https://levelup.gitconnected.com/quickstart-guide-to-vm-images-03a8ae39ee9c
Featured Images: pexels.com