Create VM

To create an Microsoft Azure virtual machine:

  • Define a virtual machine
  • Associate the previously created disk with the new virtual machine

Currently there is no way to build a VM using the Microsoft Azure Portal and attach a previously created disk as the operating system disk. See the Command Line tab for details on creating a VM using the command line.

 

Caution

Caution

Ensure that you have run the az disk revoke-access command before creating the disk. Failure to revoke prior access to the disk can cause the VM command to time out, or fail completely due to the disk being unavailable.

  1. Using the az disk list command list the details of available disks.

    az disk list --resource-group <resource-group>

    Where:

    • <resource-group> is the name of the previously created resource group. For example, AccessGateway.

    For example:

    az disk list --resource-group AccessGateway 

    Which will produce results resembling:

    {
    . . .
    "encryptionSettingsCollection": null,"hyperVgeneration": "V1", "id": "/subscriptions/8bc.../resourceGroups/AccessGateway. . ./disks/AG2020-05-00", "location": "eastus",     ... }

  2. Create a VM using the az vm create command:
    az vm create --resource-group <resource-group> --location <region> \\
        --size <size of VM> \\
        --name <name-of-VM> --os-type linux --attach-os-disk <virtual-disk> 

    Where:
    • <region> is the region to hold the VM
    • <size> is the size of the VM. See az vm list-skus --location <region> --output table for a list of available sizes.
    • <name-of-vm> is an name for the VM
    • <virtual-disk> is the name of the virtual disk to associate with the VM
    • <resource-group> is the name of the previously created resource group to house the VM

    For example:

    az vm create --resource-group AccessGateway --location eastus \
        --name AccessGateway.5.0 --os-type linux \
        --attach-os-disk AccessGateway-2020.5.0 -size Standard_D2s_v3

    Which will produce results similar to:

    {- Finished ..
    "fqdns": "",
    "id": "/subscriptions/508555fa. . . /resourceGroups/AccessGateway/providers/Microsoft.Compute/virtualMachines/OAG5.0VM",
    "location": "eastus",
    "macAddress": "00-0D-3A-0E-9C-C1",
    "powerState": "VM running",
    "privateIpAddress": "10.0.0.5",
    "publicIpAddress": "52.167.120.101",
    "resourceGroup": "AccessGateway",
    "zones": ""
    }							

See Also