USB Passthrough: device location changing


Recommended Posts

Hi,

 

I am trying to run flightradar24 data feeder with a USB dongle. 

 

I successfully connect to the dongle with device number, example: /dev/bus/usb/001/012.

 

However, this location changes after a few hours to the next available spot, i.e. /dev/bus/usb/001/013.

 

This happens after a few hours every time the image is started. 

 

Any clues to how or why this can happen? Thanks

Edited by phithor
Link to comment
  • 4 weeks later...

You need to set up a persistent name for the usb device based on its usb-id. There is a tutorial for doing that here http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/ You will also probably need to figure out how to get unraid to regenerate the udev rules every reboot.

Edited by aeleos
  • Like 2
Link to comment
  • 4 weeks later...
  • 1 month later...

For any other looking to do the same:

 

1. To see usb devices: lsusb

2. Found the one, for me: /dev/bus/usb/001/004,  0bda:2838 (flightradar DVB-T dongle)

3. Ran code to get serial number: udevadm info -a -n /dev/bus/usb/001/004 | grep '{serial}' | head -n1

Response: ATTR{serial}=="00000001"

 

4. Added new file in  /etc/udev/rules.d: 99-usb-rules.rules with content:

vi /etc/udev/rules.d/99-usb-rules.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", ATTRS{serial}=="00000001", SYMLINK+="flightradar"

 

5. To get this to persist through reboots i copied the files to /boot/config/rules.d/99-usb-rules.rules:

cp /etc/udev/rules.d/99-usb-rules.rules /boot/config/rules.d/99-usb-rules.rules

 

6. Then in the file /boot/config/go i added a command to copy it back on boot:

vi /boot/config/go

Add:

cp /boot/config/rules.d/99-serial-rules.rules /etc/udev/rules.d/99-serial-rules.rules

chmod 644 /etc/udev/rules.d/99-serial-rules.rules (not sure if it is required but it the permissions now match the other files in the folder)

 

 

Not sure if this is run before usb is initialized, so you might have to reinsert the device after boot to get the symlink recognized.

 

I will test it and report.

 

EDIT: Seems like it is not recognized on boot.

 

EDIT2: It is working!

Edited by phithor
Link to comment

No luck for me either. I've just tried this too using User Scripts to execute the copy of these rules from my boot USB at disk startup just like you've done with go. I can confirm that the right file is in the right place according to the tutorial linked in aeleos.

 

I wonder if the copy doesn't happen early enough in startup and the rules have already been run by the time they get copied.

 

If anyone else has had luck doing this, please let us know.

Link to comment

With a little bit of studying and experimentation I got this to work but I'm sure someone more experienced with udev would get this better I used the "User Scripts" app to setup a startup script that copies and refreshes the rules for the device so that the rules you setup in "99-usb-rules.rules" are loaded properly.

 

Here it is:

#!/bin/bash
# copy persistent script from usb drive to drive at startup
cp /boot/config/userFiles/99-usb-serial.rules /etc/udev/rules.d/
chmod 644 /etc/udev/rules.d/99-usb-serial.rules

# udav has likely run before the copy completes so udev needs its rules refreshed
udevadm control --reload-rules

# a reset of the device is needed so the rules just copied can take hold
udevadm trigger --attr-match=subsystem=tty

I'm a little nervous about the last line resetting all tty subsystems since I wasn't able to get something like :

udevadm trigger --attr-match=serial=0000:00:11.0

to work for some reason after confirming the serial with:

udevadm info -a -n /dev/ttyUSB1 | grep '{serial}' | head -n1

Here are some links for education:

http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/

https://www.thegeekdiary.com/beginners-guide-to-udev-in-linux/

http://reactivated.net/writing_udev_rules.html

https://unix.stackexchange.com/questions/39370/how-to-reload-udev-rules-without-reboot

http://www.reactivated.net/writing_udev_rules.html#example-printer

https://askubuntu.com/questions/445735/why-do-my-udev-rules-run-if-i-use-udevadm-trigger-but-not-at-boot-time/635477

https://www.linux.com/news/udev-introduction-device-management-modern-linux-system

 

If you run into any commands that look like they're aren't installed be conscious that udev changed a bit since some of these were written and there are new commands for these (e.g. udevadm info instead of udevinfo).

 

  • Thanks 2
Link to comment
  • 3 months later...
On 8/5/2018 at 4:14 AM, MindRazorblade said:

With a little bit of studying and experimentation I got this to work but I'm sure someone more experienced with udev would get this better I used the "User Scripts" app to setup a startup script that copies and refreshes the rules for the device so that the rules you setup in "99-usb-rules.rules" are loaded properly.

 

Here it is:


#!/bin/bash
# copy persistent script from usb drive to drive at startup
cp /boot/config/userFiles/99-usb-serial.rules /etc/udev/rules.d/
chmod 644 /etc/udev/rules.d/99-usb-serial.rules

# udav has likely run before the copy completes so udev needs its rules refreshed
udevadm control --reload-rules

# a reset of the device is needed so the rules just copied can take hold
udevadm trigger --attr-match=subsystem=tty

I'm a little nervous about the last line resetting all tty subsystems since I wasn't able to get something like :


udevadm trigger --attr-match=serial=0000:00:11.0

to work for some reason after confirming the serial with:


udevadm info -a -n /dev/ttyUSB1 | grep '{serial}' | head -n1

Here are some links for education:

http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/

https://www.thegeekdiary.com/beginners-guide-to-udev-in-linux/

http://reactivated.net/writing_udev_rules.html

https://unix.stackexchange.com/questions/39370/how-to-reload-udev-rules-without-reboot

http://www.reactivated.net/writing_udev_rules.html#example-printer

https://askubuntu.com/questions/445735/why-do-my-udev-rules-run-if-i-use-udevadm-trigger-but-not-at-boot-time/635477

https://www.linux.com/news/udev-introduction-device-management-modern-linux-system

 

If you run into any commands that look like they're aren't installed be conscious that udev changed a bit since some of these were written and there are new commands for these (e.g. udevadm info instead of udevinfo).

 

 

First thanks for your script. *Thumbs up*

The other thing..I tried to get it succesfully running using UserScript (StartUp at first Array start) but didnt survived any reboot until I noticed that you are resting tty but I use SUBSYSTEM=="usb" so the correct syntax for this thread would be.

udevadm trigger --attr-match=subsystem=usb

A short info in your post would have saved me 2 hours. :D

 

Link to comment
  • 2 months later...
  • 11 months later...
On 8/3/2018 at 8:55 AM, phithor said:

5. To get this to persist through reboots i copied the files to /boot/config/rules.d/99-usb-rules.rules:

cp /etc/udev/rules.d/99-usb-rules.rules /boot/config/rules.d/99-usb-rules.rules

 

I had to mkdir /boot/config/rules.d - anything else worked as you said! Thanks for the precise instruction

Link to comment
  • 2 months later...

Halleluja it is working! This was a real pain.

 

As you mentioned the udev-rules run before or after the "/boot/config/go" script. Seems that this depends on each case and therefore is a prime example of a race-condition. The developers should have a look at this IMHO.

 

I attached the trigger command directly to the boot script, saving the "User Scripts" App.

My "/boot/config/go" :

#!/bin/bash
# Start the Management Utility
/usr/local/sbin/emhttp &

# add udev at boot
cp /boot/config/rules.d/90-usb.rules /etc/udev/rules.d/90-usb.rules
chmod 644 /etc/udev/rules.d/90-usb.rules
udevadm trigger --attr-match=subsystem=tty

 

The reload command was not necessary in my case. 🤷‍♂️

Link to comment
  • 8 months later...

Hey there-I've tried to reproduce this for my FlightAware USB device and I keep getting the following error:

rtlsdr: error querying device #0: No such file or directory

I think I've got it configured properly, as here's the lsusb/dev output:

root@unRaid:/dev# ls -l flightradar
lrwxrwxrwx 1 root root 15 Jan  4 16:50 flightradar -> bus/usb/001/023
root@unRaid:/dev# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 001 Device 023: ID 0bda:2832 Realtek Semiconductor Corp. RTL2832U DVB-T
Bus 001 Device 005: ID 8087:0aaa Intel Corp.
Bus 001 Device 004: ID 0b05:1872 ASUSTek Computer, Inc. AURA LED Controller
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

But the FW24 docker container won't start with /dev/flightaware as its RTL-SDR Device. I have the following script configured to run hourly:

#!/bin/bash
# copy persistent script from usb drive to drive at startup
cp /boot/config/rules.d/99-usb-rules.rules /etc/udev/rules.d/
chmod 644 /etc/udev/rules.d/99-usb-rules.rules

# udav has likely run before the copy completes so udev needs its rules refreshed
udevadm control --reload-rules

# a reset of the device is needed so the rules just copied can take hold
udevadm trigger --attr-match=subsystem=usb

Off this .rules config:

root@unRaid:/etc/udev/rules.d# more 99-usb-rules.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2832", ATTRS{serial}=="00001000", SYMLINK+="flightradar"

