8

I have three webcams on my Ubuntu server 14.04. The output of lsusb:

Bus 006 Device 002: ID 0bda:8153 Realtek Semiconductor Corp.
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 003: ID 2537:1066
Bus 004 Device 002: ID 05e3:0616 Genesys Logic, Inc.
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 005: ID 1871:0101 Aveo Technology Corp. UVC camera (Bresser microscope)
Bus 003 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 003 Device 003: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 003 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 005: ID 046d:0807 Logitech, Inc. Webcam B500
Bus 001 Device 004: ID 1871:0101 Aveo Technology Corp. UVC camera (Bresser microscope)
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I want to assign a specific /dev/video# to each one. I have read that I have to create a udev rule in /etc/udev/rules.d/, but most of what I've read seems outdated and I don't want to cause problems to my server. I was thinking of creating a 25-name-video-devices.rules containing the following:

SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="1871", SYSFS{idProduct}=="0101", NAME="video10"
SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="1871", SYSFS{idProduct}=="0101", NAME="video11"
SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="046d", SYSFS{idProduct}=="0807", NAME="video12"

The additional problem I have is that 2 of the 3 webcams seem identical (although they are not, they are bought from ebay and they are used to monitor a different area). So what would be the rules for my case? Thanks

7

Solution without Udev Rules

There is a chance that video4linux has already provided you with stable device names. You may want to check the directories /dev/v4l/by-id/ and /dev/v4l/by-path/ for this. Connect your devices to different USB ports and compare the created device names to make sure that they are really stable.

Solution with Udev Rules

Otherwise it depends on whether your two seemingly identical devices do at least have a different serial number which is accessible by udev. You can find this out by using the correct “Bus” and “Device” number from your lsusb output in the following command:

udevadm info --attribute-walk /dev/bus/usb/003/005

If there is some kind of output like the following in the first block of key/value pairs and the serial is different between the two devices, then you may use that in your udev rules:

ATTR{serial}=="68974689267119892"

Your udev rules could then look like this:

SUBSYSTEM=="usb", ATTR{serial}=="68974689267119892", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video10"
SUBSYSTEM=="usb", ATTR{serial}=="12345698798725654", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video11"
SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="0807", NAME="video12"

If there is no serial (or similar unique) number, then I only see the following possibility: you would have to make sure that your devices always remain connected at the same USB ports. In that case you could use rules like these:

SUBSYSTEM=="usb", KERNEL=="2-3", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video10"
SUBSYSTEM=="usb", KERNEL=="2-4", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video11"
SUBSYSTEM=="usb", KERNEL=="2-2", ATTR{idVendor}=="046d", ATTR{idProduct}=="0807", NAME="video12"

You would have to find out which KERNEL IDs to use by again running the udevadm command mentioned above and looking for the KERNEL key/value pair.

Minor Notes

It may be nicer/better to only create new symlinks instead of new device names, and maybe even grouping them under a common directory:

SUBSYSTEM=="usb", KERNEL=="2-3", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", SYMLINK+="foo/video10"

The previous rule, for example, would create a device symlink at /dev/foo/video10.

I would probably also simply name the rules file name-video-devices.rules, i.e., leaving the leading number out. It probably doesn’t matter when the rules are executed, so no need to use a (rather high) priority of 25.

  • 2
    Correct me if I'm wrong, but it appears that NAME cannot be changed, except in the special case of network devices. From man udev: NAME The name to use for a network interface. The name of a device node cannot be changed by udev, only additional symlinks can be created. From udevadm test <devpath>: NAME="/dev/video99" ignored, kernel device nodes can not be renamed; please fix it in /etc/udev/rules.d/50-blah.rules:5 – Knio Aug 8 '18 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.