Add a Google Coral USB Init Script to an LXC Container
Set up the DFU script
-
Install the DFU utility:
apt install dfu-util -
Create a file called
/var/lib/vz/snippets/coral-init.shwith this content:#!/bin/bashgrant_coral_usb() {# DMC 12-3-24: this does not work with less than 666echo "Granting access to Coral so it can be accessed inside container" | tee -a /var/log/coral-init.logchmod 666 $(lsusb | grep 18d1:9302 | sed -nr 's|Bus (.*) Device ([^:]*):.*|/dev/bus/usb/\1/\2|p')}if [ "$2" = "pre-start" ]; thenecho "Running pre-start hookscript for VM $1" > /var/log/coral-init.loglsusb | grep 18d1:9302 > /dev/nullif [ $? -eq 0 ]; thenecho "Google Coral TPU already intialized!" | tee -a /var/log/coral-init.loggrant_coral_usbexit 0filsusb | grep 1a6e:089a > /dev/nullif [ $? -ne 0 ]; thenecho -e "Didn't detect uninitialized Google Coral TPU:\n$(lsusb)" | tee -a /var/log/coral-init.logexit 1fiecho "Initializing coral..." | tee -a /var/log/vm-pre-start.logdfu-util -D /var/lib/vz/snippets/coral-bin/apex_latest_single_ep.bin -d "1a6e:089a" -Rif [ $? -ne 251 ]; thenecho "Error occured!" | tee -a /var/log/coral-init.logexit 2fisleep 2 # pause to allow usb to settlegrant_coral_usbecho -e "Done! USBs:\n$(lsusb)" | tee -a /var/log/coral-init.logfi -
Make it executable:
chmod 744 coral-init.sh -
Create the folder
/var/lib/vz/snippets/coral-bin. -
Download the firmware:
wget https://github.com/google-coral/libedgetpu/raw/master/driver/usb/apex_latest_single_ep.bin -
Add the script to the LXC config by running:
pct set 109 -hookscript local:snippets/coral-init.sh
Add a udev rule (probably not needed)
This was tried but may not actually be necessary — kept here for reference in case a future setup needs it.
Current version:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a6e", ATTRS{idProduct}=="089a", MODE="0664", TAG+="uaccess", SYMLINK+="usbedgetpu"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="9302", MODE="0664", TAG+="uaccess", SYMLINK+="usbedgetpu"
Old version:
SUBSYSTEM=="usb",ATTRS{idVendor}=="1a6e",GROUP="plugdev"
SUBSYSTEM=="usb",ATTRS{idVendor}=="18d1",GROUP="plugdev"