I have two lidars connected to my Jetson on my robot. One is on the front, and one on the back. It is important to keep track of which one is where, but the lidars are connected via some kind of UART bridge onto the USB port. This means that Linux only sees the bridge, not the lidar behind it. The bridges look identical in terms of attributes, so making a udev rule for them is a little trickier than usual.

I can access proper serial numbers from the lidar SDK, which runs in c++. I have made a program which, given a USB port, gives the correct symlink name I wish to have for that lidar. But I am having issues creating the symlink, as I am unsure of how to trigger a udev rule based on some bash script.

Currently, the script path looks like this: udev rule calls my script and passes the device name -> scripts queries sdk for serial number and looks up proper placement -> script adds a new udev rule based on this logic -> script runs udevadm control --reload-rules && udevadm trigger. This creates the correct udev rule, but does not trigger it, and therefor does not create the symlink. If you replug the lidar at this stage, the symlink is created. However, I wish for this process to be more automatic.

What is the proper way to proceed? Does it make sense to create the symlink manually, with ln -s /dev/ttyUSB1 /dev/ttyLIDAR_FRONT or so? Can bash scripts force a udev rule to run, or can udevadm run a rule in cli?


1 Answer 1


There are at least two ways of going about this, without having to create new rules and load them.

  1. Instead of having your script create a new udev rule, make it create the appropriate symlink directly.

    As far as I can tell, all you lose by doing this, instead of having udev create the symlink, is the ability to look for created symlinks in subsequent udev rules, and udev’s link priority management.

  2. Have your script output a variable assignment, and use it in an IMPORT{program} udev rule followed by a symlink creation referring to the variable set by the script.

    This would involve something like having your script output TARGET=symlinkname (ideally with a more specific variable name), and then the SYMLINK creation referring to %E{TARGET}. See the udev manual; there’s also a decent chance you can find examples in existing rules in /lib/udev/rules.d on your system.

  • Thank you. A couple of followups: are there any downsides to creating the symlink myself over doing it in a udev rule? Also, what does it mean for an output to be in "environmental key format", which the IMPORT keyword looks for? Having trouble finding an example.
    – user93114
    Commented Aug 12, 2021 at 11:33
  • See the update, hopefully that’s a bit clearer. Commented Aug 12, 2021 at 11:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .