Create named aliases for your USB devices #usb #linux


ki7uez@...
 

Create udev rules for ttyUSB devices

1 Create udev rules for ttyUSB devices

The Linux kernel does not always enumerate USB devices in the same order. This makes knowing what is attached to the other end of a ttyUSB UART like playing roulette. Here's how to make a named alias that lets you know what is attached to the UART. This relies on the USB device having unique serial numbers or strings. Knockoff brands of cables, or cheap cables may not permit the use of this technique. It is best to spend a little more for well behaved USB cables. It also best to order them from a reputable source.

1.1 Get the properties from the USB device

udevadm info --query=all --name=/dev/ttyUSB1
P: /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/ttyUSB1/tty/ttyUSB1
N: ttyUSB1
S: serial/by-id/usb-FTDI_FT232R_USB_UART_AL02A2I5-if00-port0
S: serial/by-path/pci-0000:00:14.0-usb-0:2:1.0-port0
E: DEVLINKS=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL02A2I5-if00-port0 /dev/serial/by-path/pci-0000:00:14.0-usb-0:2:1.0-port0
E: DEVNAME=/dev/ttyUSB1
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/ttyUSB1/tty/ttyUSB1
E: ID_BUS=usb
E: ID_MM_CANDIDATE=1
E: ID_MODEL=FT232R_USB_UART
E: ID_MODEL_ENC=FT232R\x20USB\x20UART
E: ID_MODEL_FROM_DATABASE=FT232 Serial (UART) IC
E: ID_MODEL_ID=6001
E: ID_PATH=pci-0000:00:14.0-usb-0:2:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_0
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_INTERFACE_FROM_DATABASE=XHCI
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_REVISION=0600
E: ID_SERIAL=FTDI_FT232R_USB_UART_AL02A2I5
E: ID_SERIAL_SHORT=AL02A2I5
E: ID_TYPE=generic
E: ID_USB_DRIVER=ftdi_sio
E: ID_USB_INTERFACES=:ffffff:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=FTDI
E: ID_VENDOR_ENC=FTDI
E: ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
E: ID_VENDOR_ID=0403
E: MAJOR=188
E: MINOR=1
E: SUBSYSTEM=tty
E: TAGS=:systemd:
E: USEC_INITIALIZED=29075257

1.2 Get the unique identifier

The udevadm results above are for a well behaved FTDI USB UART. This allows a unique identifier to be isolated:

E: ID_SERIAL=FTDI_FT232R_USB_UART_AL02A2I5
E: ID_SERIAL_SHORT=AL02A2I5

1.3 Create a new udev rule

Using the unique identifier, create or update an existing udev rule. The leading numeric values signal the load order to the kernel.

cd /etc/udev/rules.d
ls
| 70-persistent-usb.rules   |

1.3.1 Choose 70-persistent-usb.rules

Edit the rules file and add rules for your device

# Make the kernel set the permissions to 664 for pluggable devices
KERNEL=="ttyUSB[0-9]*", NAME="tts/%n", GROUP="dialout", MODE="0664"

# Create some aliases. This shows how to use a well behaved, and a poorly behaved
# device to add nodes. FTDI provides unique SERIAL number strings, which is really
# nice. Prolific, by comparison, behaves poorly. 
SUBSYSTEM=="tty", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_AL02A2I5", SYMLINK+="tnc1"
SUBSYSTEM=="tty", ENV{ID_SERIAL}=="Prolific_Technology_Inc._USB-Serial_Controller", SYMLINK+="linuxconsole"
SUBSYSTEM=="tty", ENV{ID_SERIAL}=="067b_2303", SYMLINK+="kvm0000-serial"

1.4 Restart the udev daemon

When your changes are complete you need to restart the udev daemon. I use:

sudo systemctl restart systemd-udevd

1.5 Check the results

You should now have symbolic links between a constant name and the USB device that will enumerate with different device names. The link is owned by root, which is expected. The actual device will be in the dialout group.

ls -la /dev/linuxconsole
: lrwxrwxrwx. 1 root root 7 Sep  9 07:37 /dev/linuxconsole -> ttyUSB1 

Author: Johnathan Mantey

Created: 2020-11-10 Tue 16:47

Validate


KC7NYR
 

Thank you Johnathan, I appreciate your input on the Linux User Net and following up with this information here. 


Russ, KC7MM
 

Thank you for this, Johnathon, and thanks for your help in making a UDEV rule that sets permissions and group ownership on the /dev/hidraw device for my Expert E-coder USB box. That's an auxiliary device with a tuning knob and programmable buttons that works with my SunSDR2 DX transceiver and ExpertSDR software. I have posted details on my Web site.


ki7uez@...
 

I could only listen to the 10 Aug 2021 net tonight.
The repeater I normally use, 147.625, was silent.
I was able to listen on 442.325. All my attempts to comment failed.

For KC7GDB and KC7MM, I recommend you read this post and attempt to configure your USB devices using UDEV rules. If your USB devices are well behaved (see above), you will be able to create /dev symbolic links that have names of your choice. The name will be repeatable, regardless of how many USB devices you insert. The key being well behaved USB devices.

It is a simple matter to modify the above for GPS devices. I believe KC7GDB said the GPS enumerated as /dev/acm. If you issue this command:
udevadm info --query=all --name=/dev/acm
You will get a list of properties that can be used to uniquely identify the device. You can create udev rules, as described above.

As to the by_path and by_id linking, I think you'll find that by_id will be the same for devices built by the same vendor. You will, most likely, find this to be no solution to your problem at all.


KC7NYR
 

Thank you Johnathan, Ki7UEZ! We appreciate your post and this valuable information.

Also for repeater coverage, please try the 444.400 with 100hz tone. Let us know if this works any better for you, we would love your feedback on this repeater.


73
Mark, KC7NYR