modprobe: FATAL: Module i2c_dev not found in directory /lib/modules/6.1.35-yocto-standard

Hello,
I am trying to get an i2c device to work on an image, and I’ve already tried the tips in here:

I’ve attached my dockerfile.template, dockerfile-compose.yaml and udev-rules.

What am I getting wrong here? The fatal error (in the title of this post) happens as soon as the installer for daqhats tries to read DAQ HAT EEPROMs over i2c:
[data_kit_srv] make: Leaving directory ‘/usr/src/app/daqhats/examples/c’
[data_kit_srv] Reading DAQ HAT EEPROMs
[data_kit_srv] modprobe: FATAL: Module i2c_dev not found in directory /lib/modules/6.1.35-yocto-standard

I’ve previously had a similar config work with i2c when interfacing with sparkfun-qwiic devices, so I really don’t understand what the root of the issue is here.

Docker compose file:

version: '2'
services:
  data_kit_srv:
    labels:
      io.balena.features.kernel-modules: 1
    build: .
    privileged: true
    # command: modprobe i2c-dev && python3 test
    devices:
      - /dev/i2c-1:/dev/i2c-1
      - /dev/mem:/dev/mem
      - /dev/gpiomem:/dev/gpiomem
    environment:
      - "UDEV=1"
    ports:
      - "5555:5555"
    volumes:
    - /lib/modules:/lib/modules
    cap_add:
    - “ALL”

Dockerfile.template:

FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3.10

# Install any dependencies if required
# RUN apt-get update && apt-get install -y your-dependencies

RUN install_packages git gcc make python3-dev libc-dev
RUN apt-get update && apt-get install -y python3-smbus i2c-tools

WORKDIR usr/src/app

COPY requirements.txt requirements.txt

COPY udev-rules/90-i2c.rules /etc/udev/rules.d/90-i2c.rules

RUN cd ~
RUN git clone https://github.com/mccdaq/daqhats.git
RUN cd daqhats && chmod +x ./install.sh && ./install.sh

RUN pip3 install -r requirements.txt

# Copy all all files in root to the working directory
COPY . ./

#ensure plugged dynamic hardware devices show up in the container
ENV UDEV=1

CMD ["python","-u","src/data_kit_comms.py"]

and 90-i2c.rules:

SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0666"

What type of device are you using?

1 Like

This is on a Raspberry Pi 4, and with BalenaOS 4.0.26, development variant

1 Like

Update: I got around this by deploying a desktop container and running the same commands to clone the git repo and run its install script (which uses the I2C drivers) from here: GitHub - balena-io-examples/balena-ros2-foxy-desktop: An installation of ROS2 Foxy in a container, with a full desktop environment, ready to deploy on balena devices.

However, I tried to modify my own Dockerfile to use the same build
FROM balenalib/aarch64-ubuntu:focal
ARG DEBIAN_FRONTEND=noninteractive

and when I run balena push I see the same problem happen (modprobe: FATAL: Module i2c_dev not found in directory /lib/modules/6.1.35-yocto-standard)

What is the difference between these two methods? What’s the recommended approach here?

Are you using balena push to the balena builders? If so, the install.sh is trying to run there where there is no I2C device. It probably needs to be moved out of the Dockerfile. You would need to create your own tiny start script that runs the install.sh file and then pauses, then runs your data_kit_comms Python script so install.sh runs on your device and not the builder. When you ran it manually in the container successfully, it was on the device, correct? Hopefully I’m understanding your problem/workaround correctly so feel free to provide more details if that’s not the case!