Le Refuge

Le blog Montagnisme

#68 - Consistent Linux device enumeration - Unix & Linux Stack Exchange

En gros, une méthode qui permet d’avoir un symlink prédéfini pour un périphérique USB donné, et qui peut être attribué selon le modèle voire le serial de l’objet.
La réponse, au cas où :

Since we are talking USB devices and assuming you have udev, you could setup some udev rules.

I guess, and this is just a wild guess, somebody or something unplugged/removed the device and plugged it back in/added the device again, which bumps up the number.

Now, first you need vendor and product id's:

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 011: ID 0403:6001 FTDI FT232 USB-Serial (UART) IC


Next, you need the serial number (in case you have several):


# udevadm info -a -n /dev/ttyUSB1 | grep '{serial}' | head -n1
    ATTRS{serial}=="A6008isP"


Now, lets create a udev rule:

UDEV rules are usually scattered into many files in /etc/udev/rules.d. Create a new file called 99-usb-serial.rules and put the following line in there, I have three devices, each with a a different serial number:


SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A6008isP", SYMLINK+="MySerialDevice"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A7004IXj", SYMLINK+="MyOtherSerialDevice"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTDIF46B", SYMLINK+="YetAnotherSerialDevice"



ls -l /dev/MySerialDevice
lrwxrwxrwx 1 root root 7 Nov 25 22:12 /dev/MySerialDevice -> ttyUSB1


If you do not want the serial number, any device from vendor with same chip will then get the same symlink, only one can be plugged in at any given time.


SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="MySerialDevice