53.7 UDEV

udev hotplug

A problem that plagued earlier versions of the GNU/Linux kernel was that each time a USB device (and other devices) was connected a different mount point would be assigned. This issue was addressed in the 2.6 kernels using udev with hotplug. With udev, naming rules (e.g., in /etc/udev/rules.d/local.rules) are used to provide stable names for use in /etc/fstab. Udev uses information exported by the kernel drivers to the sysfs filesystem (usually mounted on /sys) to identify specific devices and to then associate them with specific names in /dev.

The key to using udev is with the rules that are defined to identify and distinguish the different USB devices that may be connected. A tutorial for writing udev rules is available from http://www.reactivated.net/udevrules.php.

The first step is to identify the USB device in some way. The udevinfo command can be used to identify a device path, which can then be used to identify information about the device on that path. For example, to identify a specific Flash Memory device which is recognised in GNU/Linux as a SCSI device, connect the device and run the command:

  $ udevinfo -a -p $(udevinfo -q path -n /dev/sdc)

The /dev/sdc path here is whatever the dmesg command identifies. Select some identifying piece of information, like the product identifier (the line that starts with SYSFS\{product\=}), and add that to /etc/udev/rules.d/local.rules (each rule must be on a single line).

53.7.1 Flash Memory

On one line in /etc/udev/rules.d/local.rules:

  BUS=="usb", KERNEL=="sd?1", SYSFS{product}=="USB FLASH DISK", 
  NAME="%k", SYMLINK=""usbkey"

Then restart udev:

  $ sudo restart udev

Add a suitable entry to /etc/fstab:

  /dev/usbkey   /media/usbkey   auto    user,defaults       0   0

Be sure the mount point /media/usbkey exists:

  $ sudo mkdir /media/usbkey

An alternative name might be:

  BUS=="usb", KERNEL=="sd?1", SYSFS_serial=="07381C501259", NAME="usb/key%n"

53.7.2 Camera

  $ udevinfo -a -p /block/sdc
  $ sudo emacs -nw /etc/udev/rules.d/local.rules
  BUS=="usb", KERNEL=="sd?1", SYSFS{product}=="hp photosmart 320", 
  NAME="%k", SYMLINK="photosmart"
  $ sudo emacs -nw /etc/fstab
  /dev/photosmart /media/photosmart auto user,defaults  0   0
  $ sudo mkdir /media/photosmart
  $ wajig restart udev

A Nikon Coolpix E5200 camera:

  $ udevinfo -a -p /block/sdc
  $ sudo emacs -nw /etc/udev/rules.d/local.rules
  BUS=="usb", KERNEL=="sd?1", SYSFS{product}=="NIKON DSC E5200", 
  NAME="%k", SYMLINK="nikon"
  $ sudo emacs -nw /etc/fstab
  /dev/nikon /media/nikon auto user,defaults    0   0
  $ sudo mkdir /media/nikon
  $ wajig restart udev

For some reason /dev/sdc1 is not created when the camera is plugged in (/dev/sdc is). But after an attempt to mount /dev/sdc, /dev/sdc1 comes into existence (even though the mount command fails with a request to specify the filesystem type). After installing the gnome-volume-manager /dev/sdc1 started being created.

53.7.3 iPod

The following udev rule will create a symbolic link called ipod in /dev/ to the data partition on an iPod when it is plugged in:

  BUS=="scsi", SYSFS{model}=="iPod", KERNEL=="sd?3", NAME="%k", SYMLINK="ipod"

53.7.4 Card Reader

For a card reader they usually do not provide media change information and so the kernel can not generate a hotplug event for udev. In this situation you can use the all_partitions property for the NAME. To get access to a CF slot on a specific multi-card reader:

  BUS=="scsi", SYSFS{vendor}=="Zynet*", SYSFS{model}=="USB Storage-CFC*", 

53.7.5 MP3 Player iRiver H340

An iRiver H300 Series MP3/ogg HDD player (H340):

  $ udevinfo -a -p /block/sdc | grep product
    SYSFS{product}="iRiver H300 Series"
    SYSFS{product}="Intel Corp. 82801EB/ER ..."
  $ sudo emacs -nw /etc/udev/rules.d/local.rules
  BUS=="usb", KERNEL=="sd?1", SYSFS{product}=="iRiver H300 Series", 
  NAME="%k", SYMLINK="iriver"
  $ sudo emacs -nw /etc/fstab
  /dev/iriver /media/iriver auto users,defaults     0   0
  $ sudo mkdir /media/iriver
  $ wajig restart udev
  $ mount /media/iriver iRiver ifp796

Initial connect to USB did not report anything in dmesg. By looking at /proc/bus/usb/devices found:

  T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 26 Spd=480 MxCh= 0
  D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
  P:  Vendor=4102 ProdID=1007 Rev= 0.01
  S:  Manufacturer=iRiver Limited.
  S:  Product=IFP-700 HIGH SPEED
  C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
  I:  If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
  E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms

It was being found but there is no Driver! As I understand this means that the firmware is using the Managed firmware.

So instead install ifp-line and run as root:

  $ wajig install ifp-line
  $ ifp ls
  Device is busy.  (I was unable to claim its interface.)
  $ sudo ifp ls
  f iRiver, Catch the digital flow!.mp3   (size 1988608)

This works just fine! with commands to manage the iRiver from the command line.

A decent graphics interface is ifp-manager:

  $ wget http://optusnet.dl.sourceforge.net/sourceforge/ifp-manager/ifp-manager0_2_0.tar.bz2
  $ tar xvf ifp-manager0_2_0.tar.bz2
  $ cd ifp-manager0.2.0/
  $ sudo ./ifpmanager.pl

Another graphical interface is provided by ifp-gnome. The interface is good but the functionality is limited. Seems if you select a folder of albums belonging to an artist, only the first album gets uploaded.

  $ wget http://optusnet.dl.sourceforge.net/sourceforge/ifp-gnome/ifp-gnome_0.5-ubuntu1_noarch.deb
  $ wajig install ifp-gnome_0.5-ubuntu1_noarch.deb 
  $ sudo ifp-gnome

To allow a user access to the ifp:

  $ wajig install pmp-common
  $ sudo adduser kayon plugdev

53.7.6 Ethernet Cards

 KERNEL=="eth*", SYSFS{address}=="00:00:de:ad:be:ef", NAME="eth0"
 KERNEL=="eth*", SYSFS{address}=="00:00:fe:ed:ba:be", NAME="eth1"

53.7.7 Examples

A bunch of examples from Rogrio Brito:

  # USB Key Drive: "Leading Driver Co.,LTD.", "USB Mass Storage Device" 
  BUS=="usb", SYSFS{idProduct}=="2317", SYSFS{idVendor}=="067b",
  NAME="usb/key%n", SYMLINK="sda%n"

  # Printer: "DeskJet 840C", "BR1391S0WNKV" 
  BUS=="usb", SYSFS{idProduct}=="0604", SYSFS{idVendor}=="03f0",
  NAME="usb/lp%n", SYMLINK="hp_lp"

  # iPod 
  BUS=="ieee1394", SYSFS{model_name_kv}=="iPod", NAME="ipod%n"

  # HD in Firewire Enclosure 
  BUS=="scsi", SYSFS{vendor}=="QUANTUM*", SYSFS{model}=="FIREBALLlct15 30", 

Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.