Creating static USB names - grvcTeam/grvc-utils GitHub Wiki

When you plug a USB device on Linux it can be accessed in the /dev folder. If you only plug one device, its name probably will be /dev/ttyUSB0. This name is assigned automatically by the operating system. If you plug more than one device it may supposse a worry, because you don't know which is which. i.e. if you have a FCU, a RPLIDAR and a SF11 altimeter all connected via USB you will find all of them in /dev/ttyUSB0, /dev/ttyUSB1 and /dev/ttyUSB2. This is solved creating static symlink names using udev rules.

Creating udev rule

Assing by Vendor ID and Product ID

In most cases, only two things will be necessary: the Vendor ID (idVendor) and the Product ID (idProduct). First of all you need to localize the idVendor and the idProduct of the USB device you want to set a static name. You can write the following in the terminal:

sudo lsusb

The output will look like:

Bus 001 Device 003: ID 06cb:00bd Synaptics, Inc. 
Bus 001 Device 002: ID 04f2:b67c Chicony Electronics Co., Ltd 
Bus 001 Device 006: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 005: ID 8087:0029 Intel Corp. 
Bus 001 Device 004: ID 058f:9540 Alcor Micro Corp. AU9540 Smartcard Reader
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The device we will set a static name is the number 6 on the Bus 1: "Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light". The VID and PID are separated by a colon like idVendor:idProduct, in our case idVendor=10c4 and idProduct=ea60.

You will create a file in /etc/udev/rules.d using

sudo nano /etc/udev/rules.d/<some_name>.rules

In the file you will write the following

# set the udev rule , make the device_port be fixed
#
KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0777", SYMLINK+="<some_name>"

Remember to change the ATTRS{idVendor} and ATTRS{idProduct} values, as well as the name that you want to assign to the USB device by writing it in the SYMLINK parameter. After that, save and exit nano pressing Ctrl+X.

Now you need to reload and restart the udev service in order to take effect:

sudo service udev reload
sudo service udev restart

Assign by serial number

In some cases you connect two or more device of the same type and vendor, so the idVendor and idProduct are the same. In that case you need to add some extra info in the .rules file. This info may be some unique parameter like the serial number of the device. To find that you may write the following in the terminal:

sudo lsusb -d 0403:6001 -v | grep -i iSerial

where you have to replace 0403:6001 by the idVendor:idProduct of your device. The output of this command is:

  iSerial                 3 FTACTWRD

"FTACTWRD" is the serial number of the device, write it down on a piece of paper. Now edit the .rules file:

# set the udev rule , make the device_port be fixed
#
KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTACTWRD", MODE:="0777", SYMLINK+="<some_name>"

Save and restart the service:

sudo service udev reload
sudo service udev restart

Assign by USB port number

Finally, if two or more devices have the same serial number or a null serial, the unique solution is to assign the name directly to the USB port it is connected. To get the port, type in the terminal:

udevadm info -a -n /dev/ttyUSB0 | grep -i kernels

it will output something like

    KERNELS=="ttyUSB0"
    KERNELS=="1-2:1.0"
    KERNELS=="1-2"
    KERNELS=="usb1"
    KERNELS=="0000:00:14.0"
    KERNELS=="pci0000:00"

The USB port is "1-2:1.0", just the next line of the dynamic USB name ("ttyUSB0"). Now edit the .rules file and set the KERNELS parameter to the USB port value.

# set the udev rule , make the device_port be fixed
#
KERNELS=="1-2:1.0", MODE:="0777", SYMLINK+="<some_name>"

Again, save and restart the service:

sudo service udev reload
sudo service udev restart
⚠️ **GitHub.com Fallback** ⚠️