* [gentoo-user] serial in /sys @ 2012-11-29 17:57 Jorge Almeida 2012-11-29 18:35 ` Marco Bonfiglio ` (3 more replies) 0 siblings, 4 replies; 20+ messages in thread From: Jorge Almeida @ 2012-11-29 17:57 UTC (permalink / raw To: gentoo-user Anyone knows how to dig into /sys to find the serial number of a device (say, a USB pen)? I few days ago I found by trial and error something like $ cat /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/13:0:0:0/block/sdc/../../../../../serial which gave me E68911000519 Now I can't find nothing of the sort. (Yes, I know the path changes each time the device is plugged in, but even so) Any information that would put some order into this mess would be great. TIA Joreg Almeida ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 17:57 [gentoo-user] serial in /sys Jorge Almeida @ 2012-11-29 18:35 ` Marco Bonfiglio 2012-11-29 19:07 ` Jorge Almeida 2012-11-29 19:20 ` Bruce Hill ` (2 subsequent siblings) 3 siblings, 1 reply; 20+ messages in thread From: Marco Bonfiglio @ 2012-11-29 18:35 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 673 bytes --] 2012/11/29 Jorge Almeida <jjalmeida@gmail.com> > Anyone knows how to dig into /sys to find the serial number of a device > (say, > a USB pen)? I few days ago I found by trial and error something like > $ cat > /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/13:0:0:0/block/sdc/../../../../../serial > which gave me E68911000519 > Now I can't find nothing of the sort. (Yes, I know the path changes > each time the > device is plugged in, but even so) > Any information that would put some order into this mess would be great. > > TIA > > Joreg Almeida > > If by "serial" you mean UUID I personally use "ls -l /dev/disk/by-uuid/" Marco Bonfiglio [-- Attachment #2: Type: text/html, Size: 1017 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 18:35 ` Marco Bonfiglio @ 2012-11-29 19:07 ` Jorge Almeida 2012-11-29 22:09 ` Kevin Chadwick 2012-11-30 10:00 ` Neil Bothwick 0 siblings, 2 replies; 20+ messages in thread From: Jorge Almeida @ 2012-11-29 19:07 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 6:35 PM, Marco Bonfiglio <marco.bonfiglio@gmail.com> wrote: > > > 2012/11/29 Jorge Almeida <jjalmeida@gmail.com> >> >> Anyone knows how to dig into /sys to find the serial number of a device >> (say, >> a USB pen)? I few days ago I found by trial and error something like >> $ cat >> /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/13:0:0:0/block/sdc/../../../../../serial >> which gave me E68911000519 >> Now I can't find nothing of the sort. (Yes, I know the path changes >> each time the >> device is plugged in, but even so) >> Any information that would put some order into this mess would be great. >> >> TIA >> >> Joreg Almeida >> > > If by "serial" you mean UUID I personally use "ls -l /dev/disk/by-uuid/" > It is not the same thing, but anyway I have in /dev/disk/by-id/ a symlink usb-silicon_-power_E68911000519-0:0 -> ../../sdd This is indeed the device I meant, and the serial number is the "E68911000519" substring. But this symlink exists because udev created it. I need to somehow dig it out of /sys, not out of /dev. IOW, how did udev retrieved the information to create the symlink? The values of ../by-uuid/ would probably be equally good, but I don't know how to find them any more than I know how to find the serials... Thanks J.A. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 19:07 ` Jorge Almeida @ 2012-11-29 22:09 ` Kevin Chadwick 2012-11-30 10:00 ` Neil Bothwick 1 sibling, 0 replies; 20+ messages in thread From: Kevin Chadwick @ 2012-11-29 22:09 UTC (permalink / raw To: gentoo-user > The values of ../by-uuid/ would probably be > equally good, but I don't know how to find them any more than I know how to > find the serials... I use my own automounter scripts and udev with nice static mountpoints from when udisks threw lots away for a while in favour of multiseat. A recurring theme it seems!!! Incidentally I think I'm having issues accesing a dvd from a chroot due to udisks and possibly due to not following the 'everythings a file' mantra as thoggen falls back to /dev/dvd just fine and k9copy works only in folder mode. Does blkid -U work for you? -- _______________________________________________________________________ 'Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface' (Doug McIlroy) _______________________________________________________________________ ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 19:07 ` Jorge Almeida 2012-11-29 22:09 ` Kevin Chadwick @ 2012-11-30 10:00 ` Neil Bothwick 2012-11-30 12:48 ` Jorge Almeida 1 sibling, 1 reply; 20+ messages in thread From: Neil Bothwick @ 2012-11-30 10:00 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 695 bytes --] On Thu, 29 Nov 2012 19:07:11 +0000, Jorge Almeida wrote: > This is indeed the device I meant, and the serial number is the > "E68911000519" substring. But this symlink exists because udev created > it. I need to somehow dig it out of /sys, not out of /dev. IOW, how did > udev retrieved the information to create the symlink? This is all done in /usr/lib/udev/rules.d/60-persistent-storage.rules ENV{SERIAL} seems to be the key, but udev rules use variables rather than accessing /sys directly. I really like udev as it makes just about anything you want to do easy, it's a shame to watch it getting lost. -- Neil Bothwick Does someone know the cheats for WindowsXP? [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-30 10:00 ` Neil Bothwick @ 2012-11-30 12:48 ` Jorge Almeida 0 siblings, 0 replies; 20+ messages in thread From: Jorge Almeida @ 2012-11-30 12:48 UTC (permalink / raw To: gentoo-user On Fri, Nov 30, 2012 at 10:00 AM, Neil Bothwick <neil@digimed.co.uk> wrote: > On Thu, 29 Nov 2012 19:07:11 +0000, Jorge Almeida wrote: > >> This is indeed the device I meant, and the serial number is the >> "E68911000519" substring. But this symlink exists because udev created >> it. I need to somehow dig it out of /sys, not out of /dev. IOW, how did >> udev retrieved the information to create the symlink? > > This is all done in /usr/lib/udev/rules.d/60-persistent-storage.rules > > ENV{SERIAL} seems to be the key, but udev rules use variables rather than > accessing /sys directly. The point is what sets the variables. I don't think the kernel sets SERIAL, at least it doesn't export it via the hotplug mechanism. Maybe it does it via netlink, but where oh where is the documentation for that? Short of reading the source, which is beyond my skills... > > I really like udev as it makes just about anything you want to do easy, > it's a shame to watch it getting lost. > udev is a good idea, but it was plagued from the very beginning with the syndrome "we know this arcane stuff, you don't need to understand as long as your distro's devs can make it JustWork". Most users don't care, but some do, as this is linux. Cheers Jorge Almeida ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 17:57 [gentoo-user] serial in /sys Jorge Almeida 2012-11-29 18:35 ` Marco Bonfiglio @ 2012-11-29 19:20 ` Bruce Hill 2012-11-29 19:31 ` Jorge Almeida 2012-11-30 0:56 ` James Cloos 2012-11-30 18:02 ` Volker Armin Hemmann 3 siblings, 1 reply; 20+ messages in thread From: Bruce Hill @ 2012-11-29 19:20 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 05:57:46PM +0000, Jorge Almeida wrote: > Anyone knows how to dig into /sys to find the serial number of a device (say, > a USB pen)? I few days ago I found by trial and error something like > $ cat /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/13:0:0:0/block/sdc/../../../../../serial > which gave me E68911000519 > Now I can't find nothing of the sort. (Yes, I know the path changes > each time the > device is plugged in, but even so) > Any information that would put some order into this mess would be great. > > TIA > > Joreg Almeida Why not look in dmesg output: [871998.865035] usb 2-5: new high speed USB device number 4 using ehci_hcd [871998.986925] usb 2-5: New USB device found, idVendor=13fe, idProduct=3600 [871998.986928] usb 2-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [871998.986930] usb 2-5: Product: patriot memory [871998.986931] usb 2-5: Manufacturer: [871998.986932] usb 2-5: SerialNumber: 07B20F01654F84B8 [871998.987237] usb-storage 2-5:1.0: Quirks match for vid 13fe pid 3600: 4000 [871998.987257] scsi15 : usb-storage 2-5:1.0 [872000.021585] scsi 15:0:0:0: Direct-Access patriot memory PMAP PQ: 0 ANSI: 0 CCS [872000.021983] sd 15:0:0:0: Attached scsi generic sg4 type 0 [872001.831285] sd 15:0:0:0: [sdd] 7811072 512-byte logical blocks: (3.99 GB/3.72 GiB) [872001.831776] sd 15:0:0:0: [sdd] Write Protect is off [872001.831779] sd 15:0:0:0: [sdd] Mode Sense: 23 00 00 00 [872001.832263] sd 15:0:0:0: [sdd] No Caching mode page present [872001.832265] sd 15:0:0:0: [sdd] Assuming drive cache: write through [872001.836389] sd 15:0:0:0: [sdd] No Caching mode page present [872001.836392] sd 15:0:0:0: [sdd] Assuming drive cache: write through [872001.870531] sdd: sdd1 [872001.873413] sd 15:0:0:0: [sdd] No Caching mode page present [872001.873415] sd 15:0:0:0: [sdd] Assuming drive cache: write through [872001.873417] sd 15:0:0:0: [sdd] Attached SCSI removable disk -- Happy Penguin Computers >') 126 Fenco Drive ( \ Tupelo, MS 38801 ^^ support@happypenguincomputers.com 662-269-2706 662-205-6424 http://happypenguincomputers.com/ Don't top-post: http://en.wikipedia.org/wiki/Top_post#Top-posting ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 19:20 ` Bruce Hill @ 2012-11-29 19:31 ` Jorge Almeida 2012-11-29 20:20 ` Bruce Hill 2012-11-29 22:35 ` Walter Dnes 0 siblings, 2 replies; 20+ messages in thread From: Jorge Almeida @ 2012-11-29 19:31 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 7:20 PM, Bruce Hill <daddy@happypenguincomputers.com> wrote: > On Thu, Nov 29, 2012 at 05:57:46PM +0000, Jorge Almeida wrote: >> Anyone knows how to dig into /sys to find the serial number of a device (say, >> a USB pen)? I few days ago I found by trial and error something like >> $ cat /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/13:0:0:0/block/sdc/../../../../../serial >> which gave me E68911000519 >> Now I can't find nothing of the sort. (Yes, I know the path changes >> each time the >> device is plugged in, but even so) >> Any information that would put some order into this mess would be great. >> >> TIA >> >> Joreg Almeida > > Why not look in dmesg output: It is a matter of programming, not looking. I need a program that creates the symlink when the device is plugged in. Think mdev (more precisely, a complement to mdev that would take care of a few particular devices, to allow using fstab to mount them in chosen mountpoints, and then leave the rest to mdev). Thanks J.A. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 19:31 ` Jorge Almeida @ 2012-11-29 20:20 ` Bruce Hill 2012-11-29 20:56 ` Jorge Almeida 2012-11-29 22:35 ` Walter Dnes 1 sibling, 1 reply; 20+ messages in thread From: Bruce Hill @ 2012-11-29 20:20 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 07:31:10PM +0000, Jorge Almeida wrote: > > It is a matter of programming, not looking. I need a program that creates the > symlink when the device is plugged in. Think mdev (more precisely, a > complement to mdev that would take care of a few particular devices, to allow > using fstab to mount them in chosen mountpoints, and then leave the > rest to mdev). Have you considered sys-apps/uam ? -- Happy Penguin Computers >') 126 Fenco Drive ( \ Tupelo, MS 38801 ^^ support@happypenguincomputers.com 662-269-2706 662-205-6424 http://happypenguincomputers.com/ Don't top-post: http://en.wikipedia.org/wiki/Top_post#Top-posting ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 20:20 ` Bruce Hill @ 2012-11-29 20:56 ` Jorge Almeida 0 siblings, 0 replies; 20+ messages in thread From: Jorge Almeida @ 2012-11-29 20:56 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 8:20 PM, Bruce Hill <daddy@happypenguincomputers.com> wrote: > On Thu, Nov 29, 2012 at 07:31:10PM +0000, Jorge Almeida wrote: >> >> It is a matter of programming, not looking. I need a program that creates the >> symlink when the device is plugged in. Think mdev (more precisely, a >> complement to mdev that would take care of a few particular devices, to allow >> using fstab to mount them in chosen mountpoints, and then leave the >> rest to mdev). > > Have you considered sys-apps/uam ? > -- Didn't know about it. But it doesn't look promising. It requires udev (which by itself would do what I want) and it's oriented towards automounting, which I don't need nor want. Thanks, J.A. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 19:31 ` Jorge Almeida 2012-11-29 20:20 ` Bruce Hill @ 2012-11-29 22:35 ` Walter Dnes 2012-11-30 0:28 ` Jorge Almeida 1 sibling, 1 reply; 20+ messages in thread From: Walter Dnes @ 2012-11-29 22:35 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 07:31:10PM +0000, Jorge Almeida wrote > It is a matter of programming, not looking. I need a program that > creates the symlink when the device is plugged in. Think mdev > (more precisely, a complement to mdev that would take care of a few > particular devices, to allow using fstab to mount them in chosen > mountpoints, and then leave the rest to mdev). I have a couple of scripts that automount USB devices under mdev. See https://wiki.gentoo.org/wiki/Mdev for the general setup, and https://wiki.gentoo.org/wiki/Mdev/Automount_USB and https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount Once set up, "it just works". If you want to go spelunking through /sys for connected USB devices, here are a few hints. I currently have connected to my machine... * a Dell keyboard * a Logitech trackball mouse * an external USB hard drive * 2 USB keys The output below shows that not every USB device has a serial number, and the "Patriot Memory" key has a serial number but no manufacturer... [d531][waltdnes][~] find /sys/devices/pci0* -name serial | xargs cat 0000:00:1a.0 0000:00:1a.1 0000:00:1a.2 0000:00:1a.7 0000:00:1d.0 0000:00:1d.1 0000:00:1d.2 0000:00:1d.7 00000000000000070493 078215B00E5C 574341565530313435313431 [d531][waltdnes][~] find /sys/devices/pci0* -name manufacturer | xargs cat Linux 3.3.8-gentoo uhci_hcd Linux 3.3.8-gentoo uhci_hcd Dell Linux 3.3.8-gentoo uhci_hcd Logitech Linux 3.3.8-gentoo ehci_hcd Linux 3.3.8-gentoo uhci_hcd Linux 3.3.8-gentoo uhci_hcd Linux 3.3.8-gentoo uhci_hcd Linux 3.3.8-gentoo ehci_hcd SanDisk Corporation Western Digital [d531][waltdnes][~] find /sys/devices/pci0* -name product | xargs cat UHCI Host Controller UHCI Host Controller Dell USB Keyboard 2003 UHCI Host Controller Trackball c404 EHCI Host Controller UHCI Host Controller UHCI Host Controller UHCI Host Controller EHCI Host Controller Cruzer Titanium Patriot Memory My Book 1110 -- Walter Dnes <waltdnes@waltdnes.org> We are apparently better off trying to avoid udev like the plague. Linus Torvalds; 2012/10/03 https://lkml.org/lkml/2012/10/3/349 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 22:35 ` Walter Dnes @ 2012-11-30 0:28 ` Jorge Almeida 2012-11-30 3:09 ` Walter Dnes 0 siblings, 1 reply; 20+ messages in thread From: Jorge Almeida @ 2012-11-30 0:28 UTC (permalink / raw To: gentoo-user On Thu, Nov 29, 2012 at 10:35 PM, Walter Dnes <waltdnes@waltdnes.org> wrote: > On Thu, Nov 29, 2012 at 07:31:10PM +0000, Jorge Almeida wrote > > > I have a couple of scripts that automount USB devices under mdev. See > https://wiki.gentoo.org/wiki/Mdev for the general setup, and > https://wiki.gentoo.org/wiki/Mdev/Automount_USB and > https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount > I don't care for automounting, I just want customized symlinks. Using fstab is not a second choice, it is how I want it. > > The output below shows that not every USB device has a serial number, > and the "Patriot Memory" key has a serial number but no manufacturer... > > [d531][waltdnes][~] find /sys/devices/pci0* -name serial | xargs cat > OK. I found that my pens have serial numbers. I setup /proc/sys/kernel/hotplug with a script that prints the environment. When a pen is inserted, this is what is set: ACTION=add DEVPATH=/devices/pci0000:00/0000:00:04.1/usb1/1-4/1-4:1.0/host12/target12:0:0/12:0:0:0/block/sdd SUBSYSTEM=block MAJOR=8 MINOR=48 DEVNAME=sdd DEVTYPE=disk SEQNUM=1750 Following your suggestion: # find /sys/devices/pci0* -name serial /sys/devices/pci0000:00/0000:00:04.0/usb5/serial /sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/serial /sys/devices/pci0000:00/0000:00:04.1/usb1/serial /sys/devices/pci0000:00/0000:00:06.0/usb6/serial /sys/devices/pci0000:00/0000:00:06.1/usb3/3-4/serial /sys/devices/pci0000:00/0000:00:06.1/usb3/serial /sys/devices/pci0000:00/0000:00:0c.0/0000:02:00.0/0000:03:01.0/0000:04:00.0/usb2/serial /sys/devices/pci0000:00/0000:00:0c.0/0000:02:00.0/0000:03:01.0/0000:04:00.0/usb4/serial # cat /sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/serial AA04012700011287 So, the serial number is here. To retrieve it out of $DEVPATH, I can do (in this case, at least!): # cat /sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/1-4:1.0/host12/target12:0:0/12:0:0:0/block/sdd/../../../../../../serial AA04012700011287 I'm assuming that this scenario is consistent for usb pen drives. I'll think of external hard disks next... BTW, the idea behind this is: -- have s6-devd listen to the netlink interface (http://www.skarnet.org/software/s6-linux-utils/s6-devd.html) -- when a device is inserted, s6-devd launches a program that tries to obtain the serial number, uses it as key to seek a string some_name in a constant database, and creates the symlink /dev/some_name --> $DEVNAME. On failure, exec mdev with the environment passed by the kernel. I'm supposing that the environment on netlink is the same as with the hotplug mechanism. Would this be true? I would be interested in hearing any comments... Thanks Joreg Almeida > > -- > Walter Dnes <waltdnes@waltdnes.org> > We are apparently better off trying to avoid udev like the plague. Precisely. > Linus Torvalds; 2012/10/03 https://lkml.org/lkml/2012/10/3/349 > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-30 0:28 ` Jorge Almeida @ 2012-11-30 3:09 ` Walter Dnes 2012-11-30 9:58 ` Jorge Almeida 0 siblings, 1 reply; 20+ messages in thread From: Walter Dnes @ 2012-11-30 3:09 UTC (permalink / raw To: gentoo-user On Fri, Nov 30, 2012 at 12:28:01AM +0000, Jorge Almeida wrote > When a pen is inserted, this is what is set: > > ACTION=add > DEVPATH=/devices/pci0000:00/0000:00:04.1/usb1/1-4/1-4:1.0/host12/target12:0:0/12:0:0:0/block/sdd > SUBSYSTEM=block > MAJOR=8 > MINOR=48 > DEVNAME=sdd > DEVTYPE=disk > SEQNUM=1750 [...deletia...] > I'm supposing that the environment on netlink is the same as with the hotplug > mechanism. Would this be true? This is almost exactly what I remember from when I was writing/testing/debugging my automount scripts. The one difference I remember is that when mdev handled it, there was no "DEVNAME" variable, but rather it was "MDEV". But otherwise identical. Two important notes... 1) For a USB mass storage device (pen or external hard drive) with N partitions, the hotplug handler will get N+1 events when inserting and also when removing. E.g. if your pen drive has 3 partitions, you'll get 4 events... * one for /dev/sdd * one for /dev/sdd1 * one for /dev/sdd2 * one for /dev/sdd3 2) There is one exception to the above rule. Sometimes, Windows will format an entire pen as one large partition, without a partition table. This requires an ugly hack in my script. If DEVTYPE is "disk", it checks for the string "FAT" in the first 512 bytes of the device (bleagh). Here's an excerpt from my script at https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount ###################################################################### if [ "X${ACTION}" == "Xadd" ] ; then # # Flag for mounting if it's a regular partition if [ "X${DEVTYPE}" == "Xpartition" ] ; then partition=1 ; # # Further checks if DEVTYPE is disk; looking for weird setup where the # entire USB key is formatted as one partition, without the standard # partition table. elif [ "X${DEVTYPE}" == "Xdisk" ] ; then # # If it's "disk", check for string "FAT" in first 512 bytes of device. # Flag as a partition if the string is found. if dd if=${MDEV} bs=512 count=1 2>/dev/null | grep "FAT" 1>/dev/null ; then partition=1 fi fi fi ###################################################################### The important line is... if dd if=${MDEV} bs=512 count=1 2>/dev/null | grep "FAT" 1>/dev/null ; Would you be OK if the devices were always mounted in /media ? The reason I ask is that my scripts use pmount, which can take an optional label argument. E.g. if MDEV is "sdd1" pmount --umask 007 --noatime /dev/${MDEV} would create /media/sdd1 pmount --umask 007 --noatime /dev/${MDEV} my_pendrive_1 would create /media/my_pendrive_1 I always wanted to add that functionality to the scripts, but never got around to it. > BTW, the idea behind this is: > -- have s6-devd listen to the netlink interface > (http://www.skarnet.org/software/s6-linux-utils/s6-devd.html) > > -- when a device is inserted, s6-devd launches a program that tries to > obtain the serial number, uses it as key to seek a string some_name > in a constant database, and creates the symlink /dev/some_name --> > $DEVNAME. On failure, exec mdev with the environment passed by > the kernel. The way I'm thinking of doing it is to... * launch my script (with minor changes) * on an "add" action invoke your program to look for a match * if a match is found, use the optional label, otherwise use the default name in variable MDEV Actually, if I was writing it, I would add a few lines to my script for the "add" ACTION * label=${MDEV} * look for a "serial" file in the PCI path of the newly-inserted device * if found; then grep through a textfile to match the contents of the "serial" file if matched; then label=custom_name if [ ${#MDEV} -gt 3 ]; then label="${label}_${MDEV:3}" fi fi fi pmount --umask 007 --noatime /dev/${MDEV} ${label} -- Walter Dnes <waltdnes@waltdnes.org> We are apparently better off trying to avoid udev like the plague. Linus Torvalds; 2012/10/03 https://lkml.org/lkml/2012/10/3/349 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-30 3:09 ` Walter Dnes @ 2012-11-30 9:58 ` Jorge Almeida 2012-12-01 3:47 ` Walter Dnes 0 siblings, 1 reply; 20+ messages in thread From: Jorge Almeida @ 2012-11-30 9:58 UTC (permalink / raw To: gentoo-user On Fri, Nov 30, 2012 at 3:09 AM, Walter Dnes <waltdnes@waltdnes.org> wrote: > On Fri, Nov 30, 2012 at 12:28:01AM +0000, Jorge Almeida wrote > >> When a pen is inserted, this is what is set: >> >> DEVNAME=sdd > > This is almost exactly what I remember from when I was > writing/testing/debugging my automount scripts. The one difference I > remember is that when mdev handled it, there was no "DEVNAME" variable, > but rather it was "MDEV". But otherwise identical. Two important notes... Strange. The variable name is set by the kernel. Maybe you were using a patched kernel? > > 1) For a USB mass storage device (pen or external hard drive) with N > partitions, the hotplug handler will get N+1 events when inserting and > also when removing. E.g. if your pen drive has 3 partitions, you'll get > 4 events... Right. The helper program is launched 4 times and will create (or remove, depending on $ACTION) 4 symlinks. > > Would you be OK if the devices were always mounted in /media ? The > reason I ask is that my scripts use pmount, which can take an optional > label argument. E.g. if MDEV is "sdd1" > pmount looks a good idea for a many-users workstation. For a 1-user computer, there's no loss of functionality with sticking with fstab. > > Actually, if I was writing it, I would add a few lines to my script > for the "add" ACTION Sure, I just didn't mention it. > * label=${MDEV} > * look for a "serial" file in the PCI path of the newly-inserted device > * if found; then > grep through a textfile to match the contents of the "serial" file I thought of keeping data-- (key,value) = (serial_number, custom_name_of_device)-- in a cdb database. I think it is faster than reading a text file, and no parsing needed. It is also scalable (although this is probably irrelevant on a custom-workstation scale...). My (untested) program is about 11k, statically compiled. By the way, I don't suppose there is a mailing list to talk about these matters (mdev/ udev-alternative/ udev-fork related)? This is really distro-agnostic stuff... Thanks Jorge Almeida ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-30 9:58 ` Jorge Almeida @ 2012-12-01 3:47 ` Walter Dnes 2012-12-01 4:55 ` Joshua Murphy 2012-12-01 9:08 ` Jorge Almeida 0 siblings, 2 replies; 20+ messages in thread From: Walter Dnes @ 2012-12-01 3:47 UTC (permalink / raw To: gentoo-user On Fri, Nov 30, 2012 at 09:58:10AM +0000, Jorge Almeida wrote > On Fri, Nov 30, 2012 at 3:09 AM, Walter Dnes <waltdnes@waltdnes.org> wrote: > > > 1) For a USB mass storage device (pen or external hard drive) with N > > partitions, the hotplug handler will get N+1 events when inserting and > > also when removing. E.g. if your pen drive has 3 partitions, you'll get > > 4 events... > > Right. The helper program is launched 4 times and will create (or remove, > depending on $ACTION) 4 symlinks. In my case, it would be 3 mounts. There's no point in mounting the underlying /dev/sdd, unless it happens to be the weird Windows format where the entire device is a FAT partition, with no partition table. > I thought of keeping data-- (key,value) = (serial_number, > custom_name_of_device)-- in a cdb database. I think it is faster than > reading a text file, and no parsing needed. It is also scalable > (although this is probably irrelevant on a custom-workstation > scale...). My (untested) program is about 11k, statically compiled. Come to think of it, I'd want to make it more general. I'd have my script read through a textfile ("flat-file database") with 3 columns. 1) Attribute; one of "manufacturer", "product", or "serial"; are there any others? 2) Value to match, i.e. manufacturer string, product name, or serial #. 3) The custom name I want my device to have > By the way, I don't suppose there is a mailing list to talk about these > matters (mdev/ udev-alternative/ udev-fork related)? This is really > distro-agnostic stuff... For mdev-related questions, the best place I know of is the busybox mailing list http://lists.busybox.net/mailman/listinfo/busybox mdev is part of busybox. -- Walter Dnes <waltdnes@waltdnes.org> ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-12-01 3:47 ` Walter Dnes @ 2012-12-01 4:55 ` Joshua Murphy 2012-12-01 9:11 ` Jorge Almeida 2012-12-01 9:08 ` Jorge Almeida 1 sibling, 1 reply; 20+ messages in thread From: Joshua Murphy @ 2012-12-01 4:55 UTC (permalink / raw To: gentoo-user On Fri, Nov 30, 2012 at 10:47 PM, Walter Dnes <waltdnes@waltdnes.org> wrote: > On Fri, Nov 30, 2012 at 09:58:10AM +0000, Jorge Almeida wrote >> By the way, I don't suppose there is a mailing list to talk about these >> matters (mdev/ udev-alternative/ udev-fork related)? This is really >> distro-agnostic stuff... > > For mdev-related questions, the best place I know of is the busybox > mailing list http://lists.busybox.net/mailman/listinfo/busybox mdev is > part of busybox. > > -- > Walter Dnes <waltdnes@waltdnes.org> And, while auto-mounting might be a bit beyond the 'official' scope of it, I've seen a fair bit of recent chatter on the LFS mailing lists on the general topic of device management, alongside a bit of grumbling about the kitchen sink approach being taken with systemd/udev/etc. Might be worth glancing through their archives to see if anything on this particular question crops up, and if nothing else, it shouldn't hurt much if you toss the question towards the lfs-chat list. -- Poison [BLX] Joshua M. Murphy ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-12-01 4:55 ` Joshua Murphy @ 2012-12-01 9:11 ` Jorge Almeida 0 siblings, 0 replies; 20+ messages in thread From: Jorge Almeida @ 2012-12-01 9:11 UTC (permalink / raw To: gentoo-user On Sat, Dec 1, 2012 at 4:55 AM, Joshua Murphy <poisonbl@gmail.com> wrote: > On Fri, Nov 30, 2012 at 10:47 PM, Walter Dnes <waltdnes@waltdnes.org> wrote: >> On Fri, Nov 30, 2012 at 09:58:10AM +0000, Jorge Almeida wrote >>> By the way, I don't suppose there is a mailing list to talk about these >>> matters (mdev/ udev-alternative/ udev-fork related)? This is really >>> distro-agnostic stuff... >> >> For mdev-related questions, the best place I know of is the busybox >> mailing list http://lists.busybox.net/mailman/listinfo/busybox mdev is >> part of busybox. > > And, while auto-mounting might be a bit beyond the 'official' scope of > it, I've seen a fair bit of recent chatter on the LFS mailing lists on > the general topic of device management, alongside a bit of grumbling > about the kitchen sink approach being taken with systemd/udev/etc. > Might be worth glancing through their archives to see if anything on > this particular question crops up, and if nothing else, it shouldn't > hurt much if you toss the question towards the lfs-chat list. > I'm subscribed to the lfs lists (I'm not sure about lfs-chat, though) for years. I'll have a look. Thanks Jorge Almeida ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-12-01 3:47 ` Walter Dnes 2012-12-01 4:55 ` Joshua Murphy @ 2012-12-01 9:08 ` Jorge Almeida 1 sibling, 0 replies; 20+ messages in thread From: Jorge Almeida @ 2012-12-01 9:08 UTC (permalink / raw To: gentoo-user On Sat, Dec 1, 2012 at 3:47 AM, Walter Dnes <waltdnes@waltdnes.org> wrote: > On Fri, Nov 30, 2012 at 09:58:10AM +0000, Jorge Almeida wrote >> On Fri, Nov 30, 2012 at 3:09 AM, Walter Dnes <waltdnes@waltdnes.org> wrote: >> > >> I thought of keeping data-- (key,value) = (serial_number, >> custom_name_of_device)-- in a cdb database. I think it is faster than >> reading a text file, and no parsing needed. It is also scalable >> (although this is probably irrelevant on a custom-workstation >> scale...). My (untested) program is about 11k, statically compiled. > > Come to think of it, I'd want to make it more general. I'd have my > script read through a textfile ("flat-file database") with 3 columns. > > 1) Attribute; one of "manufacturer", "product", or "serial"; are there > any others? > I checked that netlink and hotplug export exactly the same variables (well, at least for the devices I tried), but SERIAL is not one of them, one has to dig /sys. But the location of the "serial" file seems to be consistent, so problem solved. > 2) Value to match, i.e. manufacturer string, product name, or serial #. > > 3) The custom name I want my device to have > The problem with that approach is that the code is much less simple, and the program less lean. I don't know what that implies regarding efficiency, but inserting a usb pen with only one partition gives rise to 12 (!) events, and thus the program (and hence mdev) is run 12 times, 10 of which are probably completely useless (but there's no helping that). You could have 3 cdb files, one for each type of key ("manufacturer",...) and have the program seek them sequentially. It would still be very fast (faster?), and less error prone. (I know cdb is not the most widely known type of database, but it really is the appropriate one for this kind of usage--read many times, write once in a blue moon--and it is very easy to deal with. I'm using tinycdb (http://www.corpit.ru/mjt/tinycdb.html) because it provides a library interface.) >> By the way, I don't suppose there is a mailing list to talk about these >> matters (mdev/ udev-alternative/ udev-fork related)? This is really >> distro-agnostic stuff... > > For mdev-related questions, the best place I know of is the busybox > mailing list http://lists.busybox.net/mailman/listinfo/busybox mdev is > part of busybox. > OK, I just feel that mdev-related questions are really somewhat related, for example, with the recent intentions of forking udev (which I hope will be successful). For example, the evdev xorg driver requires udev! Is there a really good reason for this, or is it another way to make udev mandatory? (A bit of paranoia...) I don't know what list would be appropriate to raise this question in. Jorge Almeida ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 17:57 [gentoo-user] serial in /sys Jorge Almeida 2012-11-29 18:35 ` Marco Bonfiglio 2012-11-29 19:20 ` Bruce Hill @ 2012-11-30 0:56 ` James Cloos 2012-11-30 18:02 ` Volker Armin Hemmann 3 siblings, 0 replies; 20+ messages in thread From: James Cloos @ 2012-11-30 0:56 UTC (permalink / raw To: Jorge Almeida; +Cc: gentoo-user If you are looking for the serial number of a usb device, I find them at: /sys/bus/usb/devices/usb*/*/serial NB that not all have them. -JimC -- James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6 ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [gentoo-user] serial in /sys 2012-11-29 17:57 [gentoo-user] serial in /sys Jorge Almeida ` (2 preceding siblings ...) 2012-11-30 0:56 ` James Cloos @ 2012-11-30 18:02 ` Volker Armin Hemmann 3 siblings, 0 replies; 20+ messages in thread From: Volker Armin Hemmann @ 2012-11-30 18:02 UTC (permalink / raw To: gentoo-user; +Cc: Jorge Almeida Am Donnerstag, 29. November 2012, 17:57:46 schrieb Jorge Almeida: > Anyone knows how to dig into /sys to find the serial number of a device > (say, a USB pen)? I few days ago I found by trial and error something like > $ cat > /sys/devices/pci0000:00/0000:00:06.1/usb2/2-4/2-4:1.0/host13/target13:0:0/1 > 3:0:0:0/block/sdc/../../../../../serial which gave me E68911000519 > Now I can't find nothing of the sort. (Yes, I know the path changes > each time the > device is plugged in, but even so) > Any information that would put some order into this mess would be great. why not just use lsusb -v for usb devices? -- #163933 ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2012-12-01 9:13 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-11-29 17:57 [gentoo-user] serial in /sys Jorge Almeida 2012-11-29 18:35 ` Marco Bonfiglio 2012-11-29 19:07 ` Jorge Almeida 2012-11-29 22:09 ` Kevin Chadwick 2012-11-30 10:00 ` Neil Bothwick 2012-11-30 12:48 ` Jorge Almeida 2012-11-29 19:20 ` Bruce Hill 2012-11-29 19:31 ` Jorge Almeida 2012-11-29 20:20 ` Bruce Hill 2012-11-29 20:56 ` Jorge Almeida 2012-11-29 22:35 ` Walter Dnes 2012-11-30 0:28 ` Jorge Almeida 2012-11-30 3:09 ` Walter Dnes 2012-11-30 9:58 ` Jorge Almeida 2012-12-01 3:47 ` Walter Dnes 2012-12-01 4:55 ` Joshua Murphy 2012-12-01 9:11 ` Jorge Almeida 2012-12-01 9:08 ` Jorge Almeida 2012-11-30 0:56 ` James Cloos 2012-11-30 18:02 ` Volker Armin Hemmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox