Share via


Creating and Uploading a Virtual Hard Disk that Contains the Linux Operating System

Important

Classic VMs will be retired on March 1, 2023.

If you use IaaS resources from ASM, please complete your migration by March 1, 2023. We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

Note

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 upload a custom disk image using Azure Resource Manager.

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. Learn how to prepare the operating system so you can use it to create multiple virtual machines based on that image.

Prerequisites

This article assumes that you have the following items:

Note

The newer VHDX format is not supported in Azure. When you create a VM, specify VHD as the format. If needed, you can convert VHDX disks to VHD using qemu-img convert or the Convert-VHD PowerShell cmdlet. Further, Azure does not support uploading dynamic VHDs, so you need to convert such disks to static VHDs before uploading. You can use tools such as Azure VHD Utilities for GO to convert dynamic disks during the process of uploading to Azure.

Step 1: Prepare the image to be uploaded

Azure supports various Linux distributions (see Endorsed Distributions). The following articles guide you through how to prepare the various Linux distributions that are supported on Azure. After you complete the steps in the following guides, come back here once you have a VHD file that is ready to upload to Azure:

Note

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.

Also see the Linux Installation Notes for more general tips on preparing Linux images for Azure.

Step 2: Prepare the connection to Azure

Make sure you are using the Azure CLI in the classic deployment model (azure config mode asm), then log in to your account:

azure login

Step 3: Upload the image to Azure

You need a storage account to upload your VHD file to. You can either pick an existing storage account or create a new one.

Use the Azure CLI to upload the image by using the following command:

azure vm image create <ImageName> `
    --blob-url <BlobStorageURL>/<YourImagesFolder>/<VHDName> `
    --os Linux <PathToVHDFile>

In the previous example:

  • 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 portal to identify the virtual hard disk.
  • PathToVHDFile is the full path and name of the .vhd file on your machine.

The following command shows a complete example:

azure vm image create myImage `
    --blob-url https://mystorage.blob.core.windows.net/vhds/myimage.vhd `
    --os Linux /home/ahmet/myimage.vhd

Step 4: Create a VM from the image

You create a VM using azure vm create in the same way as a regular VM. Specify the name you gave your image in the previous step. In the following example, we use the myImage image name given in the previous step:

azure vm create --userName ops --password P@ssw0rd! --vm-size Small --ssh `
    --location "West US" "myDeployedVM" myImage

To create your own VMs, provide your own username + password, location, DNS name, and image name.

Next steps

For more information, see Azure CLI reference for the Azure classic deployment model.