LinuxQuestions.org
Help answer threads with 0 replies.
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 10-31-2012, 11:56 AM   #1
srikanth007m
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Rep: Reputation: Disabled
force usb to use same dev id using udev rule


I need some help regarding the usb devices(Android based smartphones), more over i am new to linux. After googling a lot i heard there is trick using udev rule. Does this udev rule solved my problem?

how to create a rule for my below problem. Any help would really helpful..

I am testing some android based mobiles in linux machine. The automation script uses the device id under "/dev/bus/usb/001/"053" it will be always under bus 001 only.. But the dev id will be random like if i insert one mobile then the dev id will be 053, if remove and insert it again then the dev id will be 054..

The problem is, when some tests runs on the device and if device gets rebooted then new dev id is showing for the rebooted one and my scripts failing due to new dev id..

Is there any way to force usb devices to use same dev id instead of new one. So that there will be no issues to my tests even after device reboots.

Thanks in advance.
 
Old 10-31-2012, 06:37 PM   #2
fbianconi
Member
 
Registered: Apr 2008
Location: argentina
Distribution: Arch
Posts: 86

Rep: Reputation: 22
Quote:
Is there any way to force usb devices to use same dev id instead of new one
No, the name of a device node can not be changed by udev, only additional symlinks can be created.

Here is the documentation for writing udev rules, and here and here are OLD guides to all of this.

What you can do is something like this:
1) Make a new file '/etc/udev/rules.d/40-myphone.rules' with the content:
Code:
SUBSYSTEMS=="usb", ATTRS{busnum}=="1",ACTION=="add",SYMLINK+="myphone"
This should make a symbolic link to the device when plugged under /dev/myphone

2) Try unplugging and pugging the phone and check if it worked.
3) If it did then change the automation script to point to "/dev/myphone".

For this case both SUBSYSTEMS=="usb" and ATTRS{busnum}=="1" means something like "/dev/bus/usb/001/*" (except it only matches the highest link_priority one). The bus number will change whenever you switch ports. You can try making a rule using other attribute, just use "udevadm monitor" to get udev events printed to the terminal as they happen, and then use "udevadm info -a -p <device>" for a device name udevadm just spout. ATTRS{idVendor} and ATTRS{idProduct} are very commonly used to match a single device, but a phone might act as many devices depending on the mode it is connected: eg. modem, storage device, flash mode, etc. all of this usually have different idProduct attributes.

Good luck and try not to write over a raw disk partition.

Last edited by fbianconi; 10-31-2012 at 06:46 PM. Reason: guides are old and maybe inaccureate.
 
Old 10-31-2012, 07:06 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Using a different ID type for the filesystem may work.
Select one that is constant such as the UUID of the filesystem.

You may not even need to use udev rules. The KDE devices applet may be enough. The same may be true for Gnome. Also if you use the UUID of the filesystem, it can be used in an fstab entry. The user, uid, gid, noauto, fmask and dmask options will allow you to fix the mount location, ownership and permissions.

On some distros the udev rules have been migrated to polkit and systemd targets. A user ACL is used to grant permission rather than changing the group ownership.

I'd suggest researching how your disto and desktop handle devices now before jumping in and creating udev rules. There may be an easier way that doesn't fight with the system.
 
Old 10-31-2012, 11:11 PM   #4
srikanth007m
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
@fbianconi - Thank you for the detailed info and it'a valuable suggestion for me as a biggner in linux. I'll make a try and let you know the output.. Here i am connecting 14 devices to a linux box. Do i need to append 14 entries to the same rule with corresponding values?

@jschiwal - I am totally new to linux environment. I don't know much about the types of destros and Gnome/kde etc..
 
Old 10-31-2012, 11:12 PM   #5
srikanth007m
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fbianconi View Post
No, the name of a device node can not be changed by udev, only additional symlinks can be created.

Here is the documentation for writing udev rules, and here and here are OLD guides to all of this.

What you can do is something like this:
1) Make a new file '/etc/udev/rules.d/40-myphone.rules' with the content:
Code:
SUBSYSTEMS=="usb", ATTRS{busnum}=="1",ACTION=="add",SYMLINK+="myphone"
This should make a symbolic link to the device when plugged under /dev/myphone

2) Try unplugging and pugging the phone and check if it worked.
3) If it did then change the automation script to point to "/dev/myphone".

For this case both SUBSYSTEMS=="usb" and ATTRS{busnum}=="1" means something like "/dev/bus/usb/001/*" (except it only matches the highest link_priority one). The bus number will change whenever you switch ports. You can try making a rule using other attribute, just use "udevadm monitor" to get udev events printed to the terminal as they happen, and then use "udevadm info -a -p <device>" for a device name udevadm just spout. ATTRS{idVendor} and ATTRS{idProduct} are very commonly used to match a single device, but a phone might act as many devices depending on the mode it is connected: eg. modem, storage device, flash mode, etc. all of this usually have different idProduct attributes.

Good luck and try not to write over a raw disk partition.
Thank you for the detailed info and it'a valuable suggestion for me as a biggner in linux. I'll make a try and let you know the output.. Here i am connecting 14 devices to a linux box. Do i need to append 14 entries to the same rule with corresponding values?
 
Old 11-01-2012, 08:57 AM   #6
srikanth007m
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
fbianconi - When i used the below rule. It was created lots of myphone1/2/3/4/5 etc.. but i want to refer only to /dev/bus/usb/001/XXX.. the symlink is also not point to /dev/bus/usb/001/XXX

SUBSYSTEMS=="usb", ATTRS{busnum}=="1",ACTION=="add",SYMLINK+="myphone%n"
 
Old 11-02-2012, 01:26 AM   #7
fbianconi
Member
 
Registered: Apr 2008
Location: argentina
Distribution: Arch
Posts: 86

Rep: Reputation: 22
Making udev rules is one of the things that you never should have to do, unless you're dealing with experimental hardware and/or software. I don't think we can help you further without you explaining what are you trying to do. Can we see the script you are using?

Quote:
Do i need to append 14 entries to the same rule with corresponding values?
That depends on what you're doing and the rules you write, eg. if you are trying to connect more than one device at the time you might want to look at PROGRAM and %result.
Quote:
When i used the below rule. It was created lots of myphone1/2/3/4/5 etc.. but i want to refer only to /dev/bus/usb/001/XXX..
The numbering should be expected, since you added %n to the symlink string.
Quote:
the symlink is also not point to /dev/bus/usb/001/XXX
Where does it points to?
 
  


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
udev rule to rename /dev/sdx as /dev/sdr does not work :-( on OS 11.2 tkmbe SUSE / openSUSE 2 05-10-2012 01:53 AM
usb detail via udev rule Kashif_Bash Programming 1 04-19-2012 02:05 PM
Is there something similar to a udev rule in solaris express dev. ed. crisostomo_enrico Solaris / OpenSolaris 2 08-17-2007 07:18 AM
what udev rule to create /dev/inet/tcp? bbeers Slackware 2 02-21-2007 04:55 PM
Force USB drive to specific /dev/sd? without udev cb8100 Linux - Hardware 1 01-17-2007 05:51 PM

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

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