X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=docs%2Fwriting_udev_rules%2Findex.html;h=1c5c89b3c91d512dd515f57621bd56aec2954c4a;hb=731f0aec41e3f46f5b630e70166ab384976d52c6;hp=c2ccdc3663f1878a1bbc5fe9bbf8295904057f2e;hpb=ab925d69d5d38e851ae3b71523fb70a75f7b16de;p=elogind.git
diff --git a/docs/writing_udev_rules/index.html b/docs/writing_udev_rules/index.html
index c2ccdc366..1c5c89b3c 100644
--- a/docs/writing_udev_rules/index.html
+++ b/docs/writing_udev_rules/index.html
@@ -113,7 +113,7 @@ As your own rules will effectively mask out the udev defaults which create the b
In rule files, lines starting with a "#" are treated as comments. Every uncommented line in the file corresponds to a rule.
-Rules are composed of keys. Keys are seperated by commas. Some keys are used for reading and matching information, others are used for assigning information and performing actions.
+Rules are composed of keys. Keys are seperated by commas. Some keys are used for reading and matching information, others are used for assigning information and performing actions. Matches and assignments are carried out with the expected operators (= and ==).
+BUS="usb", SYSFS{serial}="HXOLL0012202323480", NAME="lp_epson", SYMLINK="printers/epson_stylus"
The identification keys here are BUS and SYSFS{serial}. The assignment keys here are NAME and SYMLINK. udev will match this rule against a device that is connected through the USB bus and with a serial number of HXOLL0012202323480. Note that all (as opposed to any) specified keys must be matched for udev to use the rule to name a device.BUS=="usb", SYSFS{serial}=="HXOLL0012202323480", NAME="lp_epson", SYMLINK="printers/epson_stylus"
+BUS="usb", SYSFS{vendor}="FUJIFILM", SYSFS{model}="M100", NAME="camera%n"
The %n operator will be replaced with the "kernel number" for the camera device, to produce a NAME such as camera0, camera1, etc.BUS=="usb", SYSFS{vendor}=="FUJIFILM", SYSFS{model}=="M100", NAME="camera%n"
+KERNEL="ts*", NAME="input/%k"
The * operator is used here, which matches literally anything - zero, one, or more characters of any kind. The rule literally says:KERNEL=="ts*", NAME="input/%k"
+KERNEL="fd[0-9]*", NAME="floppy/%n"
This rule says:KERNEL=="fd[0-9]*", NAME="floppy/%n"
follow the class device's "device" looking at the device chain at '/sys/devices/pci0000:00/0000:00:02.1/usb3/3-3/3-3:1.0/host0/0:0:0:0': - BUS="scsi" - ID="0:0:0:0" - SYSFS{detach_state}="0" - SYSFS{type}="0" - SYSFS{max_sectors}="240" - SYSFS{device_blocked}="0" - SYSFS{queue_depth}="1" - SYSFS{scsi_level}="3" - SYSFS{vendor}=" " - SYSFS{model}="USB 2.0M DSC " - SYSFS{rev}="1.00" - SYSFS{online}="1" + BUS=="scsi" + ID=="0:0:0:0" + SYSFS{detach_state}=="0" + SYSFS{type}=="0" + SYSFS{max_sectors}=="240" + SYSFS{device_blocked}=="0" + SYSFS{queue_depth}=="1" + SYSFS{scsi_level}=="3" + SYSFS{vendor}==" " + SYSFS{model}=="USB 2.0M DSC " + SYSFS{rev}=="1.00" + SYSFS{online}=="1" looking at the device chain at '/sys/devices/pci0000:00/0000:00:02.1/usb3/3-3': - BUS="usb" - ID="3-3" - SYSFS{detach_state}="0" - SYSFS{bNumInterfaces}=" 1" - SYSFS{bConfigurationValue}="1" - SYSFS{bmAttributes}="c0" - SYSFS{bMaxPower}=" 0mA" - SYSFS{idVendor}="052b" - SYSFS{idProduct}="1514" - SYSFS{bcdDevice}="0100" - SYSFS{bDeviceClass}="00" - SYSFS{bDeviceSubClass}="00" - SYSFS{bDeviceProtocol}="00" - SYSFS{bNumConfigurations}="1" - SYSFS{speed}="12" - SYSFS{manufacturer}="Tekom Technologies, Inc" - SYSFS{product}="USB 2.0M DSC" + BUS=="usb" + ID=="3-3" + SYSFS{detach_state}=="0" + SYSFS{bNumInterfaces}==" 1" + SYSFS{bConfigurationValue}=="1" + SYSFS{bmAttributes}=="c0" + SYSFS{bMaxPower}==" 0mA" + SYSFS{idVendor}=="052b" + SYSFS{idProduct}=="1514" + SYSFS{bcdDevice}=="0100" + SYSFS{bDeviceClass}=="00" + SYSFS{bDeviceSubClass}=="00" + SYSFS{bDeviceProtocol}=="00" + SYSFS{bNumConfigurations}=="1" + SYSFS{speed}=="12" + SYSFS{manufacturer}=="Tekom Technologies, Inc" + SYSFS{product}=="USB 2.0M DSC"The udevinfo tool provides a lot of information which you can simply copy-paste as udev rules. The reason that I have colour coded the above output is to point out that you generally cannot mix and match information from different parts of the udevinfo output. In the above output, I could not combine information from the different coloured sections - this is because each section of output refers to a different directory in SYSFS. For example, the following rule would not work: -
-This rule would not work because I am combining information found in the section beginning with BUS="scsi" (green) with information only found in the blue section. The rule would work if I used BUS="usb", sticking only to information found in the blue section above.BUS="scsi", SYSFS{manufacturer}="Tekom Technologies, Inc", NAME="%k"
+This rule would not work because I am combining information found in the section beginning with BUS=="scsi" (green) with information only found in the blue section. The rule would work if I used BUS=="usb", sticking only to information found in the blue section above.BUS=="scsi", SYSFS{manufacturer}=="Tekom Technologies, Inc", NAME="%k"
+KERNEL="hdc", SYMLINK="dvd"
When udev finds this rule, it will take a mental note of it. Upon finding another rule matching the same device which also includes a NAME parameter, udev will create the node as specified by the NAME parameter, plus symbolic links as specified by the SYMLINK parameters of both rules.KERNEL=="hdc", SYMLINK="dvd"
+KERNEL="fb[0-9]*", NAME="fb/%n", SYMLINK="%k", GROUP="video"
The OWNER key, perhaps less useful, allows you to define which unix user should own the device node. Assuming the slightly odd situation where you would want "john" to own your floppy devices, you could use: -KERNEL=="fb[0-9]*", NAME="fb/%n", SYMLINK="%k", GROUP="video"
+KERNEL="fd[0-9]*", OWNER="john"
You'll notice in the above rule that we didn't specify any NAME or SYMLINK keys. This is similar to the multiple symlink style where udev will take a mental note that we want john to own floppy nodes, and will apply that ownership once it finds a rule which defines a NAME for the floppy device nodes.KERNEL=="fd[0-9]*", OWNER="john"
+SUBSYSTEM="sound", GROUP="audio"
-This prevents the need to excessively provide a GROUP="audio" key on every following rule which names sound devices.SUBSYSTEM=="sound", GROUP="audio"
+KERNEL="inotify", NAME="misc/%k", SYMLINK="%k", MODE="0666"
KERNEL=="inotify", NAME="misc/%k", SYMLINK="%k", MODE="0666"
My udev rule becomes: -looking at the device chain at '/sys/devices/pci0000:00/0000:00:02.1/usb3/3-3': -BUS="usb" -SYSFS{manufacturer}="EPSON" -SYSFS{product}="USB Printer" -SYSFS{serial}="L72010011070626380" +BUS=="usb" +SYSFS{manufacturer}=="EPSON" +SYSFS{product}=="USB Printer" +SYSFS{serial}=="L72010011070626380"
+BUS="usb", SYSFS{serial}="L72010011070626380", NAME="%k", SYMLINK="epson_680"
And my printer nodes exist at /dev/lp0 (or /dev/lp1 if another printer was plugged in beforehand) and /dev/epson_680 always points at the device node for that particular printer.BUS=="usb", SYSFS{serial}=="L72010011070626380", NAME="%k", SYMLINK="epson_680"
In the udevinfo output, I also noticed this bit of useful and understandable information: -# udevinfo -a -p /sys/block/sda/sda1
+SYSFS{product}="USB 2.0M DSC"
So that gives me my rule. For completeness, I also include a BUS key (this was also found in the udevinfo output). -SYSFS{product}=="USB 2.0M DSC"
+BUS="usb", SYSFS{product}="USB 2.0M DSC", KERNEL="sd?1", NAME="%k", SYMLINK="camera"
Now, when my camera is plugged in, it will be named /dev/sda1 (or, if sda1 isnt available, it might be called /dev/sdb1) and will always be correctly linked to from /dev/camera. The /dev/sda (or sdb) node still appears as normal, but the important thing is that my custom persistent "camera" symlink points to the mountable partition.BUS=="usb", SYSFS{product}=="USB 2.0M DSC", KERNEL=="sd?1", NAME="%k", SYMLINK="camera"
+BUS="usb", KERNEL="sd*", SYSFS{product}="USB 2.0 Storage Device", NAME="%k", SYMLINK="usbhd%n"
This rule creates symlinks such as:BUS=="usb", KERNEL=="sd*", SYSFS{product}=="USB 2.0 Storage Device", NAME="%k", SYMLINK="usbhd%n"
+BUS="usb", SYSFS{product}="USB 2.0 Storage Device", NAME{all_partitions}="usbhd"
You will now have nodes named: usbhd, usbhd1, usbhd2, usbhd3, ..., usbhd15.BUS=="usb", SYSFS{product}=="USB 2.0 Storage Device", NAME{all_partitions}="usbhd"
You may have noticed that the default 50-udev.rules file contains a rule which runs a script to produces names for block devices. Do not be confused by this - as usual, because your own rules are located in a file which is processed before the default rules, the defaults will not be used when naming the hardware you have written rules for.-BUS="ide", KERNEL="hdc", NAME="%k", SYMLINK="dvd cdroms/cdrom%n" -BUS="ide", KERNEL="hdd", NAME="%k", SYMLINK="cdrw cdroms/cdrom%n" +BUS=="ide", KERNEL=="hdc", NAME="%k", SYMLINK="dvd cdroms/cdrom%n" +BUS=="ide", KERNEL=="hdd", NAME="%k", SYMLINK="cdrw cdroms/cdrom%n"
+BUS="usb", SYSFS{product}="Palm Handheld", KERNEL="ttyUSB*", SYMLINK="pilot"
This was adapted from Carsten Clasohm's blog entry, which includes a useful discussion of the situation. You may also wish to add ownership and permission keys to the rule to suit your setup.BUS=="usb", SYSFS{product}=="Palm Handheld", KERNEL=="ttyUSB*", SYMLINK="pilot"
Every network adapter has its own unique MAC-address, so I chose to use this when writing my rule. This will not change, unless you change your network card. There is one caveat here: make sure you use the MAC address you obtain from udevinfo (as above), because it is case sensitive. Be careful when using utilities such as ifconfig as they will capitalize the letters.# udevinfo -a -p /sys/class/net/eth0/ looking at class device '/sys/class/net/eth0': - SYSFS{address}="00:52:8b:d5:04:48" + SYSFS{address}=="00:52:8b:d5:04:48"
+KERNEL="eth*", SYSFS{address}="00:52:8b:d5:04:48", NAME="lan"
You will need to reload the net driver for this rule to take effect. You can either unload and reload the module, or simply reboot the system. You will also need to reconfigure your system to use "lan" rather than "eth0". I had some troubles getting this going (the interface wasn't being renamed) until I had completely dropped all references to eth0.KERNEL=="eth*", SYSFS{address}=="00:52:8b:d5:04:48", NAME="lan"