[SOLVED] RTL2838 DVB-T USB dongle as ADS-B receiver in lxc container

Thank you for the hint, that lead me to the solution ... for no obvious reason the /dev/bus/usb/ changed from 001 to 002 :(

So the final working configuration is:
Code:
lxc.cgroup2.devices.allow: c 212:* rwm
lxc.mount.entry: /dev/dvb dev/dvb none bind,optional,create=dir 0 0
lxc.mount.entry: /dev/bus/usb/002 dev/bus/usb/002 none bind,create=dir
lxc.idmap: u 0 100000 65535
lxc.idmap: g 0 100000 46
lxc.idmap: g 46 46 1
lxc.idmap: g 47 100047 65488
 
Last edited:
Hey I've solved it by making the mountpoint writable by all on the proxmox host. In your case:

Code:
chmod 0666 /dev/bus/usb/001

Probably better to make a group for it on the host and map the right uid and gid like avw did though.
Thank you, in my case I fired chmod 0666 /dev/bus/usb/002/003 as this is my rtl-device. I only needed to forward the usb-device without /dev/dvb or something else. Just added to my config:

Code:
lxc.cgroup.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/002/003 dev/bus/usb/002/003 none bind,optional,create=file
and ran chmod on the host.
 
I'm facing a problem with the usb device numbering. After my usb-dongle gets disconnected a new usb device number is assigned on reconnect. Can I also passthrough /dev/dvb/ only as this is static?
 
hi there,
i´ve the same dongle as bgs an trying to get fr24 to work with it on a 22.04 LTS Container on pve 7.2_11.
Same problem that rtl_test works on host but fails on guest.
So i tried the conf of bgs.
Now the container doesn´t even start. The says "connection failed with error code 1006"
When i delete the last 4 lines (those with idmap) in the conf the container starts but rtl_test still fails.
I´m a bloody newbie on linux. Could somebody help me? thanx in advance ;)
 
Hi @quinti and the rest :)

I am struggling with the same problem right now. The basis is exactly the same hardware. I have created a new CT in the PVE with Ubuntu. I have put the USB parameters into the configuration. This is also passed through, if I interpret this correctly. The necessary chmod commands were also sent. Is anyone able to help me here please?

host
Code:
root@proxmox:~# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 019: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 003: ID 0bda:0153 Realtek Semiconductor Corp. 3-in-1 (SD/SDHC/SDXC) Card Reader
Bus 001 Device 002: ID 8087:0a2a Intel Corp. Bluetooth wireless interface
Bus 001 Device 020: ID 1a86:7523 QinHeng Electronics CH340 serial converter
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

host
Code:
ls -l /dev/bus/usb/001/019
crw-rw-rw- 1 100000 100000 189, 18 Feb  7 15:18 /dev/bus/usb/001/019

vi /etc/pve/lxc/102.conf
Code:
lxc.cgroup.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/001/019 dev/bus/usb/001/019 none bind,optional,create=file

host
Code:
root@proxmox:~# rtl_test
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001


Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
[R82XX] PLL not locked!
Sampling at 2048000 S/s.


Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.


Reading samples in async mode...
Allocating 15 zero-copy buffers
lost at least 60 bytes
^CSignal caught, exiting!


User cancel, exiting...
Samples per million lost (minimum): 14

CT
Code:
root@flightradar:~# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 019: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 003: ID 0bda:0153 Realtek Semiconductor Corp. 3-in-1 (SD/SDHC/SDXC) Card Reader
Bus 001 Device 002: ID 8087:0a2a Intel Corp.
Bus 001 Device 020: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Code:
root@flightradar:~# ls -l /dev/bus/usb/001/019
---------- 1 root root 0 Feb  7 14:27 /dev/bus/usb/001/019

Code:
root@flightradar:~# rtl_test
Found 1 device(s):
  0:  , , SN:


Using device 0: Generic RTL2832U OEM
usb_claim_interface error -99
Failed to open rtlsdr device #0.

Do you have any thoughts?
 
