Blog

How to Attach and Mount VHD Files to Azure Virtual Machines

Microsoft Azure has two types of virtual hard disks (VHDs): unmanaged and managed. When comparing Azure managed vs. unmanaged disks, the biggest difference is that the latter are maintained by the end user in their own storage accounts.

These unmanaged disks are bound by storage account limits, which leads to needing several storage accounts when the deployment has to scale. Managed disks are part of the Azure Managed Disks service. This disk type overcomes the storage account limit obstacle by having Microsoft manage the storage accounts for you. There are a number of other advantages that Azure managed disks have over unmanaged disks.

How can you mount VHD files to Azure virtual machines? This article will discuss methods you can use to attach, and mount managed and unmanaged VHD blob storage to Azure virtual machines (VMs). All the steps in this article are compatible with Azure Resource Manager (ARM), but if you need to create storage accounts for Azure Service Manager (ASM), make sure to use the “Storage Accounts (classic) option” in the new portal. As well as attaching data disks, we will also look at how NetApp’s Cloud Volumes ONTAP (formerly ONTAP Cloud) can be used to provide additional storage solutions for once you mount VHD files to Azure virtual machines.

Steps for Attaching Azure Managed Disks and Unmanaged Disks to
Windows VMs


Here is the step-by-step procedure for adding a VHD in Azure to a Windows VM through the Azure Resource Manager (ARM) portal.

Step 1:

Open up the Azure Resource Manager portal and browse over to the “Virtual Machine” blade.

Step 2:

Go to “Settings” and click on “Disks.” On the blade that opens up, click on the “+ Add data disk” option.

Azure Resource Manager
If you are adding an unmanaged disk, a dialog box like the one shown below will open:
 attach unmanaged disc

With managed disks, the dialog box that opens will display the options seen below:

Screen Shot 2018-05-08 at 4.14.31 PM

Step 3:


This next step varies depending on whether you are using an existing VHD or creating a new one.

Existing Azure VHD:
For unmanaged disks, select “Existing blob” under the “Source type” drop-down menu. In the “Source blob” field, browse for the blob container and then select the VHD that you want to attach.

Screen Shot 2018-05-08 at 4.25.01 PM

For managed disks, select the managed disk from the drop-down menu under “Name” as shown below:

Screen Shot 2018-05-08 at 4.25.49 PM
New VHD:
For unmanaged disks, select “New (empty disk)” in the “Source type” field. Next, select the Blob container where you want to store the VHD.

Screen Shot 2018-05-08 at 4.27.01 PM
For managed disks, click on the “Create disk” option under the “Name” drop-down menu.

Screen Shot 2018-05-08 at 4.27.52 PM
In the appropriate fields, specify the name, size and resource group of the disk to be created:

Screen Shot 2018-05-08 at 4.29.05 PM


Step 4:

Clicking on “Save” will attach the data disk to the VM. When you connect to the VM through RDP, you can see the attached disk under the “Disk Management” console. If it is a new disk, you can initialize and format the attached VHD. Otherwise, if it is a VHD containing your data, right click and bring it online.

Screen Shot 2018-05-08 at 4.29.57 PM

Attach and Mount VHD Files to a Linux VM

Here are the steps to add and mount VHD files, both unmanaged and managed disks, to a Linux VM. This example will use an Ubuntu distro.

Step 1:

Browse to the Ubuntu VM using the Azure portal.

Step 2:


Under “Settings,” click on “Disks.” On the blade that opens up, select the option “+ Add data disk”.

Screen Shot 2018-05-08 at 4.30.55 PM
For attaching managed disks, you’ll follow the same actions described in Step 2 in the above section on attaching disks to Windows VMs.

For unmanaged disks, you’ll see the same options as in the image below:

Screen Shot 2018-05-08 at 4.33.37 PM
Step 3:

First, select “Existing blob” in the “Source type” field. Next, browse the “Storage container” menu and select the VHD to be attached. For instructions on how to add new managed and unmanaged disks, please follow the same steps given in Step 3 of the Windows VM section above.

Screen Shot 2018-05-08 at 4.35.44 PM


Step 4:


Clicking on “Save” will add the data VHD. Now, connect to the Linux VM through SSH.

Screen Shot 2018-05-08 at 4.36.46 PM

Step 5:

If this is a disk with existing data, skip ahead to Step 8. Otherwise, start with this step. To list the disks, use this command:

“dmesg | grep SCSI”

Screen Shot 2018-05-08 at 4.38.33 PM
In this case, it is the sdc drive that was newly attached. You can view more details on that drive by using this command:

sudo smartctl -d scsi -a -i /dev/sdc

Screen Shot 2018-05-08 at 4.39.36 PM

Step 6:

Now that we have identified the SCSI disk, let’s format and mount it. Use the fdisk command to partition your disk. In this example, one primary partition encompassing the whole drive has been created:

Screen Shot 2018-05-08 at 4.40.24 PM

Step 7:


After the partition is created, you’ll need to write the file system (in this example ext4):

Screen Shot 2018-05-08 at 4.41.14 PM

