Azure IoT Edge on Raspberry Pi Buster

This article is a “tips and tricks” for running Azure IoT Edge on Raspberry Pi. Plus Raspberry Pi 4 Tips for cooling, USB 3, and Docker.

Azure IoT Edge on Raspberry Pi Buster plus tips for Raspberry Pi 4

Useful References

Raspberry Pi 4

If you are anything like me, then you too couldn’t resist the Raspberry Pi 4 4GB goodness. I wanted to improve the inference performance of my favourite Machine Learning project – Creating an image recognition solution with Azure IoT Edge and Azure Cognitive Services.

As a rough guide, the inference performance of my Azure Custom Vision model was as follows:

  • Raspberry Pi 4 4GB – 720 Milliseconds
  • Raspberry Pi 3B Plus – 1.2 Seconds
  • Intel Core i5-8250U (Surface Laptop 2) – 230 Milliseconds

Raspbian Buster

With the release of the Raspberry Pi 4 the Raspberry Pi Foundation has moved from Raspbian Stretch to Buster (Debian 10) as the default Linux distribution for all Raspberry Pis. For now, at least, it’s busted a few things. So here are some tips and tricks for running Azure IoT Edge on a Raspberry Pi running Raspbian Buster.

Installing Raspbian Buster

This article is not intended as a guide to getting started with Raspberry Pi or Azure IoT Edge. For more information on those topics then read the following articles.

Azure IoT Edge on Raspbian Buster

Raspberry Pi 4 Tips

  • Cooling your Raspberry Pi 4
  • Booting your Raspberry Pi 4 from USB 3 Flash or SSD drive

Azure IoT Edge and Raspbian Buster Tips

  • Installing Docker on Raspbian Buster
  • Installing Azure IoT Edge on Raspbian Buster

Cooling your Raspberry Pi 4

The Raspberry Pi 4 runs hot and you will likely need to provide some active cooling to prevent thermal throttling.

I like the Pimoroni case and Fan SHIM, it is a nice compact solution. Note, I have no affiliation with Pimoroni, I’m just a fan (pun intended). There are other cool solutions for Raspberry Pi 4 too. Check out the Raspberry Pi 4 Thermals and Fan Shim article.

Install the Fan SHIM Software

Check out the Getting Started with Fan SHIM article. In summary, install git and pip3 support, clone the Fan SHIM GitHub repo, install the dependencies, and then set up the automatic temperature monitor service that turns the fan on as required.

sudo apt install -y git sudo python3-pip && \
git clone https://github.com/pimoroni/fanshim-python && \
cd fanshim-python && \
sudo ./install.sh && \
cd examples && \
sudo ./install-service.sh --on-threshold 65 --off-threshold 55 --delay 2

Booting from a USB 3 Flash or SSD Drive

The benefit of booting from USB 3 depends on how disk IO intensive your Azure IoT Edge Solution is. The Raspberry Pi 4 introduces vastly improved USB support and disk IO performance is impressive when combined with a USB 3 SSD drive. Check out the USB 3 Flash and SSD Disk Performance numbers I recorded.

You can’t directly boot from USB 3 (yet), but you can boot from sd-card and then load the Operating System from USB.

In summary, create the boot sd-card as usual, then copy the OS files to the USB 3 drive, tweak the /boot/cmdline.txt to load the Operating System from the USB 3 drive. For step by step instructions follow the notes at How to Run Raspberry Pi 4 or 3 Off an SSD or Flash Drive

  • Plug in your USB 3 drive, then list your drives. If you only plugged in one USB drive then it’s highly likely your drive with be /dev/sda.
sudo fdisk -l
  • Delete existing partitions and create a new primary partition on the USB drive.
sudo fdisk /dev/sda
  
fdisk commands 
- p = print partitions
- d = delete a partition
- n = new partition - create a primary partition
- w = write the partition information to disk
  • Format the newly created partition
sudo mkfs.ext4 /dev/sda1
  • Create a mount point, mount the USB 3 drive, copy the Operating System files to the USB drive, and amend the cmdline.txt to enable booting from the USB 3 drive
sudo mkdir /media/usbdrive && \
sudo mount /dev/sda1 /media/usbdrive && \
sudo rsync -avx / /media/usbdrive && \
sudo sed -i '$s/$/ root=\/dev\/sda1 rootfstype=ext4 rootwait/' /boot/cmdline.txt
  • Reboot the Raspberry Pi
sudo reboot

Installing Docker on Raspbian Buster

The Azure IoT Edge recommended container runtime is the Moby based engine. For now, Moby doesn’t install on Buster, so instead, install Docker-ce.

You need to download the latest versions of containerd.iodocker-ce-cli, and docker-ce from Docker (armhf) on Buster.

An easy way to download the files to the Raspberry Pi is from your browser right mouse click the file and copy the link address and then in an SSH session to the Raspberry Pi wget each file.

