We assume that a user plugs in their USB device only after having logged in. When they do, we want the device to automatically become mounted, under the ownership of the user that controls the console.
We use Writing udev rules for documentation, and connect the device.
Procedure 37. Figuring out the device characteristics and writing a matching rule
Bus 004 Device 014: ID 0421:0410 Nokia Mobile Phones 6630 Imaging Smartphone
find /sys/ -type f -exec grep -li nokia {} \; 2>/dev/null shows:
/sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1/product
/sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1/manufacturer
udevinfo -a -p /sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1/ gives:
<snipped for brevity>
looking at device '/devices/pci0000:00/0000:00:1d.3/usb4/4-1':
KERNEL=="4-1"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{product}=="Nokia 6630"
ATTR{manufacturer}=="Nokia"
ATTR{maxchild}=="0"
ATTR{version}==" 2.00"
ATTR{devnum}=="14"
ATTR{speed}=="12"
ATTR{bMaxPacketSize0}=="64"
ATTR{bNumConfigurations}=="1"
ATTR{bDeviceProtocol}=="00"
ATTR{bDeviceSubClass}=="00"
ATTR{bDeviceClass}=="02"
<snipped for brevity>
So in /etc/udev/nokia6630.rules
, we create a rule like
DRIVER=="usb", SUBSYSTEMS=="usb", BUS=="usb", SYSFS{manufacturer}=="Nokia", SYSFS{product}=="Nokia 6630", SYMLINK+="nokia6630", RUN+="/usr/local/sbin/chown2conu /dev/nokia6630 /mobieltje"
And in order to activate the rule, we cd to /etc/udev/rules.d
and link to the file containing the rule: ln -s ../nokia6630.rules 40_nokia6630.rules.
Note | |
---|---|
This link needs to be in a proper place in the alphabetical order, as too late may mean that other rules have been applied to the device already. |
udevcontrol reload_rules
to make the udev
subsystem reconsider its position on our device.
Then we re-plug the device, and we should see some effects in the logs, and /dev/nokia6630
appears.
Note | |
---|---|
It is also possible to run udevtrigger instead of replugging. |
We now have a mount point and a device owned by the console user.
Note | |
---|---|
I saw some commands pertaining to USB subsystems still fail because they access |