Frigate + Coral USB + Proxmox

Hello,

This is yet another post explaining how to set up Coral USB on a LXC container. This is based on my findings after fighting this for days and following tutorials that didn’t end up working for my case.

A few notes

  • This tutorial will show how to run Frigate “natively” (i.e. without Docker) in an unprivileged LXC container. To be honest, running it inside Docker may be easier, but I find this way more interesting for learning purposes.
  • I won’t cover Home Assistant integration because I assume you have that already working.
  • This will work after a reboot, where the USB device id can change.

Creating the container

I just used Proxmox VE Helper-Scripts to create the initial container setup. Don’t worry too much about the configuration options, because we’ll going to change them later. Just run the script and you should have a container ready and running, but with CPU detection.

Install Coral USB in the host system

Basically follow this until you have it working.

Prepare the host system

There are a few changes you have to make in the host system.

  1. Create a group with id 10000. By default LXC containers run with uid/gid 10000/10000. Coral USB will not work with the default permissions. Run:

    groupadd -g 100000 lxc-frigate-root
    
  2. Configure udev. By default Coral setup will create /etc/udev/rules.d/71-edgetpu.rules, change it so it looks like this (the important part is to add the GROUP:

    SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", MODE="0664", GROUP="lxc-frigate-root"
    SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", MODE="0664", GROUP="lxc-frigate-root"
    
  3. Restart udev:

    udevadm control --reload-rules && udevadm trigger
    
  4. Verify it is working. First find the bus and device ID of your Coral USB:

    lsusb
    
    Bus 002 Device 005: ID 18d1:9302 Google Inc.
    
  5. Check the permissions for that file in the /dev filesystem:

    ls -la /dev/bus/usb/002/005
    
    crw-rw-r-- 1 root lxc-frigate-root 189, 132 Jul 23 12:09 /dev/bus/usb/002/005
    

    It should belong to group lxc-frigate-root.

Prepare the container

  1. Edit the container config (usually in /etc/pve/lxc/<id>.conf) to add these lines (adjust the path to match your USB bus):

    lxc.mount.entry: /dev/bus/usb dev/bus/usb none bind,create=dir
    lxc.cgroup2.devices.allow: c 189:* rwm
    
  2. Configure frigate to use Coral USB detector. You can use the UI or edit the file /config/config.yaml:

    detectors:
      coral:
        type: edgetpu
        device: usb
    

Verify it works

  1. Start the container with pct start <id>

  2. Open a shell to it with pct enter <id>

  3. Check the USB permissions:

    ls -la /dev/bus/usb/002/005
    crw-rw-r-- 1 nobody root 189, 132 Jul 23 12:25 /dev/bus/usb/002/005
    

    Note that device 005 was mounted, and it belongs to group root. If it belongs to nogroup, then you had the group mapping wrong.

    Do not use lsusb to verify it works. lsusb will list all USB devices of the host (even when run inside the container), even if they are not properly mounted in the container.

  4. Start frigate and check the logs:

    [2024-07-23 12:19:09] frigate.detectors.plugins.edgetpu_tfl INFO    : Attempting to    load TPU as usb
    [2024-07-23 12:19:12] frigate.detectors.plugins.edgetpu_tfl INFO    : TPU found
    

And I think that’s it. I hope you find it useful. Please do let me know if there is a mistake or missing info, I’ll add it.

3 Likes