Category Archives: Linux

Install TVHeadend in a Proxmox LXC Container running Ubuntu 16.04

TVHeadend is my favourite TV Server.

There weren’t too many battles setting up the install but there were some.

Step 1 of course is to create your “CT’. It doesn’t need much so I just gave it the following:

root@pve01:/etc/pve/lxc# cat 102.conf 
#TVHeadend
#Plex
#SABnzbd
#CouchPotato
#Sonarr
arch: amd64
cpulimit: 4
cpuunits: 4096
hostname: media
memory: 4096
net0: name=eth0,bridge=vmbr1,gw=10.69.10.1,hwaddr=00:0A:DE:01:02:10,ip=10.69.10.43/24,ip6=auto,tag=10,type=veth
onboot: 1
ostype: ubuntu
rootfs: ssdmirror:subvol-102-disk-1,size=32G
startup: order=4,up=5,down=5
swap: 4096
root@pve01:/etc/pve/lxc#

4 cores, 4 gigs of RAM/swap and a 32G disk. This is because I’ll also have Plex, SABnzbd, CouchPotato and Sonar in the same CT.

A few things tripped me up. The debian sources aren’t optimal for me, the local timezone wasn’t set, and TVH wouldn’t auto start.

After creating CT, some housekeeping:

root@media:/home/hts/.hts# cat /etc/apt/sources.list
deb http://au.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://au.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://au.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu xenial partner
deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse

### TVH source
deb https://dl.bintray.com/tvheadend/ubuntu stable main

Those “au” ones are much better for Australia.  You can possibly find even faster ones with this guide, although I don’t know if that works with Ubuntu. It certainly works in Debian.

The “tvheadend” source for Ubuntu is as per here:  I just go the sable branch, as I’m not after any new features and like things to not break. The stable branch is regularly updated so I don’t feel like I’m missing out.

The timezone wasn’t set so I fixed that with:

dpkg-reconfigure tzdata

Then I went to work with apt:

apt-get update
apt-get dist-upgrade
apt-get autoremove
apt-get install tvheadend

