Creating Debian VM on Windows Azure - Part 2
Create Virtual Machine with Debian System Disc
We will use the VM from VMDepot. If you use it from command line, you have to properly set the source image and also the final location of the blob in storage.
A word of caution! When I'm writing this blog post there is still open issue in Azure Command Line Tools that will not allow you to use affinity group without getting an error. Please refer to this issue and apply a patch to your local azure-cli copy before running
azure vm create command.
The command below will create a new virtual machine with many custom options:
azure vm create [dns-name] -o vmdepot-65-6-16 -a "[affinity-group-name]" [username] [password] -n [vm-name] -z [vm-size] -w [virtual-network-name] -b [vn-subnet] -u [blob location] -v [--ssh]
Yes, the command is the very long one, but I'll explain shortly some not obvious parts:
[dns-name]- DNS prefix which will be used for this VM or all other VMs attached to it later on (it is wise to make it mare generic than VM name
vmdepot-65-6-16- name of the source image, the last part (16) means it is in North Europe. To get proper one for other data centers, open VMDepot webpage, click on Deployment Script and look for similar string with different id
[vm-name]- the internal name of this exact VM
[vm-size]- size of VM, eg.
large. For VM preparation
[blob location]- you have to provide the full URL for target blob, where VM disk will be stored (use storage set up in part 1)
[vn-subnet]- use the names set up in part 1
[--ssh]- if you haven't set VPN in part 1, add this option to create the SSH endpoint to be able to log in using SSH
Please be aware that creating OS disk from image and starting VM can take several minutes.
I know that at the moment this only one VM, but it nice to add it to availability set (to not have all VMs in one rack in datacenter in the future). The sad thing is that at the moment you cannot set it from command line.
Go to the management portal, find the VM, then go to CONFIGURE tab, and then create new availability set.
SSH Keys and Small Preparations
I assume here that you want to log in to the virtual machine using SSH key instead of password. This will be the first thing to set up. I've you do not yet have Putty, install it (it is best to use installed, as you need also PuttyGen and in the future Pagent, Plink). Create SSH key using PuttyGen and save it, but do not close the PuttyGen.
Go to Management Portal, select VM and go to dashboard. Now read:
- SSH endpoint address if you do not have VPN set up
- internal IP address if you have the VPN set up
Start the VPN connection if it is set up. Start Putty and enter address and port from Management Portal. Log in using login and password from command line tools. Run below commands:
mkdir .ssh cd .ssh touch authorized_keys nano authorized_keys
Copy the string from PuttyGen (top part of the window) and paste into Putty console using right mouse click. Save the file using Ctrl+X combination, than Y key and Enter. Type
exit to close session. To test if all worked fine, load private SSH key using Pagent, open Putty but now in addition to address also go to Connection/Data on the right tree and set Auto-login username to one provided earlier. Connect to check if logged in without password.
Last thing to do is to update, upgrade and add 2-3 helpful packages. Run below commands:
sudo apt-get update sudo apt-get upgrade sudo apt-get install mc bash-completion chsh -s /bin/bash [username]
This is all for the second part. In the part 3 (the last one) we will add a separate data disc (it may be needed in some situations, like having a DB), but please remember that OS disc is persistent, so you can stop the VM or even remove it without losing VM setup etc.