|
| 1 | +--- |
| 2 | +title: Run Azure IoT Edge on Ubuntu Virtual Machines by using Bicep | Microsoft Docs |
| 3 | +description: Azure IoT Edge setup instructions for Ubuntu LTS Virtual Machines by using Bicep |
| 4 | +author: toolboc |
| 5 | +ms.service: iot-edge |
| 6 | +services: iot-edge |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 08/29/2022 |
| 9 | +ms.author: pdecarlo |
| 10 | + |
| 11 | +--- |
| 12 | +# Run Azure IoT Edge on Ubuntu Virtual Machines by using Bicep |
| 13 | + |
| 14 | +[!INCLUDE [iot-edge-version-201806-or-202011](../../includes/iot-edge-version-201806-or-202011.md)] |
| 15 | + |
| 16 | +The Azure IoT Edge runtime is what turns a device into an IoT Edge device. The runtime can be deployed on devices as small as a Raspberry Pi or as large as an industrial server. Once a device is configured with the IoT Edge runtime, you can start deploying business logic to it from the cloud. |
| 17 | + |
| 18 | +To learn more about how the IoT Edge runtime works and what components are included, see [Understand the Azure IoT Edge runtime and its architecture](iot-edge-runtime.md). |
| 19 | + |
| 20 | +:::moniker range="iotedge-2018-06" |
| 21 | +This article lists the steps to deploy an Ubuntu 18.04 LTS virtual machine with the Azure IoT Edge runtime installed and configured using a pre-supplied device connection string. The deployment is accomplished using a [cloud-init](../virtual-machines/linux/using-cloud-init.md) based [Bicep file](../azure-resource-manager/bicep/overview.md) maintained in the [iotedge-vm-deploy](https://github.com/Azure/iotedge-vm-deploy/tree/1.1) project repository. |
| 22 | + |
| 23 | +On first boot, the virtual machine [installs the latest version of the Azure IoT Edge runtime via cloud-init](https://github.com/Azure/iotedge-vm-deploy/blob/1.1/cloud-init.txt). It also sets a supplied connection string before the runtime starts, allowing you to easily configure and connect the IoT Edge device without the need to start an SSH or remote desktop session. |
| 24 | +:::moniker-end |
| 25 | +:::moniker range=">=iotedge-2020-11" |
| 26 | +This article lists the steps to deploy an Ubuntu 20.04 LTS virtual machine with the Azure IoT Edge runtime installed and configured using a pre-supplied device connection string. The deployment is accomplished using a [cloud-init](../virtual-machines/linux/using-cloud-init.md) based [Bicep file](../azure-resource-manager/bicep/overview.md) maintained in the [iotedge-vm-deploy](https://github.com/Azure/iotedge-vm-deploy/tree/1.3) project repository. |
| 27 | + |
| 28 | +On first boot, the virtual machine [installs the latest version of the Azure IoT Edge runtime via cloud-init](https://github.com/Azure/iotedge-vm-deploy/blob/1.3/cloud-init.txt). It also sets a supplied connection string before the runtime starts, allowing you to easily configure and connect the IoT Edge device without the need to start an SSH or remote desktop session. |
| 29 | +:::moniker-end |
| 30 | + |
| 31 | +## Deploy from Azure CLI |
| 32 | + |
| 33 | +You can't deploy a remote Bicep file. Save a copy of the [Bicep file](https://raw.githubusercontent.com/Azure/iotedge-vm-deploy/master/edgeDeploy.bicep) locally as **main.bicep**. |
| 34 | + |
| 35 | +1. Ensure that you have installed the Azure CLI iot extension with: |
| 36 | + |
| 37 | + ```azurecli |
| 38 | + az extension add --name azure-iot |
| 39 | + ``` |
| 40 | + |
| 41 | +1. Next, if you're using Azure CLI on your desktop, start by logging in: |
| 42 | + |
| 43 | + ```azurecli |
| 44 | + az login |
| 45 | + ``` |
| 46 | + |
| 47 | +1. If you have multiple subscriptions, select the subscription you'd like to use: |
| 48 | + 1. List your subscriptions: |
| 49 | + |
| 50 | + ```azurecli |
| 51 | + az account list --output table |
| 52 | + ``` |
| 53 | +
|
| 54 | + 1. Copy the SubscriptionID field for the subscription you'd like to use. |
| 55 | +
|
| 56 | + 1. Set your working subscription with the ID that you copied: |
| 57 | +
|
| 58 | + ```azurecli |
| 59 | + az account set -s <SubscriptionId> |
| 60 | + ``` |
| 61 | +
|
| 62 | +1. Create a new resource group (or specify an existing one in the next steps): |
| 63 | +
|
| 64 | + ```azurecli |
| 65 | + az group create --name IoTEdgeResources --location westus2 |
| 66 | + ``` |
| 67 | + |
| 68 | +1. Create a new virtual machine: |
| 69 | + :::moniker range="iotedge-2018-06" |
| 70 | + To use an **authenticationType** of `password`, see the example below: |
| 71 | + |
| 72 | + ```azurecli |
| 73 | + az deployment group create \ |
| 74 | + --resource-group IoTEdgeResources \ |
| 75 | + --template-file "main.bicep" \ |
| 76 | + --parameters dnsLabelPrefix='my-edge-vm1' \ |
| 77 | + --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ |
| 78 | + --parameters authenticationType='password' \ |
| 79 | + --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ |
| 80 | + --parameters adminPasswordOrKey="<REPLACE_WITH_SECRET_PASSWORD>" |
| 81 | + ``` |
| 82 | + |
| 83 | + To authenticate with an SSH key, you may do so by specifying an **authenticationType** of `sshPublicKey`, then provide the value of the SSH key in the **adminPasswordOrKey** parameter. An example is shown below. |
| 84 | + |
| 85 | + ```azurecli |
| 86 | + #Generate the SSH Key |
| 87 | + ssh-keygen -m PEM -t rsa -b 4096 -q -f ~/.ssh/iotedge-vm-key -N "" |
| 88 | +
|
| 89 | + #Create a VM using the iotedge-vm-deploy script |
| 90 | + az deployment group create \ |
| 91 | + --resource-group IoTEdgeResources \ |
| 92 | + --template-file "main.bicep" \ |
| 93 | + --parameters dnsLabelPrefix='my-edge-vm1' \ |
| 94 | + --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ |
| 95 | + --parameters authenticationType='sshPublicKey' \ |
| 96 | + --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ |
| 97 | + --parameters adminPasswordOrKey="$(< ~/.ssh/iotedge-vm-key.pub)" |
| 98 | + ``` |
| 99 | + |
| 100 | + :::moniker-end |
| 101 | + :::moniker range=">=iotedge-2020-11" |
| 102 | + To use an **authenticationType** of `password`, see the example below: |
| 103 | + |
| 104 | + ```azurecli |
| 105 | + az deployment group create \ |
| 106 | + --resource-group IoTEdgeResources \ |
| 107 | + --template-file "main.bicep" \ |
| 108 | + --parameters dnsLabelPrefix='my-edge-vm1' \ |
| 109 | + --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ |
| 110 | + --parameters authenticationType='password' \ |
| 111 | + --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ |
| 112 | + --parameters adminPasswordOrKey="<REPLACE_WITH_SECRET_PASSWORD>" |
| 113 | + ``` |
| 114 | + |
| 115 | + To authenticate with an SSH key, you may do so by specifying an **authenticationType** of `sshPublicKey`, then provide the value of the SSH key in the **adminPasswordOrKey** parameter. An example is shown below. |
| 116 | + |
| 117 | + ```azurecli |
| 118 | + #Generate the SSH Key |
| 119 | + ssh-keygen -m PEM -t rsa -b 4096 -q -f ~/.ssh/iotedge-vm-key -N "" |
| 120 | +
|
| 121 | + #Create a VM using the iotedge-vm-deploy script |
| 122 | + az deployment group create \ |
| 123 | + --resource-group IoTEdgeResources \ |
| 124 | + --template-file "main.bicep" \ |
| 125 | + --parameters dnsLabelPrefix='my-edge-vm1' \ |
| 126 | + --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ |
| 127 | + --parameters authenticationType='sshPublicKey' \ |
| 128 | + --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ |
| 129 | + --parameters adminPasswordOrKey="$(< ~/.ssh/iotedge-vm-key.pub)" |
| 130 | + ``` |
| 131 | + |
| 132 | + :::moniker-end |
| 133 | + |
| 134 | +1. Verify that the deployment has completed successfully. A virtual machine resource should have been deployed into the selected resource group. Take note of the machine name, this should be in the format `vm-0000000000000`. Also, take note of the associated **DNS Name**, which should be in the format `<dnsLabelPrefix>`.`<location>`.cloudapp.azure.com. |
| 135 | + |
| 136 | + The **DNS Name** can be obtained from the JSON-formatted output of the previous step, within the **outputs** section as part of the **public SSH** entry. The value of this entry can be used to SSH into to the newly deployed machine. |
| 137 | + |
| 138 | + ```bash |
| 139 | + "outputs": { |
| 140 | + "public SSH": { |
| 141 | + "type": "String", |
| 142 | + "value": "ssh <adminUsername>@<DNS_Name>" |
| 143 | + } |
| 144 | + } |
| 145 | + ``` |
| 146 | + |
| 147 | + The **DNS Name** can also be obtained from the **Overview** section of the newly deployed virtual machine within the Azure portal. |
| 148 | + |
| 149 | + > [!div class="mx-imgBorder"] |
| 150 | + > [](./media/how-to-install-iot-edge-ubuntuvm/iotedge-vm-dns-name.png) |
| 151 | + |
| 152 | +1. If you want to SSH into this VM after setup, use the associated **DNS Name** with the command: |
| 153 | + `ssh <adminUsername>@<DNS_Name>` |
| 154 | + |
| 155 | +## Next steps |
| 156 | + |
| 157 | +Now that you have an IoT Edge device provisioned with the runtime installed, you can [deploy IoT Edge modules](how-to-deploy-modules-portal.md). |
| 158 | + |
| 159 | +If you are having problems with the IoT Edge runtime installing properly, check out the [troubleshooting](troubleshoot.md) page. |
| 160 | + |
| 161 | +To update an existing installation to the newest version of IoT Edge, see [Update the IoT Edge security daemon and runtime](how-to-update-iot-edge.md). |
| 162 | + |
| 163 | +If you'd like to open up ports to access the VM through SSH or other inbound connections, refer to the Azure Virtual Machines documentation on [opening up ports and endpoints to a Linux VM](../virtual-machines/linux/nsg-quickstart.md) |
0 commit comments