Manage Linux Hardware with udev - Page 2
Writing udev Rules
Current releases of udev come
with bales of man pages, and several different useful commands. On Debian
systems, find them all with dpkg: $ dpkg -L udev
On Fedora, use the rpm command: $ rpm -ql udev
You'll see there are different command sets for each distribution, and a pox on both of them for sowing useless confusion, so we'll look at the important commands they have in common.
The first step for writing or modifying udev rules is to make sure that
your kernel sees the device you want to make the rule for. (If the kernel
doesn't see it, you need to find out if your device is supported in Linux
at all, then how to enable that support.) First try running the
udevinfo command. This example dumps all devices in the udev
database: $ udevinfo -e
You may query individual devices, if you know the device path, as this
example for an SATA partition shows: $ udevinfo -a -p /block/sda/sda1
How do you know the device path? From udevinfo. You already know
the node name for some of your devices, and can query it this way: $ udevinfo -q all -n sda
Both of these commands spit out a lot of information. Just for fun, you
can run lspci and match up the disk/by-path/pci values from
udevinfo: 0000:00:0f.0 RAID bus controller: VIA Technologies, Inc. VIA
VT6420 SATA RAID Controller (rev 80)S: disk/by-path/pci-0000:00:0f.0-scsi-0:0:0:0-part1
The output of udevinfo is pretty cryptic, so this is one way to match it up to devices with names you recognize. For USB devices compare with the output of lsusb. SCSI devices compare to lsscsi.
Come back next week to learn how to nail down USB network cards, straighten out device permissions, and manage multiple storage drives painlessly with udev.
Resources
- udev
home page on kernel.org
- udev
and devfs - The final word
- Continuing To Debate devfs and
udev
- Writing udev rules. This howto by Daniel Drake is the ultimate resource for learning how to write udev rules.