Creating and Uploading a Virtual Hard Disk that Contains the Linux Operating System
This article shows you how to create and upload a virtual hard disk (VHD) so you can use it as your own image to create virtual machines in Azure. You'll learn how to prepare the operating system so you can use it to create multiple virtual machines based on that image.
You need an Azure account to complete this tutorial:
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 will never be charged, unless you explicitly change your settings and ask to be charged.
You can activate MSDN subscriber benefits: Your MSDN subscription gives you credits every month that you can use for paid Azure services.
A virtual machine in Azure runs the operating system that's based on the image you choose when you create the virtual machine. Your images are stored in VHD format, in .vhd files in a storage account. For details, see About Disks and Images in Azure.
When you create the virtual machine, you can customize some of the operating system settings so they're appropriate for the application you want to run. For instructions, see How to Create a Custom Virtual Machine.
Important: The Azure platform SLA applies to virtual machines running the Linux OS only when one of the endorsed distributions is used with the configuration details as specified under 'Supported Versions' in Linux on Azure-Endorsed Distributions. All Linux distributions in the Azure image gallery are endorsed distributions with the required configuration.
This article assumes that you have the following items:
A management certificate - You have created a management certificate for the subscription for which you want to upload a VHD, and exported the certificate to a .cer file. For more information about creating certificates, see Create and Upload a Management Certificate for Azure.
Linux operating system installed in a .vhd file - You have installed a supported Linux operating system to a virtual hard disk. Multiple tools exist to create .vhd files, for example you can use a virtualization solution such as Hyper-V to create the .vhd file and install the operating system. For instructions, see Install the Hyper-V Role and Configure a Virtual Machine.
Important: The newer VHDX format is not supported in Azure. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
For a list of endorsed distributions, see Linux on Azure-Endorsed Distributions. Alternatively, see the section at the end of this article for Information for Non-Endorsed Distributions.
Linux Azure command-line tool - if you are using a Linux operating system to create your image, you use the Azure Command-Line Tools for Linux and Mac to upload the VHD.
Azure Powershell tools - the
Add-AzureVhd cmdlet can also be used to upload the VHD. See Azure Downloads to download the Azure Powershell cmdlets. For reference information, see Add-AzureVhd.
Step 1: Prepare the image to be uploaded
Azure supports a variety of Linux distributions (see Endorsed Distributions). The following articles will guide you through how to prepare the various Linux distributions that are supported on Azure:
Also see the Linux Installation Notes for more tips on preparing Linux images for Azure.
After following the steps in the guides above you should have a VHD file that is ready to upload into Azure.
Step 2: Prepare the connection to Azure
Before you can upload a .vhd file, you need to establish a secure connection between your computer and your subscription in Azure.
If using Azure CLI
Open an Azure CLI window
When prompted, type your username and password.
If using Azure PowerShell
Open an Azure PowerShell window.
This command opens a browser window and automatically downloads a .publishsettings file that contains information and a certificate for your Azure subscription.
Save the .publishsettings file.
<PathToFile> is the full path to the .publishsettings file.
For more information, see How to install and configure Azure PowerShell
Step 3: Upload the image to Azure
If using Azure CLI
Use the Linux command-line tool to upload the image. You can upload an image by using the following command:
azure vm image create <image-name> --location <location-of-the-data-center> --os Linux <source-path-to the vhd>
If using PowerShell
You will need a storage account to upload your VHD file to. You can either pick an existing one or create a new one. To create a storage account please refer to Create a Storage Account
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 you plan to use, 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> -LocalFilePath <PathToVHDFile>
For more information, see Add-AzureVhd.