[Triumf-linux-managers] FYI - adventures in udev, and PCI slot numbering
Andrew Daviel
advax at triumf.ca
Fri Aug 31 14:17:06 PDT 2012
FYI
I was recently looking at how devices in Linux get numbered - I have a PC
with two identical video capture cards and wanted to make sure they are
always numbered the same way round after a power outage.
I'm not sure whether I really needed to do this, but in any case I have a
recipe to ensure that the card in the lower PCI slot is always
/dev/video1 regardless of whether there are 1 or 2 cards fitted
(normally, if there's only one card it would be video0).
Similarly one can pin a particular NIC to eth0 by MAC address.
One can build udev rules and put them in /etc/udev/rules.d, e.g. I have
KERNEL=="video*", ID=="0000:08:01.0", BUS=="pci", NAME="video1"
to pin PCI slot 08:01 to /dev/video1
This is documented in e.g.
http://www.reactivated.net/writing_udev_rules.html
One can find suitable parameters using e.g.
$ udevinfo -a -p `udevinfo -q path -n /dev/video0`
In SL6, this is now
$ udevadm info -a -p `udevadm info -q path -n /dev/video0`
The same technique should work to assign invariant device names to USB
devices such as audio adapters, printers and webcams, if a suitable
identifier can be found (serial number etc.)
The PCI slots found with "lspci" seem to be invariant to power-cycling
and whether the BIOS is set to PnP OS or not. This may be obvious but I
had wondered whether the slot numbers were physical ones or logical ones
assigned by the BIOS. E.g. the second PCI slot on my motherboard is
08:01 regardless of whether it has a video card or an audio card in it,
and whether the first slot (08:00) is populated.
PCI slots seen in Windows device manager match those seen in Linux with
lspci (again ought to be obvious), e.g.
02:09.3 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev 12)
PCI bus 2 device 9 function 3 - Ricoh xD-Picture Card Controller
Incidentally, lspci version 3 (standard in SL6) has a "-q" option to
query the PCI database online, while pcitools 3 builds easily on SL5. So
you can easily identify previously "unknown" devices.
--
Andrew Daviel, TRIUMF, Canada
Tel. +1 (604) 222-7376 (Pacific Time)
Network Security Manager
More information about the Triumf-linux-managers
mailing list