wget https://download.docker.com/linux/debian/dists/buster/pool/stable/armhf/containerd.io_<LATEST VERSION>_armhf.deb
  
wget https://download.docker.com/linux/debian/dists/buster/pool/stable/armhf/docker-ce-cli_<LATEST VERSION>~debian-buster_armhf.deb
  
wget https://download.docker.com/linux/debian/dists/buster/pool/stable/armhf/docker-ce_<LATEST VERSION>~debian-buster_armhf.deb

Install the debian packages in the same order you downloaded, add the current user to the docker group, and reboot.

sudo dpkg -i containerd.io* && \
sudo dpkg -i docker-ce-cli* && \
sudo dpkg -i docker-ce_* && \
sudo usermod -aG docker $USER && \
sudo reboot

Installing Azure IoT Edge on Raspbian Buster

Review how to Install the Azure IoT Edge runtime on Debian-based Linux systems.

SSL Library libssl1.0.2

Buster does not ship with the require libssl1.0.2 library. As an interim workaround install this library before installing IoT Edge.

sudo apt-get install libssl1.0.2
  
  
curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list && \
sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/ && \
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpgsudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/ && \
sudo apt-get update && \sudo apt-get -y install iotedge

Add IoT Edge Connection String

sudo nano /etc/iotedge/config.yaml

Restart Azure IoT Edge

sudo systemctl restart iotedge

SSH Authentication with private/public keys

Setting up public/private keys for SSH login and authentication is very handy (and secure).

The following creates a new SSH key, copies the public key to the Raspberry Pi. Take the default options.

From Windows

  • Use the built-in Windows 10 (1809+) OpenSSH client. First install the OpenSSH Client for Windows (one time only operation).
    From PowerShell as Administrator.
Add-WindowsCapability -Online -Name OpenSSH.Client
  • From PowerShell, create a key pair.
ssh-keygen -t rsa
  • From PowerShell, copy the public key to your Raspberry Pi
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"

From Linux, macOS, and the Windows Subsystem for Linux

  • Create your key. Typically a one time operation.
ssh-keygen -t rsa
  • Copy the public key to your Raspberry Pi. From Linux and macOS.
ssh-copy-id [email protected]

Tools

Torrent Tool for Windows (fastest way to download Raspbian Images)

USB 3 Flash and SSD Disk Performance

For reference, these are performance stats I recorded for various drives using the performance tool found at Raspberry Pi Storage Benchmarks 2019

SD Card SanDisk Ultra 16GB

     Category                  Test                      ResultHDParm                    Disk Read                 40.22 MB/sHDParm                    Cached Disk Read          39.47 MB/sDD                        Disk Write                17.8 MB/sFIO                       4k random read            2614 IOPS (10457 KB/s)FIO                       4k random write           296 IOPS (1186 KB/s)IOZone                    4k read                   8669 KB/sIOZone                    4k write                  2808 KB/sIOZone                    4k random read            8609 KB/sIOZone                    4k random write           1480 KB/s                          Score: 923

PNY 128

     Category                  Test                      ResultHDParm                    Disk Read                 98.99 MB/sHDParm                    Cached Disk Read          70.08 MB/sDD                        Disk Write                21.6 MB/sFIO                       4k random read            2238 IOPS (8953 KB/s)FIO                       4k random write           116 IOPS (464 KB/s)IOZone                    4k read                   16067 KB/sIOZone                    4k write                  2204 KB/sIOZone                    4k random read            7747 KB/sIOZone                    4k random write           461 KB/s                          Score: 860

SanDisk Ultra 64 GB

     Category                  Test                      ResultHDParm                    Disk Read                 551.09 MB/sHDParm                    Cached Disk Read          77.30 MB/sDD                        Disk Write                55.0 MB/sFIO                       4k random read            994 IOPS (3976 KB/s)FIO                       4k random write           312 IOPS (1250 KB/s)IOZone                    4k read                   17479 KB/sIOZone                    4k write                  1616 KB/sIOZone                    4k random read            4052 KB/sIOZone                    4k random write           1005 KB/s                          Score: 1087

ASMT – Model: 1153 – USB 3 SSD

     Category                  Test                      ResultHDParm                    Disk Read                 297.42 MB/sHDParm                    Cached Disk Read          264.49 MB/sDD                        Disk Write                69.0 MB/sFIO                       4k random read            15019 IOPS (60076 KB/s)FIO                       4k random write           8239 IOPS (32957 KB/s)IOZone                    4k read                   36059 KB/sIOZone                    4k write                  27480 KB/sIOZone                    4k random read            20925 KB/sIOZone                    4k random write           33354 KB/s                          Score: 6939

Source: Azure IoT Edge on Raspberry Pi Buster

Scroll to Top
Read previous post:
Arduino-Controller-for-Automated-360°-Product-Photography
Arduino Controller for Automated 360° Product Photography

Let's build an arduino based controller that controls a steppermotor and a camera shutter. Together with a steppermotor driven turntable, this...

Close