Results 1 to 4 of 4
Hi,
I want to match a usb block device (pen, disk) with a particular USB port on my PC, i.e., only enable usbmount when a pendrive is inserted on that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-09-2012 #1Just Joined!
- Join Date
- Sep 2011
- Posts
- 14
Matching a usb block device with a USB port
Hi,
I want to match a usb block device (pen, disk) with a particular USB port on my PC, i.e., only enable usbmount when a pendrive is inserted on that USB port.
Likewise, I also want to match my USB soundcard with another USB, i.e., only make it available on that other USB port.
How can I do that?
Thanks!
- 04-19-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,657
have you tried using udev rules? they are pretty good at allowing you to tying specific hardware to events (i.e. plugging in a USB peripheral of a specific type, vendor, etc.). i'm not sure about differentiating b/t one USB port and another, but i'll bet you could. you can enumerate the buses with the lsusb command (it is part of the usbutils package in Fedora), e.g.:
on my machine, that spits outCode:lsusb
so maybe you could write a udev rule that is triggered when plugging in a specific type of USB device (or even a unique device, based upon S/N, etc.) and then run lsusb (or examine /sys/bus/usb/devices/) to determine which port it was plugged into...worth a try anyway.Code:Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB Bus 005 Device 002: ID 04d9:1603 Holtek Semiconductor, Inc. Keyboard Bus 001 Device 004: ID 1bcf:0c31 Sunplus Innovation Technology Inc.
- 04-23-2012 #3Just Joined!
- Join Date
- Sep 2011
- Posts
- 14
Hi Atreyu,
very good idea you've given me.
But I can't even get this to work here:
The message (for testing) doesn't even get logged in /var/log/syslog.Code:SUBSYSTEMS=="usb", ACTION=="add", RUN+="logger 1234567890"
- 04-23-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,657
try using the full path to the program, e.g. RUN+="/usr/bin/logger".
here is an example of my udev rule for USB devices (located at /etc/udev/rules.d/99-test-usb.rules):
the script /tmp/usb-prog.sh (which should be set executable by all) will be passed five args on the command line:Code:# only apply this rule when adding devices, not removing them ACTION!="add", GOTO="usb_storage_end" # # only match on block devices SUBSYSTEM!="block", GOTO="usb_storage_end" # # whenever a usb storage device is detected, take the following action BUS=="usb", RUN+="/tmp/usb-prog.sh 'bus=usb' 'kernelname=%k' 'vendor=%s{vendor}' 'model=%s{model}' 'devname=$env{DEVNAME}'" # LABEL="usb_storage_end"
bus=usb
kernelname=...
vendor=...
model=...
devname=...
this setup has been tested on RHEL 4 and Fedora 10/11, fwiw.


Reply With Quote

