Linux: how to force a USB device to use the same ttyUSB number

52,907

udev is Linux's dynamic device manager. udev persists information about devices you plug in, and you can modify this information so that it adds a specific 'symlink' in the directory for this device.

Now, your usb modem's definition should be inside the folder /etc/udev/rules.d/, and the filename will be something like 50-udev.rules. The file contains one line per device, (you can use a number of tools to help identify the correct line. See below link on using udevinfo)

Now, you can edit the relevant line, or even better, create another file and copy the relevant line into it. The filename should start with a lower number (e.g. 49-my-modem.rules), so that it gets loaded first. You need to add the following to the end of the line:

, SYMLINK="ttyUSBmodem"

Now, your device should come up as /dev/ttyUSBmodem (aswell as the dynamically assinged /dev/ttyUSB[0-9])

For more help with identifying the correct line and the whole process, see here: http://noctis.de/archives/16-HowTo-fixed-name-for-a-udev-device.html

HTH

Share:
52,907
Johny
Author by

Johny

Updated on July 05, 2022

Comments

  • Johny
    Johny almost 2 years

    I have an USB modem that I use on Ubuntu. I have also a program which communicate with this device using its ttyUSBxx number.

    My problem is that every time I unplug/plug the device again, or when I reboot my PC, the device gets a new ttyUSB number, for example: ttyUSB0 or ttyUSB1.

    How can I force this device to always use the same number (say: ttyUSB0)?