Create and upload a Windows Server VHD to Azure
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.
This article shows you how to upload a virtual hard disk (VHD) with an operating system so you can use it as an image to create virtual machines based on that image. For more details about disks and VHDs in Microsoft Azure, see About Disks and VHDs for Virtual Machines.
This article assumes you have:
An Azure subscription - If you don't have one, you can open an Azure account for free: You get credits you can use to try out paid Azure services, and even after they're used up you can keep the account and use free Azure services, such as Websites. Your credit card won't be charged, unless you explicitly change your settings and ask to be charged. You also can activate MSDN subscriber benefits: Your MSDN subscription gives you credits every month that you can use for paid Azure services.
Microsoft Azure PowerShell - You have the Microsoft Azure PowerShell module installed and configured to use your subscription. To download the module, see Microsoft Azure Downloads. A tutorial to install and configure the module is available here. You'll use the Add-AzureVHD cmdlet to upload the VHD.
A supported Windows operating system stored in a .vhd file and attached to a virtual machine - Multiple tools exist to create .vhd files. For example, you can use Hyper-V to create a virtual machine and install the operating system. For instructions, see Install the Hyper-V Role and configure a virtual machine. For details about operating systems, see Microsoft server software support for Microsoft Azure virtual machines.
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.
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.
Sign in to the Azure classic portal.
On the command bar, click New.
Click Data Services > Storage > Quick Create.
Fill out the fields as follows:
- Under URL, type a subdomain name to use in the URL for the storage account. The entry can contain from 3-24 lowercase letters and numbers. This name becomes the host name of the URL you use to access blob, queue, or table resources for the subscription.
- Choose the location or affinity group for the storage account. An affinity group lets you place your cloud services and storage in the same datacenter.
- Decide whether to use geo-replication for the storage account. Geo-replication is turned on by default. This option replicates your data to a secondary location, at no cost to you, so that your storage fails over to that location if a major failure occurs at the primary location. The secondary location is assigned automatically, and can't be changed. If you need more control over the location of your cloud-based storage due to legal requirements or organizational policy, you can turn off geo-replication. However, if you turn on geo-replication later, you will be charged a one-time data transfer fee to replicate your existing data to the secondary location. Storage services without geo-replication are offered at a discount. For more details, see Create, manage, or delete a storage account.
Click Create Storage Account. The account now appears under Storage.
Next, create a container for your uploaded VHDs. Click the storage account name and then click Containers.
Click Create a Container.
Type a Name for your container and select the Access policy.
By default, the container is private and can be accessed only by the account owner. To allow public read access to the blobs in the container, but not the container properties and metadata, use the Public Blob option. To allow full public read access for the container and blobs, use the Public Container option.
Sign in to the Azure classic portal.
From the navigation pane, click Storage.
Click the name of the storage account, and then click Dashboard.
From the dashboard, under Services, hover over the Blobs URL, click the clipboard icon to copy the URL, then paste and save it. You'll use it when you build the command to upload the VHD.
Before you can upload a .vhd file, you need to establish a secure connection between your computer and your subscription in Azure. You can use the Microsoft Azure Active Directory method or the certificate method to do this.
To get started with Azure PowerShell, see How to install and configure Microsoft Azure PowerShell. For general information, see Get Started with Microsoft Azure Cmdlets.
Open the Azure PowerShell console.
In the sign-in windows, type the user name and password of your work or school account.
Azure authenticates and saves the credential information, and then closes the window.
Open the Azure PowerShell console.
A browser window opens and prompts you to download a .publishsettings file. It contains information and a certificate for your Microsoft Azure subscription.
Save the .publishsettings file.
<PathToFile>is the full path to the .publishsettings file.
When you upload the .vhd file, you can place the .vhd file anywhere within your blob storage.
From the Azure PowerShell window you used in the previous step, type a command similar to this:
Add-AzureVhd -Destination "<BlobStorageURL>/<YourImagesFolder>/<VHDName>.vhd" -LocalFilePath <PathToVHDFile>
- BlobStorageURL is the URL for the storage account
- YourImagesFolder is the container within blob storage where you want to store your images
- VHDName is the name you want the Azure classic portal to display to identify the virtual hard disk
- PathToVHDFile is the full path and name of the .vhd file
For more information about the Add-AzureVhd cmdlet, see Add-AzureVhd.
To use Azure PowerShell instead of the Azure classic portal to add the image, use the Add-AzureVMImage cmdlet. For example:
Add-AzureVMImage -ImageName <ImageName> -MediaLocation <VHDLocation> -OS <OSType>
From the Azure classic portal, under All Items, click Virtual Machines.
Under Virtual Machines, click Images.
Click Create an Image.
In the Create an image from a VHD window:
- Specify the name.
- Specify the description.
- Under VHD URL, click the folder button to open the Browse Cloud Storage window. Find the .vhd file, and then click Open.
In the Create an image from a VHD window, under Operating System Family, select your operating system. Check I have run Sysprep on the virtual machine associated with this VHD to verify that you generalized the operating system, and then click OK.
After you complete the previous steps, the new image is listed when you choose the Images tab.
This new image is now available under My Images when you create a virtual machine. For instructions, see Create a custom virtual machine.
If you get an error when you try to create a VM, with this error message, "The VHD https://XXXXX... has an unsupported virtual size of YYYY bytes. The size must be a whole number (in MBs)," it means your VHD is not a whole number of MBs and needs to be a fixed size VHD. Try using the Add-AzureVMImage PowerShell cmdlet instead of the Azure classic portal to add the image (see step 5, above). The Azure cmdlets ensure that the VHD meets the Azure requirements.