Create and upload a Windows Server VHD to Azure
This article shows you how to upload your own generalized VM image as a virtual hard disk (VHD) so you can use it to create virtual machines. For more details about disks and VHDs in Microsoft Azure, see About Disks and VHDs for Virtual Machines.
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource Manager model. . You can also capture and upload a virtual machine using the Resource Manager model.
This article assumes you have:
An Azure subscription - If you don't have one, you can open an Azure account for free.
Microsoft Azure PowerShell - You have the Microsoft Azure PowerShell module installed and configured to use your subscription.
A .VHD file - supported Windows operating system stored in a .vhd file and attached to a virtual machine. Check to see if the server roles running on the VHD are supported by Sysprep. For more information, see Sysprep Support for Server Roles.
Before you upload the VHD to Azure, it needs to be generalized by using the Sysprep tool. This prepares the VHD to be used as an image. For details about Sysprep, see How to Use Sysprep: An Introduction. Back up the VM before running Sysprep.
From the virtual machine that the operating system was installed to, complete the following procedure:
Sign in to the operating system.
Open a command prompt window as an administrator. Change the directory to %windir%\system32\sysprep, and then run
The System Preparation Tool dialog box appears.
In the System Preparation Tool, select Enter System Out of Box Experience (OOBE) and make sure that Generalize is checked.
In Shutdown Options, select Shutdown.
You need a storage account in Azure so you have a place to upload the .vhd file. This step shows you how to create an account, or get the info you need from an existing account. Replace the variables in ‹ brackets › with your own information.
Set your Azure subscription.
Select-AzureSubscription -SubscriptionName <SubscriptionName>
Create a new storage account. The name of the storage account should be unique, 3-24 characters. The name can be any combination of letters and numbers. You also need to specify a location like "East US"
New-AzureStorageAccount –StorageAccountName <StorageAccountName> -Location <Location>
Set the new storage account as the default.
Set-AzureSubscription -CurrentStorageAccountName <StorageAccountName> -SubscriptionName <SubscriptionName>
Create a new container.
New-AzureStorageContainer -Name <ContainerName> -Permission Off
Use the Add-AzureVhd to upload the VHD.
From the Azure PowerShell window you used in the previous step, type the following command and replace the variables in ‹ brackets › with your own information.
Add-AzureVhd -Destination "https://<StorageAccountName>.blob.core.windows.net/<ContainerName>/<vhdName>.vhd" -LocalFilePath <LocalPathtoVHDFile>
Use the Add-AzureVMImage cmdlet to add the image to the list of your custom images.
Add-AzureVMImage -ImageName <ImageName> -MediaLocation "https://<StorageAccountName>.blob.core.windows.net/<ContainerName>/<vhdName>.vhd" -OS "Windows"
You can now create a custom VM using the image you uploaded.