Free trial

How to Attach a Data Disk to a Virtual Machine

Concepts

You can attach a data disk to a virtual machine to store application data. A data disk is a Virtual Hard Disk (VHD) that you can create either locally with your own computer or in the cloud with Windows Azure. You manage data disks in the virtual machine the same way you do on a server in your office.

You can upload and attach a data disk that already contains data to the virtual machine, or you can attach an empty disk to the machine. The virtual machine is not stopped to add the disk. You are limited in the number of disks that you can attach to a virtual machine based on the size of the machine. The following table lists the number of attached disks that are allowed for each size of virtual machine. For more information about virtual machine and disk sizes, see Virtual Machine Sizes for Windows Azure.

For more information about using data disks, see Manage disks and images.

How to: Attach an existing disk

  1. If you have not already done so, sign in to the Windows Azure Management Portal.

  2. Click Virtual Machines, and then select the virtual machine to which you want to attach the disk.

  3. On the command bar, click Attach, and then select Attach Disk.

    Attach data disk

    The Attach Disk dialog box appears.

    Enter data disk details

  4. Select the data disk that you want to attach to the virtual machine.

  5. Click the check mark to attach the data disk to the virtual machine.

    You will now see the data disk listed on the dashboard of the virtual machine.

    Data disk successfully attached

How to: Attach an empty disk

When you create a new data disk, you decide the size of the disk. After you attach an empty disk to a virtual machine, the disk will be offline. You must connect to the virtual machine, and then use Server Manager to initialize the disk before you can use it.

Note: Windows Azure storage supports blobs up to 1TB in size, which accommodates a VHD with a maximum virtual size 999GB. When you enter “1TB” in Hyper-V for a new hard disk, the value represents the virtual size. This yields a file that is oversized by 512 bytes.

  1. Click Virtual Machines, and then select the virtual machine to which you want to attach the data disk.

  2. On the command bar, click Attach, and then select Attach Empty Disk.

    Attach an empty disk

    The Attach Empty Disk dialog box appears.

    Attach a new empty disk

  3. In Storage Location, select the storage account where you want to store the VHD file that is created for the data disk.

  4. In File Name, either accept the automatically generated name or enter a name that you want to use for the VHD file that is stored. The data disk that is created from the VHD file will always use the automatically generated name.

  5. In Size, enter the size of the data disk.

  6. Click the check mark to attach the empty data disk.

    You will now see the data disk listed on the dashboard of the virtual machine.

    Empty data disk successfully attached

How to: Initialize a new data disk in Windows Server 2008 R2

The data disk that you just attached to the virtual machine is offline and not initialized after you add it. You must access the machine and initialize the disk to use it for storing data.

  1. Connect to the virtual machine by using the steps listed in How to log on to a virtual machine running Windows Server.

  2. After you log on to the machine, open Server Manager, in the left pane, expand Storage, and then click Disk Management.

    Open Server Manager

  3. Right-click Disk 2, and then click Initialize Disk.

    Initialize the disk

  4. Click OK to start the initialization process.

  5. Right-click the space allocation area for Disk 2, click New Simple Volume, and then finish the wizard with the default values.

    Initialize the volume

    The disk is now online and ready to use with a new drive letter.

    Volume successfully initialized

How to: Initialize a new data disk in Linux

  1. Connect to the virtual machine by using the steps listed in How to log on to a virtual machine running Linux.

  2. In the SSH window, type the following command, and then enter the password for the account that you created to manage the virtual machine:

    sudo grep SCSI /var/log/messages

    You can find the identifier of the last data disk that was added in the messages that are displayed.

    Get the disk messages

  3. In the SSH window, type the following command to create a new device, and then enter the account password:

    sudo fdisk /dev/sdc

  4. In the SSH window, type the following command to create a new device, and then enter the account password:

    sudo fdisk /dev/sdc

  5. Type n to create a new partition.

    Create new device

  6. Type p to make the partition the primary partition, type 1 to make it the first partition, and then type enter to accept the default value for the cylinder.

    Create partition

  7. Type p to see the details about the disk that is being partitioned.

    List disk information

  8. Type w to write the settings for the disk.

    Write the disk changes

  9. You must create the file system on the new partition. Type the following command to create the file system, and then enter the account password:

    sudo mkfs -t ext4 /dev/sdc1

    Create file system

  10. Type the following command to make a directory for mounting the drive, and then enter the account password:

    sudo mkdir /mnt/datadrive

  11. Type the following command to mount the drive:

    sudo mount /dev/sdc1 /mnt/datadrive

    The data disk is now ready to use as /mnt/datadrive.