User Tools

Site Tools


doc:appunti:linux:sa:renaming_usb_devices

Renaming USB serial devices

When you connect an usb-serial adapter to a GNU/Linux host, it gets named something like ttyUSB0. Other similar devices get the name with subsequent numbers: ttyUSB1, ttyUSB2, etc. If you want a predictable device name, you can use udev rules.

In the following examples you can assign a predictable name by USB slot position or by vendor/product of the USB adapter.

Once the device is connected, inspect the udev subsystem about it;

udevadm info -a -p  $(udevadm info -q path -n /dev/ttyUSB0)

You can choose among many attributes to identify the device.

The following example will identify the device by the USB position, which is also reported by dmesg:

usb 1-2.3: pl2303 converter now attached to ttyUSB0

Create a file /etc/udev/rules.d/10-local.rules with the following line:

ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="1-2.3", SYMLINK+="usbserial_A"

Otherwise you can select by vendor/product, with another line like this one:

ACTION=="add", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="usbserial_B"

Let the udev subsystem to re-read the rules:

udevadm trigger

Now, when you plug the USB adapter, a symlink will be created /dev/usbserial_A -> ttyUSB0.

If more than one rule match, more than one symlink will be created.

doc/appunti/linux/sa/renaming_usb_devices.txt · Last modified: 2021/06/09 12:29 by niccolo