Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


  Search this Thread
Old 07-30-2005, 10:12 AM   #1
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


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


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

Rep: Reputation: 68
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
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
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.

Old 07-31-2005, 11:33 AM   #4
Registered: Nov 2003
Distribution: slackware 14
Posts: 539

Rep: Reputation: 30
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 @

Hope this helps
Old 07-31-2005, 01:12 PM   #5
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.

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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 05:06 PM.

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