Can anyone help point me in the right direction? I just don't seem able to to get this to work, even though it looks like it should be just fine to me...

Link to comment
On 1/6/2021 at 2:46 PM, polishprocessors said:

but that doesn't seem to work...

usb2: usb to ethernet devices in a vm running opensense

 

This is the log entry:

-device usb-host,hostbus=1,hostaddr=3,id=hostdev0,bus=usb.0,port=1 \
-device usb-host,hostbus=2,hostaddr=6,id=hostdev1,bus=usb.0,port=2 \
-device usb-host,hostbus=2,hostaddr=7,id=hostdev2,bus=usb.0,port=3 \

 

The is the xml portion :

<hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x07a6'/>
        <product id='0x8515'/>
        <address bus='1' device='3'/>
      </source>
      <address type='usb' bus='0' port='1'/>
    </hostdev>
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x07a6'/>
        <product id='0x8515'/>
        <address bus='2' device='6'/>
      </source>
      <address type='usb' bus='0' port='2'/>
    </hostdev>
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x07a6'/>
        <product id='0x8515'/>
        <address bus='2' device='7'/>
      </source>
      <address type='usb' bus='0' port='3'/>
    </hostdev>

 

The vm runs normally on a manual config and I see all 3 usb devices in opensense.

 

root@Tower:/etc/udev/rules.d# cat 99-usb-rules.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek, Inc. AN8515 Ethernet"

 

root@Tower:/boot/config/rules.d# cat 99-usb-rules.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek, Inc. AN8515 Ethernet"

 

The go file :

 

#!/bin/bash
# Start the Management Utility
/usr/local/sbin/emhttp &
cp /boot/config/rules.d/99-usb-rules.rules /etc/udev/rules.d/99-usb-rules.rules
chmod 644 /etc/udev/rules.d/99-usb-rules.rules
udevadm trigger --attr-match=subsystem=tty

 

Cannot get a persistent link to usb devices after a vm shutdown and startup.

 

Got it working :

 

The word symlink did not cross my mind...

 

Had to read this : http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/

a few times to figure I had to do this :

 

renamed 99-usb-rules.rules  to 99-usb-serial.rules

 and changed this :

 

SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek, Inc. AN8515 Ethernet"

 

to this :

 

root@Tower:/boot/config/rules.d# cat 99-usb-serial.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek0"
SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek1"
SUBSYSTEM=="usb", ATTRS{idVendor}=="07a6", ATTRS{idProduct}=="8515", ATTRS{serial}=="0001", SYMLINK+="ADMtek2"

 

Now have to figure out which one comes first in order to get the ethernet to be in the right order i.e. WAN,LAN,OPT1

 

Not solved Usb to mac address issue need to resolve : https://github.com/eborisch/ethname

 

 

Edited by flamegrilled
ethernet address
Link to comment

I've run through the steps here and am having some issues, wondering if anyone can spot a problem.

 

I have /boot/config/rules.d/99-usb-rules.rules with the file

SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="1234", ATTRS{serial}=="myserial1", SYMLINK+="zigbee"
SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="1234", ATTRS{serial}=="myserial2, SYMLINK+="zwave"

I have the UserScripts addon set to start 'At First Array Start Only' 

#!/bin/bash
# add this to UserSctipt - StartUp at first Array start

# Start the Management Utility
/usr/local/sbin/emhttp &

# copy persistent script from usb drive to drive at startup
cp /boot/config/rules.d/99-usb-rules.rules /etc/udev/rules.d/
chmod 644 /etc/udev/rules.d/99-usb-rules.rules

# udav has likely run before the copy completes so udev needs its rules refreshed
udevadm control --reload-rules

# a reset of the device is needed so the rules just copied can take hold
udevadm trigger --attr-match=subsystem=tty

Please note -- I added both the Start Management Utility and Reload rules parameters. Not sure if I require both. 

 

Script output at start of array:

Script Starting Jan 09, 2021 06:33.01

Full logs for this script are available at /tmp/user.scripts/tmpScripts/99-usb-rules/log.txt

emhttpd is already started
Script Finished Jan 09, 2021 06:33.01

Full logs for this script are available at /tmp/user.scripts/tmpScripts/99-usb-rules/log.txt

 

On reboot of my system and start of array:

  1. there are no USB devices listed in /dev/  - they are usually listed as /dev/ttyUSB0 and /dev/ttyACM0. Unplugging and plugging back the USB devices gets them recognized.
  2. the devices ARE recognized with lsusb in terminal BEFORE unplugging and plugging back in
Edited by Rick_Sanchez
Clarification
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.