LinuxQuestions.org
Review your favorite Linux distribution.
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 09-05-2008, 11:37 AM   #1
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Rep: Reputation: 32
assigning permanent device nodes to video devices?


Hi all,

I have two video devices in my system, a webcam and a TV card. Sometimes the first is /dev/video0, sometimes the second is, depending for example on whether the webcam is plugged in.

Is it possible to assign a permanent device node to a given device, such as you can do with udev rules?

Searching a few months ago with Google, I thought I found the answer, but now I am unable to.

Thanks.
 
Old 09-06-2008, 08:02 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
1. Go to the /sys directory and find your devices in a subdirectory (I usually look under 'class') for example:

cd /sys/class/video4linux
ls
radio0 vbi0 video0

Now I look at information on 'video0':
udevinfo -a -p ${PWD}/video0

looking at device '/class/video4linux/video0':
KERNEL=="video0"
SUBSYSTEM=="video4linux"
DRIVER==""
ATTR{name}=="cx88_0_ video _Hauppauge WinTV-"
ATTR{dev}=="81:0"
(and a lot more info that I don't need to post)

In my case the "ATTR{name}" is enough to identify my video device, so I can make a udev rule that looks like this:

ATTR{name}=="cx88_0_ video _Hauppauge WinTV-", NAME="v4l/video0"

Be careful with clashes with existing rules:
cd /etc/udev
fgrep -r "v4l" *
fgrep -r "video" *

You may want to comment out a generic rule like:
KERNEL=="video[0-9]*", NAME="v4l/%k"

and create your own rules file that looks something like this:
ATTR{name}=="cx88_0_ video _Hauppauge WinTV-", NAME="v4l/video0", GOTO="video_naming_end"
ATTR{name}=="mywebcam", NAME="v4l/video1", GOTO="video_naming_end"
KERNEL=="video[0-9]*", NAME="v4l/%k"
LABEL="video_naming_end"

That set of rules will skip the default naming done by "KERNEL==" if the device matches either of the previous two.

You may also need to force udev to update its rules:
/etc/init.d/udev reload
 
Old 09-06-2008, 08:51 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
More about udev rules:

http://reactivated.net/writing_udev_rules.html
 
Old 09-08-2008, 06:02 AM   #4
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Original Poster
Rep: Reputation: 32
Thanks pinniped, that info was extremely helpful.
 
Old 09-08-2008, 04:10 PM   #5
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Re-editing udev rules has its own disadvantages. One is a device node may not be able to create. When your distribution updates udev, your custom udev rules may not work. In these distributions you have to create or use file that your distributor recommends on using for creating custom udev rules.

The best route to take is to specify video_nr or something similar as a module option if video capture devices uses different modules. It will set each device to a device node number every time the computer boots up or the module is reloaded.
 
Old 09-08-2008, 11:36 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Sometimes, you need a device to always be called the same. Udev reads rules from /etc/udev/rules.d/, it reads all the files there, ordering them lexically (the numbers in front of their name is a convenient and more human readable way to make emphasis on that), so as long as you create a file called 99-something and the name doesn't match this of a previously existing file, you shouldn't have problems when updating.

Udev updates do not happen everyday either.

This makes it possible to have custom automount scripts for my external drives without the need for ugly stuff like ivman, which just gives trouble (and no, I don't use mainstream desktops either, whatever they use to automount nowadays).
 
Old 09-09-2008, 03:41 AM   #7
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Mint, Ubuntu server, FreeBSD, Android
Posts: 362

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by i92guboj View Post
Udev reads rules from /etc/udev/rules.d/, it reads all the files there, ordering them lexically (the numbers in front of their name is a convenient and more human readable way to make emphasis on that), so as long as you create a file called 99-something and the name doesn't match this of a previously existing file, you shouldn't have problems when updating.
Should one's custom rulesets be loaded first or last? At the moment, mine is called with 09-local.rules, which I think places it first. 99- is already taken in my distro by 99-fuse.rules
 
Old 09-09-2008, 05:13 PM   #8
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
I do not recommend editing udev rules because each distributions require you to use a certain file to create custom rules. I strongly recommend you add something similar of the following lines to either a file in /etc/modules.d, /etc/modules.conf, or a similar file depending on your distribution.

options module_name video_nr=X

This is the easiest way and preferred way than just messing around in udev scripts to change the device node for each card. The X designates the device node number. The value 0 will be the first card and 1 will be the second card.

What pinniped and i92guboj have provided is informative, but may not work in all cases. Again each distribution may require you to use a certain file to store your custom udev rules. For example in Gentoo /etc/udev/rules.d/XX-local.rules is used to hold custom udev rules and the X designates the priority that udev loads first to last.

I recommend use udev to help you make symbolic links to a certain device node. If my Hauppauge PVR-250 is assigned at /dev/video0, and I want it name to something else, I would add code to make udev create a symbolic link named hauppaugepvr250_XX or hauppaugepvrtwofiftyXX or hauppaugepvr250 that points to /dev/video0.
 
  


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
error while assigning mobile nodes in ns-2 hari_mj23 Linux - Networking 2 02-16-2021 05:08 AM
How do you detect device nodes with C? sebajo Programming 1 06-19-2007 12:42 PM
Mounting usb devices under 2.4.x kernels - /dev nodes and mountpoints alienDog Linux - General 0 10-28-2005 08:29 AM
assigning raw devices: error when going to init3 GlennsPref Mandriva 1 11-25-2004 09:03 PM
Device nodes zoomzoom Linux - General 0 08-18-2003 08:00 AM

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

All times are GMT -5. The time now is 07:48 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