Mounting USB devices from udev with permissions of the user at the console

November 2007


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

  1. lsusb shows:

  2. find /sys/ -type f -exec grep -li nokia {} \; 2>/dev/null shows:

  3. udevinfo -a -p /sys/devices/pci0000:00/0000:00:1d.3/usb4/4-1/ gives:

  4. 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"
    	

  5. 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]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.

  6. udevcontrol reload_rules to make the udev subsystem reconsider its position on our device.

  7. Then we re-plug the device, and we should see some effects in the logs, and /dev/nokia6630 appears.

    [Note]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]Note

    I saw some commands pertaining to USB subsystems still fail because they access /dev/bus/usb and deeper, which they weren't allowed to read (let alone write).