LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-30-2005, 10:12 AM   #1
malo_umoran
Member
 
Registered: Dec 2003
Distribution: Desktop: Slackware 13.1 &13.37 | Server: Debian 6.0
Posts: 270

Rep: Reputation: 32
which device in /dev is mapped to an USB device


Hi,

How can I find which device (example: /dev/sda) is mapped to an USB device?

I can find it dmesg, but is there a file in /proc or in /sys which shows something like:

Bus 003 Device 059: ID 0781:5151 => /dev/sda

Thanks

M.
 
Old 07-30-2005, 07:14 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
The usbfs filesystem is usually mounted on /proc/bus/usb (although you may need to mount this yourself). If contains a file called devices that tells you a lot about USB devices on your system, but it doesn't tell you /dev device names.

Actually, the filenames in /dev are purely arbitrary; what matters are the major and minor device IDs — which you can see by
Code:
ls -l /dev/file
You could potentially have multiple files per device, if they each have the same numbers. Unfortunately, these numbers aren't listed in the devices file either, although they are listed in /usr/src/linux/Documentation/devices.txt

I think the device number can be found in a file like /sys/class/usb_host/usb1/device/usb1/1-1/devnum (although I'm not entirely certain is this is a major or minor device number, or something else entirely).

Hope that's of some help,

— Robert J. Lee
 
Old 07-31-2005, 10:29 AM   #3
malo_umoran
Member
 
Registered: Dec 2003
Distribution: Desktop: Slackware 13.1 &13.37 | Server: Debian 6.0
Posts: 270

Original Poster
Rep: Reputation: 32
thanks for the information.

I already knew these things, but I had no success in finding out the device.

for example, my UBS stick is mostly /dev/sda, but sometimes it is /dev/sdb without any obvious reason for me.

M.
 
Old 07-31-2005, 11:33 AM   #4
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 15
Posts: 546

Rep: Reputation: 43
Hi,
device nodes are managed by hotplug/udev (assuming you're using 2.6 series kernel)
This system,basically, creates a device node just for devices that are actually connected. The name of the nodes is given chonologically. In other words if you plug in two removable devices (ie a camera as first and a pendrive then) that will use the same bus type, they will have respectively assigned the sda1 and sdb1 nodes.
In order they have assigned always the same device node name (as it will be just a symlink) you should edit your
/etc/udev/rules.d/ directory adding a file called 01-udev.rules containing a line like
BUS="scsi", KERNEL="sd[a-z][0-9]", NAME="%k", SYSFS{model}="JUMPDRIVE ", SYSFS{vendor}="LEXAR ", SYMLINK="pendrive"

those parameters can be obtained by the command
udevinfo -a -p `udevinfo -q path -n /dev/sda1`

Some useful suggestions can be found @
/usr/doc/udev-050/docs/writing_udev_rules

Hope this helps
ciao
 
Old 07-31-2005, 01:12 PM   #5
malo_umoran
Member
 
Registered: Dec 2003
Distribution: Desktop: Slackware 13.1 &13.37 | Server: Debian 6.0
Posts: 270

Original Poster
Rep: Reputation: 32
thanks, it helped ...

I knew about UDEV, but I didn't have any special rules about /dev/sd* devices, so I ignored it. But I got it now ...


If someone needs it:

I want my hotplug scripts to be able to recognize which device in /dev/ they got. /etc/hotplug/usb.agent delivers global variable $DEVPATH to every script.

so if I need to find out device name in a script, I can use $DEVPATH to find it. I use this only for "usb-storage" (block) device, but it can probably be used for other devices also.


when hotplug runs my_usb_script in /etc/hotplug/usb/, I should be able to find the device name with $DEVPATH.

Code:
sleep 5
USB_DEVICE=`udevinfo -as | grep -B 4 "$DEVPATH" | grep /sys/block | sed -re "s/^DEVPATH\s+'\/sys\/block\/(.*)'/\/dev\/\1/"`
USB_DEVICE is now /dev/sda or /dev/sdb or /dev/sdc... I had to put "sleep 5" before this, because hotplug/udev needs a litle bit to make a device etc.


I have USB-stick with a openssl key for a encrypted partition (dm-crypt). now when I put USB-stick in an USB slot, zenity asks me for a password in a popup windows and my encrypted partiton gets mounted. when I pull it out, the partition is again encrypted and umounted.

M.
 
  


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
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 07:32 AM
Block device /dev/sda3 is not a valid root device.. rincewind Linux - Hardware 7 06-09-2006 04:47 AM
Failed to open device /dev/usb/ttyUSB0: No such device efm Linux - Newbie 2 04-04-2005 08:46 PM
loop: can't open device /dev/loop0: No such device or address miaviator278 Linux - Security 3 06-09-2004 09:24 PM
/dev location or name of USB device dark_forests Linux - Hardware 3 10-12-2003 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:59 AM.

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