UDev for persistent symlink - ashBabu/Utilities GitHub Wiki
Persistent udev Symlink for Cameras.
Example: Intel RealSense D435i on Ubuntu 24.04
- Run
v4l2-ctl --list-devices
Intel(R) RealSense(TM) Depth Ca (usb-0000:00:0d.0-1.2):
/dev/video0
/dev/video1
/dev/video2
/dev/video3
/dev/video4
/dev/video5
/dev/media0
/dev/media1
Integrated_Webcam_HD: Integrate (usb-0000:00:14.0-6):
/dev/video6
/dev/video7
/dev/video8
/dev/video9
/dev/media2
/dev/media3
-
Of these /dev/video*, we dont know which one is the color stream. To identify that, run the following on all of the /dev/video* and look for the 'YUYV' in Pixel Format
-
v4l2-ctl --device=/dev/video4 --all | grep -i 'Format\|Name\|Pixel Format'
Driver name : uvcvideo
Extended Pix Format
Extended Pix Format
Driver name : uvcvideo
Name : Intel(R) RealSense(TM) Depth Ca
Link 0x02000010: from remote pad 0x100000a of entity 'Processing 7' (Video Pixel Formatter): Data, Enabled, Immutable
Format Video Capture:
Pixel Format : 'YUYV' (YUYV 4:2:2)
From the above, we know that /dev/video4
is the color stream from realsense camera
- Get the unique device path (ID_PATH) for the video device:
udevadm info --name=/dev/video4 | grep ID_PATH
orudevadm info -q property -n /dev/video4
Example output:
E: ID_PATH=pci-0000:00:0d.0-usb-0:1.2:1.4
-
Sometimes ID_PATH may not be enough to uniquely identify the device. Then other fields needs to be added in the udev rule
-
Create a udev rule for the RGB stream symlink:
-
sudo nano /etc/udev/rules.d/99-realsense-rgb.rules
-
Add the following line (replace with your ID_PATH):
-
SUBSYSTEM=="video4linux", ENV{ID_PATH}=="platform-0000:00:0d.0-usb-0:1.2:1.4", SYMLINK+="realsense-rgb”
-
Reload udev rules and trigger:
-
sudo udevadm control --reload-rules
-
sudo udevadm trigger
-
Verify the symlink:
-
ls -l /dev/realsense-rgb
Should point to the correct /dev/video4 device -
Use in OpenCV:
cap = cv2.VideoCapture('/dev/realsense-rgb')
Tips:
- If symlink does not appear, unplug and replug the USB or reboot.
- Repeat for other streams (depth, IR) using their respective /dev/video* and ID_PATH.
- Always verify device formats with v4l2-ctl.
OR
Add udev rules on host to avoid permission issues for USB devices
- Plug in the USB device
- Run
lsusb
which would showBus 001 Device 005: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
- In the above
10c4 --> idVendor
andea60 --> idProduct
- Or use
udevadm info --name=/dev/ttyUSB0 --attribute-walk
. Example output would look like
looking at device '/devices/.../ttyUSB0':
KERNEL=="ttyUSB0"
ATTRS{idVendor}=="10c4"
ATTRS{idProduct}=="ea60"
sudo nano /etc/udev/rules.d/99-usb-lidar.rules
and add the followingSUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE="0666", SYMLINK+="lidar"
sudo udevadm control --reload-rules && sudo udevadm trigger
ls -l /dev/lidar
and it should showlrwxrwxrwx 1 root root 7 Month xx hr:min /dev/lidar -> ttyUSB0
- Run the docker with
-v /dev/lidar:/dev/lidar
- The above method is more robust but for testing, you could run the docker with
--device=/dev/ttyUSB0:/dev/ttyUSB0