Linux USB Serial Device Name Binding
Have you worked with USB serial devices on Linux? One annoyance you may have
come across is device name changes after each reboot. This problem gets solved
by binding a custom /dev name to a USB device. This post shows you how.
To be clear, this article walks through assigning USB serial devices persistent names. If you have a USB block device and would like to give it a persistent name, the ArchWiki has you covered.
USB Serial Device Name Binding Using udev
The instructions below will work on a Linux distro that uses udev for
device management. You will need root privileges to follow these
instructions!
- Plugin the USB serial device.
- Identify the
/dev/ttyUSB*name assigned to your device. There are many ways to do this. Perhaps the easiest is togrepthedmesglog to see what name the kernel gives the device:
dmesg | grep USB- List the device attributes using
udevadm. Replace<X>with the USB number found in step 2:
udevadm info --name=/dev/ttyUSB<X> --attribute-walk- You’ll see a list of attributes for your device on the console. Find one or more attributes that uniquely identify your device. The combination of vendor ID and product ID is a good choice.
- Create or edit the
/etc/udev/rules.d/99-usb-serial.rulesfile to include an entry like the one shown below. Be sure to input your own attributes and setSYMLINKto the name you’d like the device to have.
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="mydevice"- Load the new rules using
udevadm:
udevadm trigger- Verify the USB serial device has its new name:
ls -l /dev/mydevice- On reboot or when you plugin the device, the new name will persist.
To bind more device names, simply add rules to 99-usb-serial.rules. To undo
these changes, delete the device’s corresponding rule in
/etc/udev/rules.d/99-usb-serial.rules and run udevadm trigger.