Create a Virtual Machine Running Linux
Creating a virtual machine that is running the Linux operating system is easy when you use the Image Gallery in the Windows Azure Management Portal. This guide assumes that you have no prior experience using Windows Azure. You can create a virtual machine running the Linux operating system in the cloud that you can access and customize.
You will learn:
Note: This tutorial creates a virtual machine that is not connected to a virtual network. If you want a virtual machine to use a virtual network, you must specify the virtual network when you create the virtual machine. For more information about virtual networks, see Windows Azure Virtual Network Overview.
What is a virtual machine in Windows Azure
A virtual machine in Windows Azure is a server in the cloud that you can control and manage. After you create a virtual machine in Windows Azure, you can delete and recreate it whenever you need to, and you can access the virtual machine just as you do with a server in your office. Virtual hard disk (VHD) files are used to create a virtual machine. The following types of VHDs are used for a virtual machine:
- Image - A VHD that is used as a template to create a new virtual machine. An image is a template because it doesn’t have specific settings like a running virtual machine, such as the computer name and user account settings. If you create a virtual machine using an image, an operating system disk is automatically created for the new virtual machine.
- Disk - A disk is a VHD that you can boot and mount as a running version of an operating system. After an image is provisioned, it becomes a disk. A disk is always created when you use an image to create a virtual machine. Any VHD that is attached to virtualized hardware and that is running as part of a service is a disk
The following options are available for using images to create a virtual machine:
How to create a custom virtual machine running the Linux operating system by using the Management Portal
You use the From Gallery method to create a custom virtual machine in the Management Portal. This method provides more options for configuring the virtual machine when you create it, such as the connected resources, the DNS name, and the network connectivity if needed.
-
Sign in to the Windows Azure Management Portal. On the command bar, click New.

-
Click Virtual Machine, and then click From Gallery.

-
The Select the virtual machine operating system dialog box appears.
-
From Platform Images, select the OpenLogic CentOS 6.2 image, and then click the arrow to continue.
The Virtual machine configuration dialog box appears.
-
In Virtual Machine Name, type the name that you want to use for the virtual machine. The name must be 15 characters or less. For this virtual machine, type MyTestVM1.
-
In New User Name, type the name of the account that you will use to administer the virtual machine. You cannot use root for the user name. For this virtual machine, type NewUser1.
-
In New Password, type a strong password for the administrative account on the virtual machine. For this virtual machine, type @dm1nVM1. In Confirm Password, retype the password.
-
In Size, select the size that you want to use for the virtual machine. The size that you choose depends on the number of cores that are needed for your application. For this virtual machine, accept the default of Extra Small.
-
Click the arrow to continue.
The Virtual machine mode dialog box appears.
-
You can connect virtual machines together under a cloud service to provide robust applications, but for this tutorial, you only create a single virtual machine. To do this, select Standalone Virtual Machine.
-
A virtual machine that you create is contained in a cloud service. In DNS Name, type a name for the cloud service that is created for the virtual machine. The entry can contain from 3-24 lowercase letters and numbers. This value becomes part of the URI that is used to contact the cloud service that the machine belongs to. For this virtual machine, type MyService1.
-
You can select a storage account where the VHD file is stored. For this tutorial, accept the default setting of Use Automatically Generated Storage Account.
-
In Region/Affinity Group/Virtual Network, select where you want to locate the virtual machine.
-
Click the arrow to continue.
The Virtual machine options dialog box appears.
-
The options on this page are only used if you are connecting this virtual machine to other machines or if you are adding the machine to a virtual network. For this virtual machine, you are not creating an availability set or connecting to a virtual network. Click the check mark to create the virtual machine.
The virtual machine is created and operating system settings are configured. When the virtual machine is created, you will see the new virtual machine listed as Running in the Windows Azure Management Portal.

