The kernel-assigned names are always assigned in the order the devices are detected, and you cannot change them. (Not anymore, anyway – this function was removed due to various race conditions that "persistent name" rules caused.)
But you can tell udev to create symlinks with whatever names you choose. In fact, on modern systems, you should already have symlinks under /dev/serial
named after both the device's path, and its unique ID; for example:
/dev/serial/by-path/pci-0000:00:1a.0-usb-0:1.2:1.0
→ ttyUSB0
/dev/serial/by-id/usb-Motorola_Inc._Motorola_Phone__C350_-if00
→ ttyACM0
/dev/disk/by-id/ata-ST9640320AS_5WX1ZH91-part1
→ sda1
/dev/disk/by-partlabel/Arch
→ sda3
/dev/input/by-id/usb-PIXART_USB_OPTICAL_MOUSE-mouse
→ mouse1
And so on. Just run tree /dev
or ls -lR /dev
to find your device.
You can also run udevadm info /dev/ttyUSB0
and all symlinks to that device will be listed as S: ...
lines.
If this is not enough, you can write your own udev rules. First run udevadm info /dev/ttyUSB0
and choose any identifying property (such as ID_PATH
for the USB port). It's a good idea to always include the subsystem as well.
Then open (or create) a file in /etc/udev/rules.d/
(named, for example, serial-symlinks.rules
), and put the udev rule there.
For example, if the output for ttyUSB0
is:
$ udevadm info /dev/ttyUSB0
. . .
E: ID_PATH=pci-0000:00:1d.0-usb-0:1.2:1.0
. . .
E: SUBSYSTEM=tty
. . .
...you can write this rule:
SUBSYSTEM=="tty", ENV{ID_PATH}=="pci-0000:00:1d.0-usb-0:1.2:1.0", SYMLINK+="tty-xbee"
...and udev will always symlink /dev/tty-xbee
to whatever tty device you connected to USB port #2.
(Note: Do not use the same names for symlinks as the kernel uses for device nodes. Using SYMLINK+="ttyUSB0"
will cause bad things to happen.)