Trouble Setting udev Rules Inside a Container Using Most Recent Method

Hey all,

Apologies in advance if this topic has already been covered. I can’t find any posts about udev issues since PR #1206 has been merged in though.

Balena Info:

  • Host OS Version: balenaOS 2.29.2+rev3
  • Supervisor Version: 9.0.1
  • Device type: CTI Spacely TX2 (BETA)
  • Using Ubuntu 16.04 as the base of the container
  • Running a single container on the device

Here is my issue: I am trying to set specific device rules inside the solo container that is running. I just can’t seem to find the right way to do it. I have followed what seem like the most recent steps in this PR: PR1209 (that I believe has been merged into master at this point), but I can’t seem to get the rules to run.

Here is my exact workflow:

  • Download .img file from Balena Cloud
  • Download config file from Balena Cloud
  • Add udev rules to the config file under os/udevRules as specified in the steps in PR1209
  • Update .img using the command balena os configure my_image.img --app my_ap_name --config ./my_config.json --version 2.29.2
  • Burn image to SD card using Balena Etcher
  • Flash to device

The device flashes just fine, but my udev rules still are not seeming to take effect. When I run balena config read --type spacely-tx2 to read the config from the SD card I don’t see any os related keys. This leads me to believe that I am not updating the .img using the config file properly, but I am not sure of anything at this point.

Thanks in advance for anything you all can help with! I love using Balena and this is really the first issue that has stumped me. I appreciate whatever you can do.


I have just tried to copy what you are attempting to do and it appears to not work like that.
Reading through the docs I am not quite sure if balena os configure is meant to be used the way you are using it. The --config option is documented as follows:

--config <config>                      path to the config JSON file, see `balena os build-config` 

The output of balena os build-config is not actually a config.json but some meta-format as far as I see and adding the os/usedvRules section does not lead to the above command adding them. Unfortunately it fails silently so you were lead to believe that it succeeded.

A reliable way to do this would be to modify config.json directly. This can be done in the running os by writing your os/udevRules section to /mnt/boot/config.json or if you want to replicate this to several installations by modifying the image file (this is what balena os build-config does but not in the way you need it).

Please be aware that if you damage the config.json file eg. write invalid json syntax your device will fail to boot. So make sure your file is valid json and valid config.json format.

Changes to /mnt/boot/config.json wil be active after reboot.

The image file can be modified by mounting the image file directly or by burning it to an SD card and then modifying the card (config.json on the first partition).

In linux, modifying the image can be done using kpartx as follows:

sudo kpartx -av <image.file>
# mounts loop devices for each partition in the image, 
# -v will display the create loop devices eg add map loop41p1 (253:0): 0 81920 linear 7:41 8192...
mkdir /tmp/tmpmount
# mount the first partition with the loop device number from the kpartx step.
sudo mount /dev/mapper/loop<XX>p1 /tmp/tmpmount
# now change config.json in /tmp/tmpmount/config,json
nano /tmp/tmpmount/config.json
#  then unmount image
sudo umount /tmp/tmpmount 
sudo kpartx -dv <image.file>

Feel free to contact me if the above does not work for you.

Hey hey. Thanks for all this. It works perfectly! You the best.