Edit

Share via


Create Azure Local virtual machines enabled by Azure Arc

Applies to: Hyperconverged deployments of Azure Local

This article describes how to create Azure Local virtual machines (VMs) enabled by Azure Arc, starting with the VM images that you created on your Azure Local instance. You can create Azure Local VMs by using the Azure CLI, the Azure portal, or an Azure Resource Manager template (ARM template).

About Azure Local resources

Use the Azure Local resource page for the following operations:

  • Create and manage Azure Local VM resources such as VM images, disks, and network interfaces.
  • View and access the Azure Arc resource bridge and custom location associated with the Azure Local instance.
  • Provision and manage VMs.

The procedure to create VMs is described later in this article.

Prerequisites

Before you create an Azure Local VM, make sure that you meet the following prerequisites.

Create Azure Local VMs

To create a VM on your Azure Local instance, follow these steps.

Note

  • Two DVD drives are created and used in Azure Local VMs during VM provisioning. The ISO files used during provisioning are removed after you successfully create the VM. However, you might see the empty drives visible for the VM.
  • To delete these drives in a Windows VM, use Device Manager to uninstall the drives. Depending on the flavor of Linux that you use, you can also delete them for Linux VMs.

Follow these steps on the client by running the az cli command that's connected to your Azure Local instance.

Sign in and set the subscription

  1. Connect to a machine on your Azure Local instance.

  2. Sign in and enter the following command:

    az login --use-device-code
    
  3. Set your subscription.

    az account set --subscription <Subscription ID>
    

Create a Windows VM

Depending on the type of network interface that you created, you can create a VM that has a network interface with a static IP or one with a dynamic IP allocation.

If you need more than one network interface with a static IP for your VM, create one or more interfaces now before you create the VM. Adding a network interface with a static IP after the VM is provisioned isn't supported.

Now create a VM that uses specific memory and processor counts on a specified storage path.

  1. Set some parameters:

    $vmName ="local-vm"
    $subscription =  "<Subscription ID>"
    $resource_group = "local-rg"
    $customLocationName = "local-cl"
    $customLocationID ="/subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.ExtendedLocation/customLocations/$customLocationName"
    $location = "eastus"
    $computerName = "mycomputer"
    $userName = "local-user"
    $password = "<Password for the VM>"
    $imageName ="ws22server"
    $nicName ="local-vnic" 
    $storagePathName = "local-sp" 
    $storagePathId = "/subscriptions/<Subscription ID>/resourceGroups/local-rg/providers/Microsoft.AzureStackHCI/storagecontainers/local-sp" 
    

    The parameters for VM creation are listed in the following table.

    Parameters Description
    name Name for the VM that you create for your Azure Local instance. Make sure to provide a name that follows the rules for Azure resources.
    admin-username Username for the user on the VM that you're deploying on your Azure Local instance.
    admin-password Password for the user on the VM that you're deploying on your Azure Local instance.
    image-name Name of the VM image used to provision the VM.
    location Azure regions as specified by the az locations parameter. For example, they could be eastus or westeurope.
    resource-group Name of the resource group where you create the VM. For ease of management, we recommend that you use the same resource group as your Azure Local instance.
    subscription Name or ID of the subscription where your Azure Local instance is deployed. This name or ID could be another subscription that you use for the VM on your Azure Local instance.
    custom-location Use this parameter to provide the custom location associated with your Azure Local instance where you create this VM.
    authentication-type Type of authentication to use with the VM. The accepted values are all, password, and ssh. The default is the password for Windows and the Secure Shell (SSH) public key for Linux. Use all to enable both ssh and password authentication.
    nics Names or the IDs of the network interfaces associated with your VM. You must have at least one network interface when you create a VM to enable guest management.
    memory-mb Memory in megabytes allocated to your VM. If not specified, defaults are used.
    processors The number of processors allocated to your VM. If not specified, defaults are used.
    storage-path-id The associated storage path where the VM configuration and the data are saved.
    proxy-configuration Use this optional parameter to configure a proxy server for your VM. For more information, see Create a VM with proxy configured.
  2. Run the following commands to create the applicable VM:

    • To create a Trusted launch Azure Local VM:

      1. Specify more flags to enable secure boot, enable virtual Trusted Platform Module (vTPM), and choose the security type. When you specify that security type as TrustedLaunch, you must enable secure boot and vTPM. Otherwise, TrustedLaunch VM creation fails.

        az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --enable-secure-boot true --enable-vtpm true --security-type "TrustedLaunch"
        
      2. After the VM is created, verify that the security type of the VM is TrustedLaunch.

      3. Run the following cmdlet (on one of the cluster nodes) to find the owner node of the VM:

        Get-ClusterGroup $vmName
        
      4. Run the following cmdlet on the owner node of the VM:

        (Get-VM $vmName).GuestStateIsolationType
        
      5. Ensure that a value of TrustedLaunch is returned.

    • To create a standard Azure Local VM:

       az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId 
      
    • To create a VM with dynamic memory:

      1. Specify more flags to create a VM with dynamic memory:

        --hardware-profile vm-size="Custom" processors=1 memory-mb=1024 maximum-memory-mb=2048 minimum-memory-mb=1024 target-memory-buffer=20

      2. Note that minimum-memory-mb is less than or equal to memory-mb, and maximum-memory-mb is greater than or equal to memory-mb.

      Sample script:

      az stack-hci-vm create --name "my_dynmemory" -g "my_registration" --admin-username "admin" --admin-password "" --custom-location "/subscriptions/my_subscription/resourceGroups/my_registration/providers/Microsoft.ExtendedLocation/customLocations/my_customlocation" --location "eastus2euap" --image "/subscriptions/my_subscription/resourceGroups/my_registration/microsoft.azurestackhci/marketplacegalleryimages/2022-datacenter-azure-edition-core-01" --hardware-profile vm-size="Custom" processors=1 memory-mb=1024 maximum-memory-mb=2048 minimum-memory-mb=1024 target-memory-buffer=20 --enable-agent true --nics "dynnic"
      

