How to Give Persistent Names To USB-Serial Devices on Ubuntu 14.04

Tayyar GUZELMay 22, 2017

If you have a bunch of USB-serial devices connected to your dock station and you needed to bind your USB-serial devices under static names so that all the USB-serial devices don't get to be assigned to random names by "udev" manager when you re-plug your laptop to the dock station, follow the instructions below. I will share the udev rules I created as a reference and give the step by step instructions to achieve persistent naming. All the steps worked on my Ubuntu 14.04 machine.

Step-by-step guide

  1. Need to first find out what's on ttyUSB:
    $ dmesg | grep ttyUSB
  2. List all attributes of the device and pick out a unique identifier set, eg idVendor + idProduct (and if necessary SerialNumber if you have more than one device with the same idVendor and idProduct).$ udevadm info --name=/dev/ttyUSB0 --attribute-walkYou need to do this for all devices (ttyUSB0, ttyUSB1, ...) and note the identifiers somewhere so that you can later use. Note  that when you list all the attributes to pick identifiers, you will see groups of attributes from child devices to parent devices. Make sure the ones you pick are from the same group.

    In my case, I have picked only KERNELS and ATTRS{serial} attributes to uniquely identify my devices.
  3. Create a file /etc/udev/rules.d/11-usb-serial.rules with something like this line in it:

    KERNELS=="some numbers", ATTRS{serial}=="alpha-numeric string", NAME="ttyUSB##", SYMLINK+="your_device_name"For instance; in my case, the following four lines worked.KERNELS=="3-4.2.3", ATTRS{serial}=="FTGNRHRS", NAME="ttyUSB20", SYMLINK+="ttyB5_1"
    KERNELS=="3-4.2.4", ATTRS{serial}=="FTH9KOBZ", NAME="ttyUSB21", SYMLINK+="ttyB5_2"
    KERNELS=="3-13.2", ATTRS{serial}=="FTH0AP09", NAME="ttyUSB22",SYMLINK+="ttyB5_3"
    KERNELS=="3-13.1", ATTRS{serial}=="A403IMVH", NAME="ttyUSB23",SYMLINK+="ttyOCD"The trick here is to give the dummy tty names with numbers to NAME and get uniqueness out of using identifiers such as KERNELS. You can name your symbolic link to anything.Notice if you don't have any rules defined for your usb devices under /etc/udev/rules.d, then pick any random number in front of the usb-serial.rules. In my case, I picked "11-usb-serial.rules".If you later write another rule with a higher number, it will override this rule.
  4. Load the new rule:
    $ sudo udevadm trigger
  5. Verify what happened:

    $ ls /dev/ttyB* -allrwxrwxrwx 1 root root 7 Jul 9 18:50 /dev/ttyB5_1 -> ttyUSB0
    lrwxrwxrwx 1 root root 7 Jul 9 18:50 /dev/ttyB5_2 -> ttyUSB1
    lrwxrwxrwx 1 root root 7 Jul 9 18:52 /dev/ttyB5_3 -> ttyUSB2
  6. Then, test it:
    $ sudo minicom -s ttyB5_1

What Might Go Wrong

You may end up seeing the symbolic links and running the serial terminals (minicom, putty) but not able to read/write from/to the serial devices. That means, udev manager could not uniquely identify your USB devices.

1) When you list all the attributes to pick identifiers, you will see groups of attributes from child devices to parent devices. Make sure the ones you pick are from the same group.

2) NAME field numbering might be wrong. Try to pick number you will never reach to (for instance, you may never connect 20 USB-serial devices to your computer. Then, start from ttyUSB20).

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: