LXC container and attach USB devices

For those who do want to use a USB z-wave controller on a TO, be aware that it’s devicename can change during reboots. I use the following hotplug script (on the TO) to ensure the USB device always has the same name, in this case: /dev/zwave (the code is poorly written, but it works):

cat > /etc/hotplug.d/usb/10-usb_hotplug <<EOF
# logger -t DEBUG "hotplug usb: action='\$ACTION' product='\$PRODUCT' type='\$TYPE' interface='\$INTERFACE'"
# logger -t DEBUG "hotplug usb: devicename='\$DEVICENAME' devname='\$DEVNAME' devpath='\$DEVPATH'"

  case "\$ACTION" in
  add)
    case "\$PRODUCT" in

    658/200/*)
      logger -t DEBUG "hotplug usb: Z-wave.me ZME_UZB1 has been connected!"

#     DEVICE_NAME=\$(ls /sys/\$DEVPATH | grep ttyA)
      DEVICE_NAME=\$(ls /dev | grep ttyACM*)
      logger -t DEBUG "hotplug usb: DEVICE_NAME='\$DEVICE_NAME'"

      if [ -z \${DEVICE_NAME} ];
           then logger -t DEBUG "hotplug usb: Warning DEVICE_NAME is empty"
           exit
      fi

      chmod a+rw /dev/\$DEVICE_NAME
      ln -sf /dev/\$DEVICE_NAME /dev/zwave
      logger -t DEBUG "hotplug usb: Symlink from /dev/\$DEVICE_NAME to /dev/zwave created"
    ;;
    esac
    ;;

  remove)
    case "\$PRODUCT" in

    658/200/*)
      logger -t DEBUG "hotplug usb: Z-wave.me ZME_UZB1 has been removed!"
      logger -t DEBUG "hotplug usb: Symlink from /dev/\$DEVICE_NAME to /dev/zwave destroyed"
    ;;
    esac
    ;;
  esac

EOF

Please note the text ‘658/200’, (found via lsusb) above, and ‘c 166’ (found via: ls -al /dev/tty*) below.

I note also you needed opkg install kmod-usb-serial-ftdi (for a RFXTRX433E), where I required opkg install kmod-usb-acm (for a zwave.me ZME-UZB1).

If you’re using LXC, I expose that USB device to LXC via:

if ! grep -q zwave /srv/lxc/${LXC_NAME}/config; then
    cat >> /srv/lxc/${LXC_NAME}/config << EOF
# for lsusb in LXC-Container, fix error message "unable to initialize libusb: -99"
lxc.mount.entry = /dev/bus/usb  dev/bus/usb  none  bind,optional,create=dir  0 0

# Setup USB passthrough for Z-Wave.me ZME-UZB1, with permissions a+rw (umask=000)
lxc.cgroup.devices.allow = c 166:* rwm
lxc.mount.entry = /dev/zwave  dev/zwave  none  bind,optional,create=file,umask=000  0 0
EOF
fi;

Some of this code has been shamelessly copied from elsewhere, and I am sorry for not being able to provide attributions - however the following were relevant;

1 Like