Udev

From Devipedia

Jump to: navigation, search

udev controls the mounting of devices to the /dev directory.

The general process is:

  1. Find out what attributes are logged from the device you want to mount (udevinfo)
  2. Write a udev rule that will match on the attribute
  3. Make the rule do the mount

To see what's happening when you add/remove a device, run...

udevmonitor

You will see this kind of output when you plug in a device:

UEVENT[1268081474.926762] add@/devices/pci0000:00/0000:00:04.0/0000:06:00.0/host6/target6:0:0/6:0:0:0
UEVENT[1268081474.926832] add@/class/scsi_disk/6:0:0:0
UEVENT[1268081474.937927] add@/block/sdc
UEVENT[1268081474.937937] add@/block/sdc/sdc1
UEVENT[1268081474.938185] add@/class/scsi_device/6:0:0:0
UEVENT[1268081474.938231] add@/class/scsi_generic/sg1
UDEV  [1268081475.049069] add@/devices/pci0000:00/0000:00:04.0/0000:06:00.0/host6/target6:0:0/6:0:0:0
UDEV  [1268081475.252219] add@/class/scsi_disk/6:0:0:0
UDEV  [1268081475.256564] add@/class/scsi_generic/sg1
UDEV  [1268081475.299790] add@/block/sdc
UDEV  [1268081475.456067] add@/class/scsi_device/6:0:0:0
UDEV  [1268081475.616953] add@/block/sdc/sdc1
UEVENT[1268081475.961183] mount@/block/sdc/sdc1
UDEV  [1268081476.021674] mount@/block/sdc/sdc1

Also, refer to this thread:

http://ubuntuforums.org/showthread.php?t=168221

And this one:

http://reactivated.net/writing_udev_rules.html

Example

To mount the removable drives, I created a file called 96-udev.rules and placed it under /etc/udev/rules.d. This mounts the drive as /media/removable when plugged in.

ACTION=="add",SYSFS{rev}=="ST6O",SYSFS{model}=="Hitachi HDT72101",KERNEL=="sd?1",NAME="REMOVABLE", RUN+="/bin/mount /dev/REMOVABLE /media/removable"
ACTION=="remove",SYSFS{rev}=="ST6O",SYSFS{model}=="Hitachi HDT72101",RUN+="/bin/umount /media/removable"
Personal tools