The VM is successfully created when the provisioningState parameter appears as succeeded in the output.

Note

The VM created has guest management enabled by default. If for any reason guest management fails during VM creation, follow the steps in Enable guest management on the Azure Local VM to enable it after the VM creation.

In this example, the storage path was specified by using the --storage-path-id flag. That flag ensures that the workload data (including the VM, VM image, and non-OS data disk) is placed in the specified storage path.

If the flag isn't specified, the workload (VM, VM image, and non-OS data disk) is automatically placed in a high-availability storage path.

Additional parameters for Windows Server 2012 and Windows Server 2012 R2 images

When you create a VM by using Windows Server 2012 and Windows Server 2012 R2 images, specify the following parameters to create the VM:

  • --enable-agent: Set this parameter to true to onboard the Azure Connected Machine Agent on VMs.
  • --enable-vm-config-agent: Set this parameter to false to prevent the onboarding of the VM agent on the VM from the host via the Hyper-V sockets channel. Windows Server 2012 and Windows Server 2012 R2 don't support Hyper-V sockets. In the newer image versions that support Hyper-V sockets, the VM agent is used to onboard the Azure Connected Machine Agent on VMs. For more information on Hyper-V sockets, see Make your own integration services.

Create a Linux VM

To create a Linux VM, use the same command that you used to create the Windows VM:

  • The gallery image you specify must be a Linux image.
  • The username and password you use must work with the authentication-type-all parameter.
  • For SSH keys, you must pass the ssh-key-values parameters along with the authentication-type-all.

Important

Setting the proxy server during VM creation is supported for Ubuntu Server VMs.

Create VM with proxy configured

Use the optional parameter proxy-configuration to configure a proxy server for your VM.

Proxy configuration for VMs is applied only to the onboarding of the Azure Connected Machine Agent and set as environment variables within the guest VM operating system. Browsers and applications on the VM referencing WinInet and netsh aren't necessarily all enabled with this proxy configuration. The WinInet and netsh parameters should be configured with the proxy settings separately.

You might need to specifically set the proxy configuration for your applications if they don't reference the environment variables set within the VM.

If you create a VM behind a proxy server, run the following command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="<Http URL of proxy server>" https_proxy="<Https URL of proxy server>" no_proxy="<URLs which bypass proxy>" cert_file_path="<Certificate file path for your machine>"