I started tvheadend with “service tvheadend start” and saw it all looked good. The only problem is that it doesn’t start on reboot. I traced this down with a google search to the installer being not quite compatible with systemd, but there is a fix that works fine for me (as per this bug ID: https://tvheadend.org/issues/3027)

root@media:~# systemctl enable tvheadend.service
tvheadend.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable tvheadend
root@media:~#

 Picons

For Australia you can get the TV icons by:

cd /usr/src
git clone https://bitbucket.org/beyonwiz/picons-australia.git

Then prefer picons over channel names in the settings and set the path to:

file:///usr/src/picons-australia/picon

 Migrating from another Server

I found this post to be very handy. In a nutshell:

## the "FROM" box
sudo service tvheadend stop
sudo -s
cd /home/hts/.hts
sudo tar cvfp ../tvheadend.tar tvheadend
cd /home/hts/

## the "TO" box
new box
sudo service tvheadend stop
sudo -s
cd /home/hts/.hts
sudo mv tvheadend tvheadend-backup
tar xvfp ~/tvheadend.tar

I was very glad I didn’t need to manually copy all my old settings across!

 

Install dnsmasq in a Proxmox LXC Container running Ubuntu 16.04

dnsmasq is a very handy DHCP server for the LAN. I also use it as a DNS forwarder, so I can use hostnames for all my virtual machines under the gavowen.local domain.

I had a few little battles setting this up so thought I’d share the step by step.

Step 1 of course is to create your “CT’. It doesn’t need much so I just gave it the following:

root@pve01:/etc/pve/lxc# cat 100.conf
#dnsmasq DNS/DHCP server%0A%0A
arch: amd64
cpulimit: 1
cpuunits: 1024
hostname: dnsmasq
memory: 512
nameserver: 203.8.183.1 192.189.54.17
net0: name=eth0,bridge=vmbr1,gw=10.69.10.1,hwaddr=00:0A:DE:01:00:10,ip=10.69.10.41/24,ip6=auto,tag=10,type=veth
onboot: 1
ostype: ubuntu
rootfs: ssdmirror:subvol-100-disk-1,size=8G
searchdomain: gavowen.local
startup: order=1,up=10,down=5
swap: 512

1 core, half a gig of RAM/swap and a 8G disk is plenty. That’s by standard amount for smaller containers (CTs).

A few things tripped me up. The debian sources aren’t optimal for me, the local timezone wasn’t set, and “resolvconf” was screwing up dnsmasq.

After creating the CT, some housekeeping:

root@media:/home/hts/.hts# cat /etc/apt/sources.list
deb http://au.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://au.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://au.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu xenial partner
deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse

Those “au” ones are much better for Australia.  You can possibly find even faster ones with this guide, although I don’t know if that works with Ubuntu. It certainly works in Debian.

The timezone wasn’t set so I fixed that with:

dpkg-reconfigure tzdata

Then I went to work with apt:

apt-get update
apt-get dist-upgrade
apt-get autoremove
apt-get remove resolvconf
apt-get install dnsmasq

The resolvconf fix I found here.  If you don’t remove resolvconf, or fix the issue up another way you get something like this:

root@dnsmasq:/etc# service dnsmasq status 
* dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
  Drop-In: /run/systemd/generator/dnsmasq.service.d
           `-50-dnsmasq-$named.conf, 50-insserv.conf-$named.conf
   Active: active (running) since Sun 2016-09-18 03:24:07 UTC; 3s ago
  Process: 910 ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf (code=exited, status=0/SUCCESS)
  Process: 953 ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf (code=exited, status=0/SUCCESS)
  Process: 944 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=0/SUCCESS)
  Process: 943 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)
 Main PID: 952 (dnsmasq)
   CGroup: /system.slice/dnsmasq.service
           `-952 /usr/sbin/dnsmasq -x /var/run/dnsmasq/dnsmasq.pid -u dnsmasq -r /var/run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpk

Sep 18 03:24:06 dnsmasq dnsmasq[943]: dnsmasq: syntax check OK.
Sep 18 03:24:06 dnsmasq dnsmasq[952]: started, version 2.75 cachesize 500
Sep 18 03:24:06 dnsmasq dnsmasq[952]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset au
Sep 18 03:24:06 dnsmasq dnsmasq-dhcp[952]: DHCP, IP range 10.69.10.100 -- 10.69.10.149, lease time 12h
Sep 18 03:24:06 dnsmasq dnsmasq[952]: using local addresses only for domain gavowen.local
Sep 18 03:24:06 dnsmasq dnsmasq[952]: no servers found in /var/run/dnsmasq/resolv.conf, will retry
Sep 18 03:24:06 dnsmasq dnsmasq[952]: read /etc/hosts - 5 addresses
Sep 18 03:24:06 dnsmasq dnsmasq[952]: read /etc/banner_add_hosts - 0 addresses
Sep 18 03:24:07 dnsmasq dnsmasq[953]: /etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolv
Sep 18 03:24:07 dnsmasq systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.

The DHCP part of dnsmasq works fine, but DNS breaks like this (tcpdump)

03:38:02.900866 IP dnsmasq.gavowen.local.domain > 10.69.10.80.59954: 48699 Refused 0/0/0 (45)
03:38:03.887415 IP 10.69.10.80.58335 > dnsmasq.gavowen.local.domain: 4837+ A? img-s-msn-com.akamaized.net. (45)
03:38:03.887523 IP dnsmasq.gavowen.local.domain > 10.69.10.80.58335: 4837 Refused 0/0/0 (45)
03:38:04.076221 IP 10.69.10.80.52683 > dnsmasq.gavowen.local.domain: 59968+ A? img-s-msn-com.akamaized.net. (45)
03:38:04.076306 IP dnsmasq.gavowen.local.domain > 10.69.10.80.52683: 59968 Refused 0/0/0 (45)
03:38:05.068785 IP 10.69.10.80.54085 > dnsmasq.gavowen.local.domain: 24507+ A? img-s-msn-com.akamaized.net. (45)
03:38:05.068892 IP dnsmasq.gavowen.local.domain > 10.69.10.80.54085: 24507 Refused 0/0/0 (45)

Now for my /etc/dnsmasq.conf

root@dnsmasq:~# cat /etc/dnsmasq.conf
# Configuration file for dnsmasq.

############
## SERVER ##
############

# listen interface and address
except-interface=lo0
listen-address=10.69.10.41

#########
## DNS ##
#########

local=/gavowen.local/  # domain(s) to search local /etc/hosts
cache-size=500 # set DNS lookup cache to 500 entries
no-negcache    # don't do negative caching
domain-needed  # never forward plain names
bogus-priv     # never forward bogus private (RFC1918) addresses

# block 'sitefinder' wildcard redirects from VeriSign and others for bogus A records
bogus-nxdomain=64.94.110.11
bogus-nxdomain=194.168.4.100
bogus-nxdomain=194.168.8.100
bogus-nxdomain=81.200.64.50
bogus-nxdomain=67.215.65.132

# no LDAP server for the local domain
#srv-host=_ldap._tcp.gavowen.local # no LDAP server for the local domain

# route rDNS to this server
server=/10.69.10.in-addr.arpa/10.69.10.41


##########
## DHCP ##
##########

dhcp-leasefile=/var/lib/misc/dnsmasq.leases
dhcp-authoritative

dhcp-range=10.69.10.100,10.69.10.149,255.255.255.0,12h
dhcp-option=option:router,10.69.10.1 # default route
dhcp-option=option:dns-server,10.69.10.41
# dhcp-option=option:dns-server,10.69.10.41,203.8.183.1
dhcp-option=option:ntp-server,10.69.10.1
dhcp-option=23,50 # set default IP TTL to 50

# Windows clients and Samba
dhcp-option=19,0              # option ip-forwarding off
dhcp-option=44,10.69.10.20    # set netbios-over-TCP/IP nameserver(s) aka WINS server(s)
dhcp-option=45,10.69.10.20    # netbios datagram distribution server
dhcp-option=46,8              # netbios node type
dhcp-option=252,"\n"          # send an empty WPAD option. Windows 7 and possibly later
dhcp-option=vendor:MSFT,2,1i  # Windows release DHCP lease when it shuts down
# http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true
# These are the node types for netbios options:
#   1 = B-node, 2 = P-node, 4 =M-node, 8 = H-node

# FQDN settings for DHCP
expand-hosts
domain=gavowen.local 

# static leases
dhcp-host=c4:4e:ac:0d:d4:8e,Kodi,10.69.10.60,infinite
dhcp-host=00:18:dd:23:03:9d,HDHR-123039DD,10.69.10.61,infinite
dhcp-host=fc:f1:52:a2:68:de,STR-DN850,10.69.10.63,infinite
dhcp-host=b8:27:eb:db:27:28,OldKodi,10.69.10.64,infinite
dhcp-host=00:17:88:2b:96:47,Philips-hue,10.69.10.70,infinite
dhcp-host=30:85:a9:93:8a:5c,Vader,10.69.10.80,infinite
dhcp-host=cc:20:e8:c4:42:64,Gavs-iPhone6S,10.69.10.81,infinite
dhcp-host=34:ab:37:1e:cb:c1,Gavs-iPadAir2,10.69.10.82,infinite

touch the following DHCP leases file:

touch /var/lib/misc/dnsmasq.leases #DHCP leases file

Also update /etc/hosts so you can easily ping hosts on your network:

root@dnsmasq:~# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# --- BEGIN PVE ---
10.69.10.41 dnsmasq.gavowen.local dnsmasq
# --- END PVE ---
.69.10.40 pve01.gavowen.local pve01
10.69.10.42 crashplan.gavowen.local crashplan
10.69.10.43 media.gavowen.local media
10.69.10.50 sarlacc.gavowen.local sarlacc

much easier than IP addresses:

root@dnsmasq:~# ping sarlacc
PING sarlacc.gavowen.local (10.69.10.50) 56(84) bytes of data.
64 bytes from sarlacc.gavowen.local (10.69.10.50): icmp_seq=1 ttl=64 time=0.333 ms
64 bytes from sarlacc.gavowen.local (10.69.10.50): icmp_seq=2 ttl=64 time=0.234 ms
64 bytes from sarlacc.gavowen.local (10.69.10.50): icmp_seq=3 ttl=64 time=0.214 ms
^C
--- sarlacc.gavowen.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.214/0.260/0.333/0.053 ms
root@dnsmasq:~# ping media
PING media.gavowen.local (10.69.10.43) 56(84) bytes of data.
64 bytes from media.gavowen.local (10.69.10.43): icmp_seq=1 ttl=64 time=0.283 ms
64 bytes from media.gavowen.local (10.69.10.43): icmp_seq=2 ttl=64 time=0.031 ms
64 bytes from media.gavowen.local (10.69.10.43): icmp_seq=3 ttl=64 time=0.027 ms
^C
--- media.gavowen.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.027/0.113/0.283/0.120 ms

last but not least start up dnsmasq:

service dnsmasq start
service dnsmasq status

Hopefully now you are up and away with a nify little DNS and DHCP server.

Getting Tvheadend Picons to Work in Plex

Picons are handy if you are using the Plex Tvheadend channel and you want the TV station icons to show up.

I was able to pull down all the Australian TV icons online from Beyonwiz (this is for my Ubuntu Linux Tvheadend server):

apt-get install git
cd /usr/src
git clone https://bitbucket.org/beyonwiz/picons-australia.git

 

Then you can set the Tvheadend (TVH) server “Configuration -> General” tab to prefer picons over channel name, and set the path to file:///usr/src/picons-australia/picon

The other thing you need to do is under “Configuration -> Access Entries”, add a new entry with the following:

Enabled: tick
Username: *
Password: *
Network prefix:  The IP address of your Plex server or Kodi player, or even local subnet if you want. e.g. "10.1.0.45/32" or "10.1.0.0/24" (or "127.0.0.1/32" if Plex and TVH are on the same box).
Streaming: tick

That should be enough access to get the icons working.

When I get time I’ll see if I can feed Kodi the picons in a similar way, as I prefer this server-side method of delivering TV channel icons, rather than client-side. For now I just point Kodi to a local directory with PNG images named the same as the channel names, which seems to work fine.

The only issue with my current picon set-up for the Plex Tvheadend Channel, and it is a minor one, is that the picons get truncated on my iPhone as they aren’t square format. They do look look fine on the PC though. I’m tossing up whether it’s worth my time to create square icons for the 22 stations I make use of in Melbourne Australia.

Other than that, I’m pretty stoked with being able to get the icons/picons to display!

Installing Tvheadend on Ubuntu

Update April 2016: You don’t have to build your own Ubuntu packages any more, as they are maintained here.

I’ve chosen to install Tvheadend (TVH) on a vanilla Ubuntu Server 14.04.2 installation. Incidentally I have Ubuntu (64-bit version) setup on a ESXi 6.0 host. Here’s how you can do it to:

Install Ubuntu Server 14.04.2

I recommend installing these at install time:

ssh server
samba server

Otherwise don’t install them straight up, but later once in the CLI you can do this:

apt-get install ssh
apt-get install samba

If the timezone is somehow messed up you can:

dpkg-reconfigure tzdata

In Ubuntu, you don’t log on as root or set the root password, but rather sudo -i, which will get you root privs.

Finalise the install:

sudo -i
rm -rf /var/lib/apt/lists/*
apt-get update
apt-get upgrade
reboot

Install Required Libraries

apt-get install build-essential git pkg-config libssl-dev bzip2 wget
apt-get install libavahi-client-dev zlib1g-dev libavcodec-dev
apt-get install libavutil-dev libavformat-dev libswscale-dev
apt-get install libcurl4-gnutls-dev liburiparser-dev
apt-get install debhelper

Install Tvheadend

Go to your building area:

cd /usr/src/

Get a snapshot of the latest TVH:

git clone https://github.com/tvheadend/tvheadend.git

This will install the latest development code branch. At the moment this is 4.1. If you want to install the stable 4.0 branch then try this:

git clone --branch release/4.0 https://github.com/tvheadend/tvheadend.git

Now change into the “tvheadend” directory and list the build optons:

cd tvheadend/
./configure --help

Build it with hdhomerun support, and some other goodies required for transcoding:

AUTOBUILD_CONFIGURE_EXTRA=" --enable-hdhomerun_client --enable-avahi --enable-hdhomerun_static --enable-libffmpeg_static" ./Autobuild.sh -t precise-amd64

This should create a tvheadend deb package a level up, which you can now install using the distro’s install tool “dpkg”:

cd ..
# dpkg -i tvheadend_<your freshly created package>.deb
# e.g.
dpkg -i tvheadend_4.0.7-11~g398e4fe~precise_amd64.deb

Now run it:

service tvheadend start

You should be able to browse to your TVH server on port 9981. eg. http://10.69.10.42:9981/

login is tvhadmin/tvhadmin.   You can update that once you’re in. Enjoy.

Keeping TVH Up to Date

Go into the /usr/src/tvheadend directory and run git pull .  After that, do a build just as you would before, and install the new deb package which will update TVH.  Simples! You should still have the previous deb package if anything mucks up, and you can apt-get remove tvheadend the current version, and then re-install the older version.

You can keep the base system up to date with:

apt-get upgrade
apt-get autoremove

 

Tvheadend vs MythTV for Kodi – TVH the Clear Winner

As you can see from my previous blogs, I’ve been playing around with MythTV of late, as a backend TV server for Kodi.  Even though I was successful in setting this up, I’ve hit some frustrating limitations and have so decided to pull the pin on that experiment, and go back to Tvheadend (TVH for short). My major annoyances are/were:

  • I couldn’t find a way to split DVB-T TV and DVB-T radio stations, the way TVH does in Kodi. With MythTV, they all appear as TV stations.
  • The ability to set channel groups seems to be lacking in MythTV.

I was looking further and further into these issues and there was some talk in some forum somewhere about being able to do these things with SQL commands in MySQL, but I figured I didn’t want to waste any more time – I’d invested far too much already! In TVH it *just works*.  Other gripes with MythTV include:

  • Since Myth’s both a front-end and back-end, there are often parts of config that relate to the front-end that I’ll never touch, so it’s a bit confused when you’re only using the backend. This is especially apparent with some iPhone apps I bought, where some screens of the app are for the backend server, and some for the frontend. The benefit of TVH is that it is a pure server – there is none of this confusion of backend vs frontend!
  • It’s pretty fiddly just to get the MythTV server running. You also have to jump through a lot of hoops to get the mythweb webserver going as well. Say goodbye to a weekend!

A fairer comparison is MythBuntu vs TVH-Ubuntu, rather than MythTV-FreeBSD.  I’ve tried MythBuntu, and set-up is a bit easier than all that work I did on FreeBSD, but it’s still kludgy to my mind, and still suffers from my major gripes with it.

I have found it to be actually quite straightforward to install TVH from a vanilla Ubuntu install, and to keep it up to date with Git pulls. I’ll add a blog post soon to show how this is done. My ideal setup would be for TVH to stabilise and add native HDHomeRun support for FreeBSD (the way MythTV manages to do!), and then have the FreeBSD people update the Ports collection with this stable code. Hopefully TVH will get there in the next year or two. Then I could run TVH on my FreeNAS/FreeBSD box, and shut down my separate Linux server.