That's what I did, and it works fine with MythTV.
After my pve crashed and i rebuilt so many things up i'm failing here again. On the old pve i ended up with mapping the usb device instead of the dvb device. @leesteken can you tell me what i am doing wrong here:
Code:
root@pve:~# ls -al /dev/dvb/adapter0/
total 0
drwxr-xr-x 2 root root     120 Aug 25 15:47 .
drwxr-xrwx 3 root root      60 Aug 25 15:47 ..
crw-rw---- 1 root video 212, 0 Aug 25 15:47 demux0
crw-rw---- 1 root video 212, 1 Aug 25 15:47 dvr0
crw-rw---- 1 root video 212, 3 Aug 25 15:47 frontend0
crw-rw---- 1 root video 212, 2 Aug 25 15:47 net0
root@pve:~# ls -aln /dev/dvb/adapter0/
total 0
drwxr-xr-x 2 0  0    120 Aug 25 15:47 .
drwxr-xrwx 3 0  0     60 Aug 25 15:47 ..
crw-rw---- 1 0 44 212, 0 Aug 25 15:47 demux0
crw-rw---- 1 0 44 212, 1 Aug 25 15:47 dvr0
crw-rw---- 1 0 44 212, 3 Aug 25 15:47 frontend0
crw-rw---- 1 0 44 212, 2 Aug 25 15:47 net0

root@ads-b:~# getent group sasl
sasl:x:45:
root@ads-b:~# getent group video
video:x:44:
Should result in the same config like yours...
Code:
lxc.idmap: u 0 100000 65535
lxc.idmap: g 0 100000 44
lxc.idmap: g 44 44 1
lxc.idmap: g 45 100045 65490
lxc.cgroup2.devices.allow: c 212:* rwm
lxc.mount.entry: /dev/dvb dev/dvb none bind,create=dir 0 0
...but starting the container fails...
Code:
root@pve:~# pct start 106
lxc_map_ids: 3701 newgidmap failed to write mapping "newgidmap: gid range [44-45) -> [44-45) not allowed": newgidmap 3377377 0 100000 44 44 44 1 45 100045 65490
lxc_spawn: 1788 Failed to set up id mapping.
__lxc_start: 2107 Failed to spawn container "106"
startup for container '106' failed
...until i comment out lxc.idmap: g 44 44 1 but then rtl_sdr has errors.
So what's the way you made this config?
 
lxc_map_ids: 3701 newgidmap failed to write mapping "newgidmap: gid range [44-45) -> [44-45) not allowed": newgidmap 3377377 0 100000 44 44 44 1 45 100045 65490
If the mapping is not allowed, check your /etc/subgid (which I always forget) if there is a line in there with root:44:1, otherwise root is not allowed to map to groupid 44. Same with /etc/subuid if the error is about newuidmap.
 
