[TriLUG] finding udev renamed flashkeys

Rodney Radford rradford at mindspring.com
Sun Apr 12 23:12:53 EDT 2009


Not a complete solution, but an observation that should get you to the solution with a bit of scripting.

This is what I get from 'mount':

   /dev/sdc1 on /media/disk type vfat (rw,nosuid,nodev,uhelper=hal,shortname=mixed,uid=1000,utf8,umask=077,flush)

This is what I get from 'lsusb':

   $ lsusb
   Bus 002 Device 003: ID 0781:5406 SanDisk Corp. Cruzer Micro 1/4GB Flash Drive

I think your question is how can I map sdc1 to the above usb device - right?

So checking the /sys/devices directory tree for sdc, we see:

   $ find /sys/devices -name sdc
   /sys/devices/pci0000:00/0000:00:1d.1/usb2/2-2/2-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc

So now we know that sdc is a USB device (usb2 in the path), but how do we know it is the correct usb device (I only had one usb device, but you could possibly have many mounted).

Take a look at the files:

   $ cat /sys/devices/pci0000:00/0000:00:1d.1/usb2/2-2/idProduct
   5406
   $ cat /sys/devices/pci0000:00/0000:00:1d.1/usb2/2-2/idVendor
   0781

This is the same product and vendor id we saw from lsusb.

So it seems like you could use walk the /sys/devices tree to find the correct sd* device, and then check the idProduct and idVendor to find one that matches the device you want.

Does that help you in the right direction?


-----Original Message-----
>From: Joseph Mack NA3T <jmack at wm7d.net>
>Sent: Apr 12, 2009 10:41 PM
>To: Triangle Linux Users Group General Discussion <trilug at trilug.org>
>Subject: Re: [TriLUG] finding udev renamed flashkeys
>
>On Sun, 12 Apr 2009, Matt Pusateri wrote:
>
>(and Kevin Hunter)
>
>> I would expect when you plugged it in, that you would see it show up in dmesg 
>> or in syslog.
>
>yes, it appears as /dev/sda*
>
>
>> lsusb should show you the device information that you could 
>> use to put it in udev rules show it shows up in the same 
>> place every time.
>
>I have working udev rules and eg one key shows up as 
>/dev/pny* just fine and in /etc/mtab as /dev/pny*, which is 
>what I want (usb harddrives appear as /dev/backup* etc). 
>However in /proc/partitions or /proc/diskstats it's 
>/dev/sda*. I'm logging disk read/writes etc through 
>/proc/diskstates, so I want to know which usb drive is
>plugged in, rather than the arbitary sd[a..z]* device.
>
>While dmesg is fine for watching the device being plugged 
>in, it doesn't help in 2hrs when a script is trying to 
>figure out which external devices are doing what disk 
>activity.
>
>lsusb doesn't tell me anything about the scsi device 
>(/dev/pny* or /dev/sda*)
>
>systool doesn't help either (AFAICT)
>
>
>Thanks Joe
>
>-- 
>Joseph Mack NA3T EME(B,D), FM05lw North Carolina
>jmack (at) wm7d (dot) net - azimuthal equidistant map
>generator at http://www.wm7d.net/azproj.shtml
>Homepage http://www.austintek.com/ It's GNU/Linux!
>--
>TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
>TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions




More information about the TriLUG mailing list