Use the following parameters for proxy-server-configuration.

Parameters Description
http_proxy HTTP URLs for the proxy server. An example URL is http://proxy.example.com:3128.
https_proxy HTTPS URLs for the proxy server. The server might still use an HTTP address, as shown in this example: http://proxy.example.com:3128.
no_proxy URLs, which can bypass that proxy. Typical examples are localhost, 127.0.0.1, .svc, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, and 100.0.0.0/8.
cert_file_path Select the certificate file used to establish trust with your proxy server. An example is C:\Users\Palomino\proxycert.crt.

Sample command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" https_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" no_proxy="localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8,s-cluster.test.contoso.com" cert_file_path="C:\ClusterStorage\UserStorage_1\server.crt"

For proxy authentication, you can pass the username and password combined in a URL, as shown in this example: "http://username:password@proxyserver.contoso.com:3128".

Create a VM with the Azure Arc gateway configured

Configure the Azure Arc gateway to reduce the number of required endpoints that are needed to provision and manage Azure Local VMs with the Azure Connected Machine Agent. Certain VM extensions can use the Azure Arc gateway to route all Azure Arc traffic from your VM through a single gateway.

For the most up-to-date list of VM extensions that are enabled through the Azure Arc gateway, see Simplify network configuration requirements with Azure Arc gateway.

To configure an Azure Arc gateway for your Azure Local VM, create a VM with guest management enabled and pass the optional --gateway-id parameter. You can use the Azure Arc gateway with or without proxy configuration. By default, only the Azure Arc traffic is redirected through the Azure Arc proxy.

If your VM applications or services are reaching the Azure endpoint, configure the proxy inside the VM to use the Azure Arc proxy. For applications that don't reference the environment variables set within the VMs, specify a proxy as needed.

Important

Traffic intended for endpoints not managed by the Azure Arc gateway is routed through the enterprise proxy or firewall.

For Windows VMs, allow the following endpoints: https://agentserviceapi.guestconfiguration.azure.com and https://<azurelocalregion>-gas.guestconfiguration.azure.com.

For Linux VMs, allow the following endpoints: https://agentserviceapi.guestconfiguration.azure.com, https://<azurelocalregion>-gas.guestconfiguration.azure.com, and https://packages.microsoft.com.

Create a VM with the Azure Arc gateway enabled behind a proxy server

Run the following command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --gateway-id $gw --proxy-configuration http_proxy="<Http URL of proxy server>" https_proxy="<Https URL of proxy server>" no_proxy="<URLs which bypass proxy>" cert_file_path="<Certificate file path for your machine>"

You can use the following parameters for proxy-server-configuration with Arc gateway.

Parameters Description
gateway-id Resource ID of your Azure Arc gateway. A gateway resource ID example is /subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.HybridCompute/gateways/$gwid.
http_proxy HTTP URLs for the proxy server. An example URL is http://proxy.example.com:3128.
https_proxy HTTPS URLs for the proxy server. The server might still use an HTTP address, as shown in this example: http://proxy.example.com:3128.
no_proxy URLs, which can bypass the proxy. Typical examples are localhost, 127.0.0.1, .svc, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, and 100.0.0.0/8.

Sample command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --gateway-id $gw --proxy-configuration http_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" https_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" no_proxy="localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8,s-cluster.test.contoso.com" 

Create a VM with the Azure Arc gateway enabled without the proxy server

Run the following command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --gateway-id $gw

You can use the following parameters for the Azure Arc gateway.

Parameters Description
gateway-id Resource ID of your Azure Arc gateway. A gateway resource ID example is /subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.HybridCompute/gateways/$gwid.

Sample command:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --gateway-id $gw 

Use managed identity to authenticate Azure Local VMs

When the VMs are created on your Azure Local instance via the Azure CLI or the Azure portal, a system-assigned managed identity is also created that lasts for the lifetime of the VMs.

The VMs on your Azure Local instance are extended from Azure Arc-enabled servers and can use system-assigned managed identity to access other Azure resources that support authentication based on Microsoft Entra ID. For example, the VMs can use a system-assigned managed identity to access Azure Key Vault.

For more information, see System-assigned managed identities and Authenticate against Azure resources with Azure Arc-enabled servers.