How to Attach an Empty Data Disk (VHD) to a New Azure Virtual Machine (VM)

How to Attach an Empty Data Disk (VHD) to a New Azure Virtual Machine (VM)

Getting Started with MS AzureWindows Azure is Microsoft’s platform, which offers Public Cloud. Azure provides the IaaS offering to host or run the user’s applications with Virtual Machines. The virtual machine is a server, which the user can access, control or manage as per the requirement and is created from the Virtual Hard Disk (VHD).

The present guide demonstrates how to attach a data disk to a Linux virtual machine in Windows Azure.

The virtual machine in MS Azure offers various kinds of disks, such as an OS disk, a local or temporary disk or a data disk. Azure allows attaching a disk to a virtual machine to store the application data. This data disk is similar to a Virtual Hard Disk (VHD). Azure allows creating a blank disk in the Azure cloud as well as importing the local data disk to the Azure cloud. Windows Azure allows attaching or detaching a data disk any time to a VM. However, there is a cap for attaching the maximum number of disks based on the vm size.

MS Azure Cloud VM Types

Check out for more information on the MS Azure VM types here

When the application is required to store some app specific data, it is beneficial to have an additional data disk attached to the virtual machine.

1. Create a virtual machine with Windows Azure

2. Select the VM to which disk will be attached and click on “attach” from the toolbar.

3. In the dialogue box provide the details given below and click on the correct sign to attach the disk.

a. Disk Size in GBs [Maximum 1 TB / 1024 GB]

b. Host cache preference: The host caching settings for an operating system disk or for a data disk improves the performance under certain circumstances. Host caching is set to off by default for both the read and write operations in data disks. However, it is set to on by default for operating system disks.

c. Do not change the storage location and VM name unless specifically required. This is because the storage location and VM have been selected by the VM user to attach the disk.

d. The user can change the name of the VHD file. However, the name of the disk is automatically generated.

4. It will take some time to attach the disk to the virtual machine. The portal will show the corresponding message above the toolbar.

5. Once the data disk has been attached, the user can check it in Portal -> Virtual Machines-> Dashboard in the disks. It will show both the OS and the data disks.

6. The disk will also be listed in the storage portal screen.

7. The data disk attached to the virtual machine will be offline until it has been initialized and mounted to the virtual machine. To initialize, Login to the virtual machine.

8. Run the following command:

ls /dev/sd*, which lists all the devices attached to the virtual machine. The new data disk is attached as /dev/sdc by default.

Also run the following command:

df –h to list all the device information. The device /dev/sdc will not be listed here.

9. First format the disk with the command sudo fdisk /dev/sdc.

[The user has changed the profile to root with the bash command to avoid typing “sudo” every time, as shown below]

When prompted, provide the partition as primary with the “p” input as marked. To create a new partition first type “n” and then type “p” to make it primary. If the console prompts for the number of partitions provide “1” or as per the user requirement.

10. Type “w” to write the settings to the disk.

11. The user is required to create a file system on the new partition. Run the following command:

“mkfs -t ext4 /dev/sdc” to create the file system.

12. After the disk is formatted and the file system has been created, mount it to the virtual machine with the following command:

sudo mount /dev/sdc1 /mnt/mountDevice

In the above mentioned command, create the /mnt/mountDevice folder if it does not exist.

13. Verify the devices mounted on the virtual machine with the “df-h” command.

14. The above image shows that the device /dev/sdc is mounted at /mnt/mountDevice.

15. The above mentioned steps will complete the process of creating an empty data disk to the virtual machine.

Keywords: Microsoft Azure, Windows Azure, Azure Cloud, Azure Public Cloud, Virtual Machines, Virtual Networks, Virtual Hard Disk, High Performance Computing, Azure VM, Azure Images Gallery, Azure VHD, Azure Virtual Hard Drive, Azure VHD, Azure VM, Getting started with MS Azure

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!

Hitchhiker's Guide to The Cloud

Newvem's eBook for Cloud Operations