Converting OVA / VMDK to VHD for use in Azure

Software required:

7-zip: http://www.7-zip.org/download.html

Virtualbox: https://www.virtualbox.org/wiki/Downloads (Or you could use https://cloudbase.it/qemu-img-windows/ which is less to install)

Azure PowerShell: https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-5.0.0

Azure Storage Explorer: https://go.microsoft.com/fwlink/?LinkId=708343&clcid=0x409

Install the software listed above. Azure Storage Explorer isn’t needed but makes it a lot easier to both upload and move files between storage accounts.

Converting the file

Rename the OVA-file to filename.TAR, unpack it with 7-zip so that you get the VMDK-file in a directory.

Start a command prompt (CMD.exe) and navigate to the “C:\Program Files\Oracle\Virtualbox” directory

Using vboxmanage.exe we’ll convert our file to VHD.

Once it’s done we’ll need to upload it to Azure.

Create a storage account in the portal

See https://docs.microsoft.com/en-us/azure/storage/common/storage-create-storage-account for instructions.

Create a blob container

Using Azure Storage Explorer you can create a blob container.

Upload the VHD

Click the upload button and select “Upload Files”. Select one or more VHD-files to upload

l

Click “Upload” and wait for it to complete.

Deploying your virtual machine

For the script to work you will need an existing Resource Group containing a virtual network.

You will need to replace the variables with the settings for your deployment.

From storage explorer you can copy the storage account name and osDiskURI.

Click your storage account that you uploaded the files to:

The name of the storage account can be found at the bottom.

Click your blob container

The URL is found at the bottom and the URI is made up of URL + filename, in this example it’s azurevm.vhd. So the URI would be “https://revmgrstorage.blob.core.windows.net/revmgr/azurevm.vhd”

The rest of the variables can be found in the portal.

Copy the below script to the editor of your choice. I prefer Notepad++ or PowerShell ISE.

$RGName                	= "resourcegroupname"
$storageAccName        	= "storageaccountname"
$ComputerName          	= "Computer name"
$osDiskName            	= "name-of-osdisk"
$osDiskUri 			= "https://storageaccountname.blob.core.windows.net/blobcontainer/filename.vhd"
$location              	= "West Europe"
$vmName                	= "vm name"
$vmSize 			= "Standard_A2"
$cred 				= Get-Credential
$vnetName			= "existing vnet name"
$subnetIndex=0
$vnet=Get-AzureRMVirtualNetwork -Name $vnetName -ResourceGroupName $rgName
$nicName="nic name"
$pip=New-AzureRmPublicIpAddress -Name $nicName -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic -Force
$nic=New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id -Force
$storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $storageAccName
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Add-AzureRmVMNetworkInterface -VM $vmConfigget -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Linux
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm -Verbose


 

Edit the script with your parameters.

Use Add-AzureRMAccount to login to your subscription.

Run the script in PowerShell.

The script will only work for Linux virtual machines.

Once the script is done your vm is deployed to Azure.