I figured it out. I was sure that what I was missing was something basic: tvheadend was also installed in TurrisOS and was configured to start automatically. This means it was taking over the tuner so it was unavailable to the container. I stopped the tvheadend service in TurrisOS using LuCI and also disabled autostart for it. I also stopped the tvheadend service in the container and then the w_scan2 utility was able detect and use the tuner. There are some weird things I encountered along the way that is probably best to share:
– First of all, one of the reasons why I tried to run tvheadend inside an LXC container was because I couldn’t get tvheadend in TurrisOS to find any channels. The tuner – in my case Astrometa DVB T/T2/C aka HanfTek aka Rafael Micro R828D – has two chipsets inside Realtek RTL2832P and Panasonic MN88473 handling different network types. I was interested in the MN88473 in particular because it handles the DVB-C that I need. This chipset requires binary firmware to be placed in /lib/firmware, which I obtained from the OpenELEC GitHub repository.
Anyway, tvheadend running on TurrisOS properly detected the tuner frontends, both Realtek and Panasonic; dmesg showed the firmware was loaded properly, but scanning didn’t work. Furthermore, scanning with the w_scan command line utility also didn’t find anything. I put the same tuner in a computer with Linux Mint, used the same firmware from OpenELEC and used Kaffeine to scan channels. It worked. This indicated to me there is something wrong with the setup in TurrisOS and/or tvheadend on TurrisOS. Since Mint is based on Ubuntu and since I read reports on this forum about tvheadend success with Ubuntu containers, I decided to give the container approach a try.
The other reason was security. I want to expose this publicly and it’s better if it runs in a container rather than on the main router OS. Since now I managed to get it to work in tvheadend in an Ubuntu container and actually scan and find channels, it’s further indication that there’s something wrong with the tvheadend setup in TurrisOS or in the way the userspace communicates with the driver. One final note on this, when you test with w_scan you have to first stop the tvheadend service.
– The LXC configuration that worked for me was this:
#TV Tuner
lxc.cgroup.devices.allow = c 189:* rwm
lxc.mount.entry = /dev/bus/usb/004 dev/bus/usb/004 none bind,optional,create=dir 0 0
lxc.cgroup.devices.allow = c 212:* rwm
lxc.mount.entry = /dev/dvb dev/dvb none bind,optional,create=dir 0 0
Please note that there are various instructions on this forum and in the wiki that use lxc.group.devices.allow
instead of lxc.cgroup.devices.allow
. Also, there are also instructions that did not have the 0 0
after create=dir
. Without adding this, the directories were not created for me. I needed to add the 0 0
.
– After I stopped tvheadend under TurrisOS, w_scan2 in the container was able to see the tuners and find something on scan. However, tvheadend in container was still not able to see the tuners. Then I remembered reading someone saying on this forum that they had to run tvheadend as root for the scan to work.
By default tvheadend runs as user hts with group video. The devices under /dev/dvb/adapter0 are owned by root and group video. The group has rw permissions, so technically running tvheadend as hts with group video should work out of the box, but for some reason it didn’t.
I modified the tvheadend config in /etc/default/tvheadend and changed the user from hts to root and restarted the service. Now, this causes a different problem, because the service reads the user-specific config for the web interface from .hts/tvheadend in the user’s home directory and of course there is no such directory for root if you went through the setup wizard when tvheadend was running as hts. So I couldn’t log into the tvheadend web interface anymore. At this point I decided to stop the service, edit the /etc/default/tvheadend config again and change the service user from root back to hts. Once I did that and started the service again it suddenly started identifying the TV tuners. Why? I have no idea, but it worked and appears to continue to work even across container restart.
I hope this whole experience helps someone. My case applied to:
Turris OS version 3.11.14
Kernel version 4.4.199-a890a5a94ebb621f8f1720c24d12fef1-0
LXC Container Ubuntu Bionic