Create and upload a Windows Server VHD to Azure
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 information about disks and images in Microsoft Azure, see About Disks and Images in Azure.
When you create a virtual machine based on an image, you can customize the operating system settings as appropriate for the applications you plan to run on the virtual machine. This configuration is saved for that virtual machine and doesn't affect the image. For instructions, see How to Create a Custom Virtual Machine.
This article assumes you have the following:
An Azure subscription - If you don't have one, you can create a free trial account in just a couple of minutes. For details, see Create an Azure account.
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 - You have installed a supported Windows Server operating system to a virtual hard disk. Multiple tools exist to create .vhd files. You can use a virtualization solution such as 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.
The VHDX format is not supported in Microsoft Azure. You can convert the disk to VHD format using Hyper-V Manager or the Convert-VHD cmdlet. A tutorial on this can be found here.
The following Windows Server versions are supported:
|OS ||SKU ||Service Pack ||Architecture |
|Windows Server 2012 R2 ||All editions ||N/A ||x64 |
|Windows Server 2012 ||All editions ||N/A ||x64 |
|Windows Server 2008 R2 ||All editions ||SP1 ||x64 |
This task includes the following steps:
Step 1: Prepare the image to be uploaded
Before the image can be uploaded to Azure, it must be generalized by using the Sysprep command. For more information about using Sysprep, see How to Use Sysprep: An Introduction.
From the virtual machine that the operating system was installed to, complete the following procedure:
Log 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.
Step 2: Create a storage account in Azure
You need a storage account in Azure to upload a .vhd file so it can be used in Azure to create a virtual machine. You can use the Azure Management Portal to create a storage account.
Sign in to the Azure Management 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 within the URL that is used to address 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 data center.
- 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, be aware that if you later turn on geo-replication, 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. More details on managing geo-replication of Storage accounts can be found here: 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.
Step 3: Prepare the connection to Microsoft Azure
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.
Use the Microsoft Azure AD method
Open the Azure PowerShell console, as instructed in How to: Install Microsoft Azure PowerShell.
Type the following command:
This command opens a sign-in window so you can sign with your work or school account.
Azure authenticates and saves the credential information, and then closes the window.
Use the certificate method
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.
For more information, see Get Started with Microsoft Azure Cmdlets
For more information on installing and configuring PowerShell, see How to install and configure Microsoft Azure PowerShell
Step 4: Upload the .vhd file
When you upload the .vhd file, you can place the .vhd file anywhere within your blob storage. In the following command examples, BlobStorageURL is the URL for the storage account that you created in Step 2, YourImagesFolder is the container within blob storage where you want to store your images. VHDName is the label that appears in the Management Portal to identify the virtual hard disk. PathToVHDFile is the full path and name of the .vhd file.
From the Azure PowerShell window you used in the previous step, type:
Add-AzureVhd -Destination "<BlobStorageURL>/<YourImagesFolder>/<VHDName>.vhd" -LocalFilePath <PathToVHDFile>
For more information about the Add-AzureVhd cmdlet, see Add-AzureVhd.
Step 5: Add the Image to Your List of Custom Images
After you upload the .vhd, you add it as an image to the list of custom images associated with your subscription.
From the Management Portal, under All Items, click Virtual Machines.
Under Virtual Machines, click Images.
And then click Create an Image.
In Create an image from a VHD, do the following:
- Specify name
- Specify description
- To specify the URL of your VHD, click the folder button to open the following window:
- Select the storage account your VHD is in and click Open. This returns you to the Create an image from a VHD window. - After you return to the Create an image from a VHD window, select the Operating System Family. - Check I have run Sysprep on the virtual machine associated with this VHD to acknowledge that you generalized the operating system in Step 1, and then click OK.
OPTIONAL : You can the Add-AzureVMImage cmdlet instead of the Management Portal to add your VHD as an image. In the Azure PowerShell console, type:
Add-AzureVMImage -ImageName <Your Image's Name> -MediaLocation <location of the VHD> -OS <Type of the OS on the VHD>
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 Virtual Machine Running Windows Server.
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 Management Portal to add the image (see step 5, above). The Azure cmdlets ensure that the VHD meets the Azure requirements.
After creating a virtual machine, trying creating a SQL Server Virtual Machine. For instructions, see Provisioning a SQL Server Virtual Machine on Microsoft Azure.