Step 8:


After the file system has been written, assign a directory and mount the device to the directory.

Screen Shot 2018-05-08 at 4.42.09 PM

Step 9:


Now that we have the drive set up, you can read and write files from it.

Screen Shot 2018-05-08 at 4.43.04 PM

Using Powershell and Azure CLI to Attach Disks


For PCs running on Linux or Mac (or even Windows using WSL), you can use Azure Command Line Interface (CLI) to create and manage Azure resources. Having said that, this blog post’s author prefers to connect to Azure CLI through Azure Cloud Shell directly on the Azure portal. Here are some of the commands that you would run to attach disks to an Azure VM.

Managaed disks: The following command would add a new 20GB managed disk named “netappman2” to the VM “netappmanvm” in the resource group “netapptests”:

az vm disk attach -g netapptests --vm-name netappmanvm --disk netappman2 --new --size-gb 20

Unmanaged disks: This command will add a new 20GB unmanaged disk named “netappunman3” of to the VM “netappwintest” and place it under the same storage account as the VM:

az vm unmanaged-disk attach -g netapptests -n netappunman3 --vm-name netappwintest --new --size-gb 20

For more command lines, the article behind this link has a full list of Azure CLI commands.

Microsoft Powershell is another programmatic tool that can be used to attach VHDs to virtual machines. Start by logging into the Azure RM account:

Login-AzureRmAccount

The following cmdlets would get the information of the VM “netappwintest” and attach an unmanaged disk named netappunman3 with 20GB capacity:

$VM = Get-AzureRmVM -ResourceGroupName netapptests -Name netappwintest

Add-AzureRmVMDataDisk -VM $VirtualMachine -Name "netappunman3" -VhdUri "https://dataunman2.blob.core.windows.net/netappunman1/netappunman3.vhd" -LUN 0 -Caching ReadOnly -DiskSizeinGB 20 -CreateOption Empty

Update-AzureRmVM -ResourceGroupName "netapptests" -VM $VirtualMachine

NetApp Cloud Volumes ONTAP


While Azure Disks and VHDs allow for a single virtual machine to actively make use of a storage allocation, sometimes data needs to be shared between many virtual machines concurrently. This requires the use of NFS or CIFS file share services that client hosts can connect to.

NetApp’s Cloud Volumes ONTAP for Azure provides a comprehensive solution for cloud storage management, which includes the provisioning of cloud-based NAS services. Cloud Volumes ONTAP is built on top of Azure compute and Azure storage resources and can therefore be made readily available to your existing virtual machines.

Here are some of the benefits of using Cloud Volumes ONTAP:

  • Multi-protocol support: Cloud Volumes ONTAP can serve out both NFS and CIFS shares, as well as block-level storage allocations over iSCSI. This allows you to centrally manage all of the storage use across your enterprise
  • Space efficiencies: Many of the core features in Cloud Volumes ONTAP help to reduce your cloud storage footprint and related costs. These cost-cutting storage efficiencies on Azure include data compression, data compaction, and data deduplication, to name a few. Thin provisioning can be used to “grow-as-you-go” by only allocating storage when it is actually needed
  • Snapshots and cloning: Cloud Volumes ONTAP can create instant, space-efficient, point-in-time copies of any storage volume. These snapshots can then be used as a basis for a copy-on-write clone of the data, which can be used, for example, for development or testing
  • Enterprise-grade data replication: Using SnapMirror for data replication, Cloud Volumes ONTAP can incrementally synchronize data between any NetApp systems, whether on-premises or in the cloud. This can be a huge win when you need to migrate data from existing in-house systems to Azure, or when creating a DR (disaster recovery) environment
  • Easy to use/integrate: OnCommand Cloud Manager provides a modern, web-based user interface for deploying and managing all of your Cloud Volumes ONTAP instances. In addition to this, DevOps users and administrators can make use of the fully-featured RESTful API for integrating Cloud Volumes ONTAP with their data workflows


Final Note

That’s our rundown for how to mount VHD files to Azure VMs. Although managed disks have a number of features and functionalities that unmanaged disks just don’t offer, make sure you understand that there are a few gotchas involved with using managed disks. For instance, the pricing for standard managed disks is based on provisioned size: that means you’re paying for disk space you may not wind up using. Using Cloud Volumes ONTAP with Azure, you can wind up saving on the amount you spend on Azure storage. To see for yourself, take a look at our Azure calculator to see what Cloud Volumes ONTAP can do to lower your TCO.

One last note: if you are using standard disks, don’t forget to turn on TRIM on the Windows and Linux VMs after you attach VHD disks. Trim discards unused blocks on the disk and helps save on costs if you create large files and then delete them. You can do this in Windows by running the fsutil command and in Linux by using the fstrim command.

For more about Cloud Volumes ONTAP on Azure, visit us here, or to start a 30-day free trial today.

New call-to-action

Related Articles

ONTAP Cloud is Now Cloud Volumes ONTAP

Read More

Data Replication: How SnapMirror Works When it Comes to...

Read More

Alibaba Cloud Computing: An Introduction

Read More
-