If the mapping is not allowed, check your /etc/subgid (which I always forget) if there is a line in there with root:44:1, otherwise root is not allowed to map to groupid 44. Same with /etc/subuid if the error is about newuidmap.
You're right, I needed to add this to /etc/subgid. Now I see the mapping:
Code:
root@ads-b:~# ls -la /dev/dvb/adapter0/
total 0
drwxr-xr-x 2 nobody nogroup    120 Aug 25 13:47 .
drwxr-xrwx 3 nobody nogroup     60 Aug 25 13:47 ..
crw-rw---- 1 nobody video   212, 0 Aug 25 13:47 demux0
crw-rw---- 1 nobody video   212, 1 Aug 25 13:47 dvr0
crw-rw---- 1 nobody video   212, 3 Aug 25 13:47 frontend0
crw-rw---- 1 nobody video   212, 2 Aug 25 13:47 net0
But rtl-sdr still doesn't like me...
Code:
root@ads-b:~# rtl_test
Found 1 device(s):
  0:  , , SN: `,

Using device 0: Generic RTL2832U OEM
usb_open error -4
Failed to open rtlsdr device #0.
Can I determine wether the problem is proxmox or hardware/rtl_sdr related? (Maybe a read test on some file?)
 
Can I determine wether the problem is proxmox or hardware/rtl_sdr related? (Maybe a read test on some file?)
It works with mythtv-backend. I don't know rtl_sdr and cannot help. Find out what files/directories/permissions it needs and try to provide those. Also make sure to load the necessary drivers and firmware (which you usually need to download yourself from somewhere) on the Proxmox host. Check the logs on the host to see if you need something there.
 
It works with mythtv-backend. I don't know rtl_sdr and cannot help. Find out what files/directories/permissions it needs and try to provide those. Also make sure to load the necessary drivers and firmware (which you usually need to download yourself from somewhere) on the Proxmox host. Check the logs on the host to see if you need something there.
Sooo rtl-sdr uses libusb so i was forced to passtrough my usb device:
  • lsusb -> select device
  • ls -l /dev/bus/usb/<bus>/<device> and remember first number (whatever this is, didnt find in the web)
  • added to config:
    Code:
    lxc.cgroup2.devices.allow: c <remembered first number>:* rwm
    lxc.mount.entry: /dev/bus/usb/<bus>/<device> dev/bus/usb/<bus>/<device> none bind,optional,create=file
  • started the container and ran rtl_test which was not successful
  • chmod 0666 /dev/bus/usb/<bus>/<device>
I think i have to do chmod every boot so I'll add it to rc.local
 
I have a second variant which I think is better:
  1. Pass through all USB busses
    Code:
    lxc.cgroup2.devices.allow: c <remembered first number>:* rwm
    lxc.mount.entry: /dev/bus/usb/<bus> /dev/bus/usb/<bus> none bind,optional,create=dir
    lxc.mount.entry: /dev/bus/usb/<bus>+1 /dev/bus/usb/<bus>+1 none bind,optional,create=dir
    lxc.mount.entry: /dev/bus/usb/<bus>+n /dev/bus/usb/<bus>+n none bind,optional,create=dir
  2. Add a custom script and place it somewhere (I use /root/) to set the chmod for the right device. Adjust the second line for the model of your SDR that is shown with lsusb. Also if you want to restart services inside the LXC after setting the permissions adjust the container id "106" in the second if-statement with your id. In my case i restart my readsb service which consumes the SDR.
    Bash:
    #!/bin/bash
    usbmapping=$(lsusb | grep "RTL2838")
    if [ $? -ne 0 ]; then
        echo "ERROR: NO SDR for ADS-B available. Exiting."
        exit 1
    fi
    
    bus=$(echo "$usbmapping" | cut -d" " -f2)
    device=$(echo "$usbmapping" | cut -d" " -f4 | cut -c -3)
    
    chmod 0666 /dev/bus/usb/$bus/$device
    
    if [ $? -eq 0 ]; then
        echo "INFO: chmod on SDR USB port /dev/bus/usb/$bus/$device successful."
    
        /usr/sbin/pct status 106 | grep running > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            #Restart SDR reader
            echo "Restarting readsb on guest 106"
            /usr/sbin/pct exec 106 systemctl restart readsb.service
        fi
    else
        echo "ERROR: chmod on SDR USB port not successful"
        exit 1
    fi
  3. [Optionally] Add Script to cron to restart every night in case you reconnect USB:
    Code:
    # For ADS-B LXC Container
    0 0 * * * /root/grantPermissionsOnPassedThroughUsbDevices.sh
  4. Add hookscript to apply permissions before the start of the container. Add the Snippets category to an storage ("local" in my case) and copy default script cp /usr/share/pve-docs/examples/guest-example-hookscript.pl /var/lib/vz/snippets/usbshare.pl and adjust the pre-start phase:
    Perl:
    if ($phase eq 'pre-start') {
        # First phase 'pre-start' will be executed before the guest
        # is started. Exiting with a code != 0 will abort the start
    
        my $exitCode = system("/bin/bash /root/grantPermissionsOnPassedThroughUsbDevices.sh");
        $exitCode = $exitCode >> 8;
        print "Exit code of bash script: $exitCode\n";
        exit $exitCode;
    
        # print "preparations failed, aborting."
        # exit(1);
    
    }
  5. Activate script pct set 106 -hookscript local:snippets/usbshare.pl (thats why we need the storage (here "local") ready for Snippets)
  6. Check if the hookscript is being called on startup of the container.
 
  • Like
Reactions: Wi-en-a

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!