How to log on to the virtual machine after you create it
To manage the settings of the virtual machine and the applications that run on the machine, you can use a Secure Shell (SSH) client. To do this, you must install an SSH client on your computer that you want to use to access the virtual machine. There are many SSH client programs that you can choose from. The following are possible choices:
- If you are using a computer that is running a Windows operating system, you might want to use an SSH client such as PuTTY. For more information, see PuTTY Download.
- If you are using a computer that is running a Linux operating system, you might want to use an SSH client such as OpenSSH. For more information, see OpenSSH.
This tutorial shows you how to use the PuTTY program to access the virtual machine.
-
Find the Host Name and Port information from the Management Portal. You can find the information that you need from the dashboard of the virtual machine. Click the virtual machine name and look for the SSH Details in the Quick Glance section of the dashboard.

-
Open the PuTTY program.
-
Enter the Host Name and the Port information that you collected from the dashboard, and then click Open.

-
Log on to the virtual machine using the NewUser1 account that you specified when the machine was created.

You can now work with the virtual machine just as you would with any other server.
How to attach a data disk to the new virtual machine
Your application may need to store data. To set this up, you attach a data disk to the virtual machine that you previously created. The easiest way to do this is to attach an empty data disk to the machine.
-
If you have not already done so, sign in to the Windows Azure Management Portal.
-
Click Virtual Machines, and then select the MyTestVM1 virtual machine that you previously created.
-
On the command bar, click Attach, and then click Attach Empty Disk.

The Attach Empty Disk dialog box appears.

-
The Virtual Machine Name, Storage Location, and File Name are already defined for you. All you have to do is enter the size that you want for the disk. Type 5 in the Size field.
Note: All disks are created from a VHD file in Windows Azure storage. You can provide a name for the VHD file that is added to storage, but the name of the disk is automatically generated.
-
Click the check mark to attach the data disk to the virtual machine.
-
You can verify that the data disk is successfully attached to the virtual machine by looking at the dashboard. Click the name of the virtual machine to display the dashboard.
The number of disks is now 2 for the virtual machine and the disk that you attached is listed in the Disks table.

The data disk that you just attached to the virtual machine is offline and not initialized after you add it. You must log on to the machine and initialize the disk to use it for storing data.
-
Connect to the virtual machine by using the steps listed above in How to log on to the virtual machine after you create it.
-
In the SSH window, type the following command, and then enter MyPassword1 for the account password:
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 MyPassword1 for 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 MyPassword1 for the account password:
sudo mkfs -t ext4 /dev/sdc1

-
Type the following command to make a directory for mounting the drive, and then enter MyPassword1 for 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.
How to set up communication with the virtual machine
All virtual machines that you create in Windows Azure can automatically communicate with other virtual machines in the same cloud service or virtual network. However, you need to add an endpoint to a machine for other resources on the Internet or other virtual networks to communicate with it. You can associate specific ports and a protocol to endpoints.
-
If you have not already done so, sign in to the Windows Azure Management Portal.
-
Click Virtual Machines, and then select the MyTestVM1 virtual machine that you previously created.
-
Click Endpoints.

-
For this tutorial, you add an endpoint for communicating with the virtual machine using the TCP protocol. Click Add Endpoint.

The Add Endpoint dialog box appears.

-
Accept the default selection of Add Endpoint, and then click the arrow to continue.
The New Endpoint Details page appears.

-
In Name, type MyTCPEndpoint1.
-
In Public Port and Private Port, type 80. These port numbers can be different. The public port is the entry point for communication from outside of Windows Azure and is used by the Windows Azure load balancer. You can use the private port and firewall rules on the virtual machine to redirect traffic in a way that is appropriate for your application. Linux images that are available in the Image Gallery may have their local firewall disabled. If the firewall is disabled, you must open the external endpoint to enable communication with the virtual machine.
-
Click the check mark to create the endpoint.
You will now see the endpoint listed on the Endpoints page.

Next Steps
To learn more about Linux on Windows Azure, see the following articles: