LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 05-09-2009, 06:29 AM   #1
rrrssssss
Member
 
Registered: Mar 2005
Posts: 288

Rep: Reputation: 34
Video device nodes swap (video0, video1, video2) [SOLVED]


Hello Linux forum,

I have a problem that is common for most every Linux user and I have been trying for years to find a solution. And it seems to be common for all Linux distributions but I'm using Linux Mint 5 at this time.

I have three PCI capture cards installed and, of course, each one is assigned a device node called video0, video1, and video2. But they randomly swap places on each reboot so that a different device node is assigned for any particular capture card. This means I have to reconfigure my software for the new assignment of the device nodes often.

I have tried unloading the modules and loading them back in the order I want them to appear but that does not work for long. They end up swapping again.

I also have created a 95-perso.rules file in the /etc/udev/rules.d directory to create symlinks for the device nodes that looks like this:
------------------------------------------------------------------------

KERNEL=="video0", ATTR{dev}=="81:0", ATTR{name}=="ivtv0 encoder MPG", ATTRS{device}=="0x0016" ATTRS{vendor}=="0x4444" ATTRS{subsystem_vendor}=="0x0070" ATTRS{subsystem_device}=="0x8801" SYMLINK+="pvr150"

KERNEL=="video1", ATTR{dev}=="81:1", ATTRS{vendor}=="0x14f1" ATTRS{device}=="0x8800" ATTRS{subsystem_vendor}=="0x1002" ATTRS{subsystem_device}=="0x00f8" SYMLINK+="bttv1"

KERNEL=="video2", ATTR{dev}=="81:2", ATTRS{vendor}=="0x3388" ATTRS{device}=="0x0021" SYMLINK+="bttv2"

-----------------------------------------------------------------------

The above rule will indeed form the correct symlinks for each device node as long as they do not swap but they still swap from time to time! Once they swap, no symlink is formed, which is to be expected.

I got the above information for the 95-perso.rules file from the udevinfo command, and in Kubuntu Jaunty I used the udevadm command which is the replacement for udevinfo. I even tried using the python scripts to automatically create the 95-perso.rules file called udev-rules-jaunty.py and udev-rules.py but the files they created needed tweaking before the symlinks were formed and the device nodes still swapped in spite of it all.

Why do my video device nodes still swap upon a reboot of my machine?

Help will be most appreciated,
Roy

Last edited by rrrssssss; 05-14-2009 at 05:54 AM. Reason: clarity
 
Old 05-11-2009, 01:49 AM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by rrrssssss View Post
I also have created a 95-perso.rules file in the /etc/udev/rules.d directory to create symlinks for the device nodes that looks like this:
------------------------------------------------------------------------

KERNEL=="video0", ATTR{dev}=="81:0", ATTR{name}=="ivtv0 encoder MPG", ATTRS{device}=="0x0016" ATTRS{vendor}=="0x4444" ATTRS{subsystem_vendor}=="0x0070" ATTRS{subsystem_device}=="0x8801" SYMLINK+="pvr150"

KERNEL=="video1", ATTR{dev}=="81:1", ATTRS{vendor}=="0x14f1" ATTRS{device}=="0x8800" ATTRS{subsystem_vendor}=="0x1002" ATTRS{subsystem_device}=="0x00f8" SYMLINK+="bttv1"

KERNEL=="video2", ATTR{dev}=="81:2", ATTRS{vendor}=="0x3388" ATTRS{device}=="0x0021" SYMLINK+="bttv2"

-----------------------------------------------------------------------
If you want to use udev rules to have persistent device naming (IMO the preferred solution), you should not specify match variables which can possibly change. The variable KERNEL is the device name the kernel gives udev as it loads the drivers. The dev attribute is closely related, as the minor number is dynamically assigned as the kernel encounters the device. Both these variables may change between kernel versions or even through a race condition in the order in which modules gets loaded (which may differ, especially with an SMP system).

The rest of your ruleset looks ok. If you remove all the KERNEL and ATTR{dev} matches, you will have persistent symlinks (e.g., pvr150 will always point to the physical device named “ivtv0 encoder MPG” regardless of whether it shows up as video0, video1, or video2).

This will work if you are going to use the symlinks in your capture program. Some programs which use these devices, however, will have the video? device names hardcoded (due to programmer negligence). In order to accommodate these, you’ll want to go further and change the actual device name by appending NAME="video0" and so on.
 
Old 05-14-2009, 05:47 AM   #3
rrrssssss
Member
 
Registered: Mar 2005
Posts: 288

Original Poster
Rep: Reputation: 34
Solved

Hello osor,

Thank you for your expertise in this matter. Your recommendation fixed my problem.

If I understand this correctly, it does not matter if the device node swaps to another capture card, just so the symlink never swaps since my software is configured to use the symlink, not the device node. As a matter of fact, the device nodes still swap upon various reboots but it does not matter because the symlinks always point to the proper capture card. The reason the variables (video0, video1, and video2 and dev) can not be included in the mix is because when they do swap, the device nodes no longer match the other entries in each line, resulting in conflicting information so udev can not create the symlink.


What worries me is that there are several topics on this problem on the Internet that say to use video0, video1, or video2, which apparently is bad information.

The python scrips I mentioned use KERNEL=="video*" instead of video0, video1, and video2 but for some reason the symlinks are not formed but that may be because I was not tweaking it right.

Thank you again for coming to my rescue,
Roy

Last edited by rrrssssss; 05-14-2009 at 06:19 AM.
 
Old 05-15-2009, 04:59 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by rrrssssss View Post
If I understand this correctly, it does not matter if the device node swaps to another capture card, just so the symlink never swaps since my software is configured to use the symlink, not the device node. As a matter of fact, the device nodes still swap upon various reboots but it does not matter because the symlinks always point to the proper capture card. The reason the variables (video0, video1, and video2 and dev) can not be included in the mix is because when they do swap, the device nodes no longer match the other entries in each line, resulting in conflicting information so udev can not create the symlink.
Yes, that is a very good explanation. Of course, as I said before, you might want device renaming in addition to device symlinks. In that case, you would put the new device name in a NAME="newname" assignment. This, however, is discouraged in modern udev, since you could just as easily tell your capture software to use the symlinks.
Quote:
Originally Posted by rrrssssss View Post
What worries me is that there are several topics on this problem on the Internet that say to use video0, video1, or video2, which apparently is bad information.
Perhaps they are trying to solve a different problem, where the device nodes stay fixed, but it is hard to remember which is which so you want symlinks. This can happen if you have a single-processor computer which loads the modules sequentially in a specific order (e.g., from /etc/modules), but it is too confusing to remember which number corresponds to which physical device. I admit that this is pretty unlikely.
Quote:
Originally Posted by rrrssssss View Post
The python scrips I mentioned use KERNEL=="video*" instead of video0, video1, and video2 but for some reason the symlinks are not formed but that may be because I was not tweaking it right.
If you use KERNEL=="video*" (or KERNEL=="video?") it should still work, as long as you remove the ATTR{dev} matches. A more elegant match would be to use SUBSYSTEM=="foo"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning permanent device nodes to video devices? Kropotkin Linux - Hardware 7 09-09-2008 05:13 PM
Video0, Video1, Video2 Switch Places During Each Reboot rrrssssss Ubuntu 1 05-03-2007 09:33 PM
/dev/video0: No such device meranto Linux - Hardware 5 11-12-2005 10:38 AM
The ideal way to stream a video from device video0 over the internet? brynjarh Linux - Software 1 01-05-2005 06:46 AM
Two Video Devices - /dev/video0 & /dev/video1 liguorir Linux - Software 1 07-21-2003 08:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration