共用方式為


Step-by-Step: Deploy a new Linux VM from a captured image

Hello folks,

in my last post we discussed who to capture an existing Linux machine in Azure in order to be able to deploy new instances of that machine.  In effect turning that machine into a template.

Now, we’ll use that image, Azure CLI and the and the JSON template the last process generated to create a new Linux VM in a new virtual network.

 

Creating environment to deploy the template.

To deploy the Linux machine we imaged in the last post we need to set up a virtual network and NIC for your new VM. Furthermore, we recommend using a new resource group for these resources in the location where your VM image is stored.

Using Azure CLI we will use the following command in order to create the Resource Group, the virtual network, the subnet with address space and the public IP address.

In these command I will use the following :

  1. RG-New-CDNeast-1 as my new resource group name.
  2. East US "eastus" is the location.
  3. VNet1 is the virtual network name
  4. FrontEnd is the subnet name
  5. publicip is the Public IP object name

 

 
azure group create RG-New-CDNeast-1 -l "eastus"
azure network vnet create RG-New-CDNeast-1 VNet1 -l "eastus"
azure network vnet subnet create RG-New-CDNeast-1 VNet1 -n FrontEnd -a 10.0.2.0/24
azure network public-ip create RG-New-CDNeast-1 publicip -l "eastus"
azure network nic create RG-New-CDNeast-1 NIC-1 -k frontend -m VNet1 -p publicip -l "eastus"

 

image

 

image

 

image

 

image

 

image

 

Now that our environment is created we will deploy a new VM using the template we created in the last post.  However, we do need the you'll need the Id of the NIC we created in the last command we ran above.  if this is still on your screen copy it.  if you closed/cleared the terminal screen already you can get it back with the following command:

 
azure network nic show RG-New-CDNeast-1 NIC-1

In my case the ID is:

 

 
/subscriptions/54a522b6-6cd7-4325-b4e6-566f9d921835/resourceGroups/RG-New-CDNeast-1/providers/Microsoft.Network/networkInterfaces/NIC-1

 

Create a new deployment of our template.

 

now that the environment is setup, we can use one command to deploy a new VM using our template. (note:  I moved the template to a different machine and path from the last post)

 

 
azure group deployment create RG-New-CDNeast-1 newlinuxvm -f "C:\Users\pierrer\OneDrive - Pierre Roman\blog\template.json"

the command will prompt you for a VM name, an administrator account name, with it’s password and the NIC ID.  You copied it right??

After a bit the command will complete.

image

 

Here we are.  A new VM has been created.  And because this is a JSON template you can modify it  to fit your needs.  For example, if you wanted to change the VM size you would have to edit the template VMSize section.

image

 

I hope this helps,

Cheers! Signature

Pierre Roman
@pierreroman

Comments

  • Anonymous
    February 14, 2017
    Hi, Good post. Contains easy steps to follow up