Creating Debian VM on Windows Azure - Part 3

In the last part we will add a separate data disk to our VM. It is not required. There are cases where this is necessary, but there are many more where this is not needed, especially if you want to have stateless VMs so you can easily spin up more of them. In those cases you will use the persistence layer of Windows Azure (SQL Database, Azure Storage) or separate Linux VMs for your own persistence layer (MongoDB). We will prepare for this second case.


Virtual Machines on Windows Azure are stateful. This applies to OS disk. You can write to it whatever you want and it will be persisted on Azure Storage Blob. But OS disk has limits on size (127 GB) and by default is optimized for reads and writes by using cache, which is not good for DB data or similar.

OS disk can be generalized and pretty easily used to create many identical virtual machines quickly (using snapshots). But to do it really quickly it is better to not have any persistence stored on them. In those cases you do not need a separate data disk.

Then there is a question? There must be a persistence layer somewhere. If you will use what Windows Azure provides (SQL Database, Azure Storage), you do not have to care about data disks at all. But if you want to build your own persistence layer on several separate virtual machines - for example to get up MongoDB, MySQL or something similar) - separate data disks are the way to go.

Adding a New Disk to VM

Adding a new data disk is very easy:

azure vm disk attach-new [vm-name] [size] [location-in-blob]
  • the [size] is in GB and at the moment you can create up to 1 TB disk

For some bigger virtual machine sizes you can attach more than one data disk, but the rules are the same.

Preparing and Formatting

First you have to check on which /dev/ the data disk is:

sudo grep SCSI /var/log/messages

Look for the last entry (for example /dev/sdc).

Now run below command:

sudo fdisk /dev/sdc

Now it is best to use below keys on keyboard: n, Enter, p, Enter, 1, Enter, Enter, Enter, p, Enter, w, Enter. After doing all of this you have created one partition that you can format using below command:

sudo mkfs -t ext4 /dev/sdc1

Now almost the last step is to mount the disk somewhere:

sudo mkdir /mnt/data
sudo mount /dev/sdc1 /mnt/data1

Of course this will not survive the VM restart, so start the text editor as superuser and edit /etc/fstab by adding below entry

/dev/sdc1 /mnt/data ext4 defaults 0 0

To check if everything is set up properly, restart the VM and check if data disk will be mounted:

shutdown -r now

After this you can now start to install MongoDB, MySQL, PostgreSQL on VM created in this tutorial, but for high availability I really recommend using more than one VM. If you do not want to play with those setup, you can always use Windows Azure SQL Database and Storage, which have persistence and high availability build in (personally I think that for websites and web services this is the hardest part and it is best to "outsource" the problem).