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.
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.
Click Virtual Machines, and then select the virtual machine to which you want to attach the data disk.
On the command bar, click Attach, and then select Attach Empty Disk.
The Attach Empty Disk dialog box appears.
In Storage Location, select the storage account where you want to store the VHD file that is created for the data disk.
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.
In Size, enter the size of the data disk.
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.
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.
Connect to the virtual machine by using the steps listed in How to log on to a virtual machine running Linux.
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.
In the SSH window, type the following command to create a new device, and then enter the account password:
sudo fdisk /dev/sdc
Type n to create a new partition.
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.
Type p to see the details about the disk that is being partitioned.
Type w to write the settings for the disk.
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
Type the following command to make a directory for mounting the drive, and then enter the account password:
sudo mkdir /mnt/datadrive
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.
Add the new drive to /etc/fstab:
To ensure the drive is re-mounted automatically after a reboot it must be added to the /etc/fstab file. In addition, it is highly recommended that the UUID (Universally Unique IDentifier) is used in /etc/fstab to refer to the drive rather than just the device name (i.e. /dev/sdc1). To find the UUID of the new drive you can use the blkid utility:
sudo -i blkid
The output will look similar to the following:
`/dev/sda1: UUID="11111111-1b1b-1c1c-1d1d-1e1e1e1e1e1e" TYPE="ext4"`
`/dev/sdb1: UUID="22222222-2b2b-2c2c-2d2d-2e2e2e2e2e2e" TYPE="ext4"`
`/dev/sdc1: UUID="33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e" TYPE="ext4"`
Note: blkid may not require sudo access in all cases, however, it may be easier to run with
sudo -i on some distributions if /sbin or /usr/sbin are not in your
Caution: Improperly editing the /etc/fstab file could result in an unbootable system. If unsure, please refer to the distribution's documentation for information on how to properly edit this file. It is also recommended that a backup of the /etc/fstab file is created before editing.
Using a text editor, enter the information about the new file system at the end of the /etc/fstab file. In this example we will use the UUID value for the new /dev/sdc1 device that was created in the previous steps, and the mountpoint /mnt/datadrive:
UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e /mnt/datadrive ext4 defaults 1 1
If additional data drives or partitions are created you will need to enter them into /etc/fstab as well.
You can now test that the file system is mounted properly by simply unmounting and then re-mounting the file system, i.e. using the example mount point
/mnt/datadrive created in the earlier steps:
`sudo umount /mnt/datadrive`
`sudo mount /mnt/datadrive`
If the second command produces an error please check the /etc/fstab file for correct syntax.