Add udev rules to configuration

Hi

I am trying to add udev rules to config.json and make it available as a configuration variable. I have tried to follow this guide, but I can’t get it to work: Advanced boot settings - Balena Documentation

I have done the following:

  1. Created a USB stick with the balena OS image
  2. Added the udev rules to config.json on the USB stick. This is what I have added:
  "os": {
    "udevRules": {
      "48": "SUBSYSTEMS==\"usb\", ENV{.LOCAL_ifNum}=\"$attr{bInterfaceNumber}\"",
      "49": "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"0403\", ATTRS{idProduct}==\"6011\", SYMLINK+=\"ttyFTDI%E{.LOCAL_ifNum}\""
    }
  }
  1. Flashed my device
  2. Confirmed that /mnt/boot/config.json looks as expected
  3. Confirmed my udev rules are working
  4. I expected (based on the documentation) that my changes would show up as a new configuration variable. This is what the documentation is saying:

Any values added to config.txt will be added to the balenaCloud API during device provisioning and displayed on the dashboard.

I see no new configuration variables in the dashboard, so my question is what I am missing.

I want to have my udev rules on the dashboard, so it will be easy to update it on a deployed fleet if needed.

Hi, unfortunately in this case the docs are incorrect and the udev rules are not shown in the dashboard.

I will create an issue so the docs are corrected with a more specific description of what is displayed. Would you like to recommend that the udev rules are displayed? I can submit it as a suggested product improvement.

Hi

What I want to achieve is that my udev rules can be deployed - and updated at a later point if needed, without having to go into the terminal on each device.

It is fine by me if this is done in the configuration variables, but if it somehow can be added to the docker-compose.yml, then that would also be a solution (not sure if that is feasible).

Please guide me in how to manage this.

Thanks

Hi,

You can set udev rules from a service container by using a balenalib base image, and doing the following:

  1. Save your udev rules into a .rules file (e.g. 48-usb.rules) and include a build step in your Dockerfile that copies the file into the /etc/udev/rules.d/ path of your service.
  2. Add privileged: true to your container’s service definition on the docker-compose.yml file
  3. Add ENV UDEV=on to your container’s Dockerfile.

You may read more about how the balenalib base images works with dynamically plugged devices here: Balena base images - Balena Documentation

You can also find an example in the docs showing how to mount an external USB drive using udev rules here: Communicate outside the container - Balena Documentation

You should be able to use the same approach to set udev rules for your devices from within the service and update those rules as you update the services for the fleet.

Let us know if this works for you.

Cheers,
Carlo