Assign static /dev identifiers to USB devices

This tutorial shows you how to always assign the same alias to a particular /dev device, such as a mote.

Problem description

Linux creates a special file when you connect USB devices. Those file are in the form /dev/ttyUSB0 for the first one you plug in, /dev/ttyUSB1 for the second, etc.

Those name are created dynamically and depends on the order devices are plugged in.

It is sometimes useful to assign static names to those devices, e.g. to always reflash the right mote.

udev allows you to assign alias on certain devices depending on some of their properties.


First let's find the serial number of each USB devices:

$ udevadm info --attribute-walk -n /dev/ttyUSB5 | grep serial

Repeat this step for all your devices, changing /dev/ttyUSB to yours.

Once you have the mapping between the aliases you want to apply and the serial number of devices you can put them in a udev rules file like this one :

$ cat /etc/udev/rules.d/10-local.rules 
ACTION=="add", ATTRS{serial}=="A9040YRU", SYMLINK+="sniffer"
ACTION=="add", ATTRS{serial}=="AK004SL3", SYMLINK+="dr"
ACTION=="add", ATTRS{serial}=="AK004SL6", SYMLINK+="6n"

You can also see which device an alias points to by doing:

$ ls -all /dev/sniffer
lrwxrwxrwx 1 root root 7 août 30 14:17 /dev/sniffer -> ttyUSB3