Night owl

Night owl

Building a MythTV PVR

How to (or in some cases - not to) do it

Introduction - the project
System components
Basic installation
HDMI monitor and overscan
Shutdown and wakeup
MythTV backend setup
MythTV frontend setup
Kodi setup
Conclusions and summary
Epilogue - 3 years on
Links

Basic installation

Bear in mind in the following sections that this what finally what I did to install everything and get it going. Actually I must have reinstalled from scratch 10-20 times while trying to sort problems. So, this was just the final order, not what I did when experimenting.

BIOS

Some basic settings in the BIOS:

  • Boot order - CDROM then HDD (need that for install and backup)
  • Wake from RTC - to allow restart from standby / shutdown etc (possibly a mistake, see later)
  • Boot on power on - so it starts again on a power outage

Initial install

The .ISO was burnt to a DVD and the system booted from it.

Largely, all the defaults were used: it detected the wireless network OK, and I selected download updates while installing and install 3rd party drivers.

When it came to install location I selected other and created a 40GB ext4 primary boot partition mounted at / at the start of the disk, an 8GB swap partition at the end, and all the space in the middle was an ext4 logical partition for data mounted at /media/data. The reason for this is that all the video and other media data will go into the data partition keeping the boot partition quite small so it can easily be backed up.

Usual locale information was entered as required, and the username set up was 'pvr'. The reason mythtv cannot be set up as a username is that it is already used for MythTV. It was set to start up without logging in, to be a backend with frontend (even though the frontend isn't used, some setup is done via the frontend), and Myth service, Samba, SSH and VNC support added. Finally the open source video driver was used (tried both, didn't seem to make much difference). Rebooted on command, Note - do not remove the DVD until explicitly told to.

It rebooted and everything worked. Some changes were immediately made: it started the MythTV frontend immediately, so exited that (ESC) and in Applications >> Settings >> Autostart unticked the entry for the frontend. The screen saver was temporarily disabled while installing.

Extra package install

A number of extra packages were installed. Except for Firefox which came from Google, and Libre Office and Thunderbird which were installed from the Ubuntu software centre, these were all installed from command line as I sometimes had problems with the GUI locking up. The packages were:

  • gedit for script editing - sudo apt-get install gedit
  • emacs for script editing - sudo apt-get install emacs
  • Chrome browser (could not get on with the open source version - Chromium) - download and install from https://www.google.co.uk/intl/en/chrome/browser/desktop/index.html, then lose Chromium: sudo apt-get purge chromium-browser. Mozilla firefox works just as well (sudo apt-get install firefox), but I use Chrome as it synchronises bookmarks with other devices I also have Chrome on.
  • cifs-utils for connecting to Windows shares - sudo apt-get install cifs-utils
  • Pulse Audio controls (audio mixer) - sudo apt-get install pavucontrol
  • nmap for searching IP addresses - sudo apt-get install nmap
  • Alacarte menu editor - sudo apt-get install alacarte
  • gparted partition editor - sudo apt-get install gparted
  • Gnome disk utility - sudo apt-get install gnome-disk-utility
  • Suspend and powerstate framework (for shutdown) - sudo apt-get install pm-utils

Then updated all the software packages (but not yet MythTV):

sudo apt-get update sudo apt-get dist-upgrade

This takes some time and during that, kept Samba config file when asked.

Then install Kodi and the MythTV PVR support:

sudo apt-add-repository ppa:team-xbmc/ppa sudo apt-get update sudo apt-get install kodi sudo apt-get install kodi-pvr-mythtv

Then updated MythTV: first used MythTV control centre (in Applications >> System) to enable the 0.27 repository, then:

sudo apt-get update sudo apt-get dist-upgrade

When asked, allowed other computers to access, this web server not set exclusively for Mythweb and keep existing mythtv.cnf. The reason all these updates were done separately was the first time I tried them all in one go it all crashed.

Network access

Needed this on a fixed IP address rather than DHCP so in Applications >> Settings >> Network configuration set the wireless network parameters to manual, IP address 192.168.0.7, subnet mask 255.255.255.0, Default gateway 192.168.0.1 and DNS server 192.168.0.1 (settings for my network). Then rebooted.

All good so far.

Handling crashes

It is not supposed to crash, but occasionally, around every 2-3 months it will fail to boot with a 'kernel panic', no reason has been found for this but it is probably a suspect driver. Reboot, and all is well again - until the next time. It has never crashed with a 'kernel panic' when up and running.

The problem is, if it does this, it is then left sitting with the crashed text screen until it is manually rebooted. To get around this some boot changes were made. The file /etc/default/grub was edited as follows:

  • The GRUB_HIDDEN_TIMEOUT and GRUB_HIDDEN_TIMEOUT_QUIET lines were commented out (put a '#' at the start of each line).
  • GRUB_TIMEOUT was set to 5
  • GRUB_CMDLINE_LINUX_DEFAULT was changed to quiet splash panic=15.

It must be edited as root (eg gksu gedit, or start a root terminal - sudo su - and run the editor from there), and then the command sudo update-grub is run.

The effect of all that is the the boot menu shows for 5 seconds on boot before automatically continuing - this allows manual intervention if necessary, and (in theory) if there is a 'kernel panic' on boot, it should wait 15 seconds then reboot. The latter has not been proven - but then it hasn't stuck on boot recently either.

Sudo without a password

As will be seen in following sections, various scripts were used that had to be run with root privileges for one reason or another. The usual way to do this in Ubuntu Linux is to 'sudo' the command or script, which basically runs it with root prvileges, but you need to enter your user password to do this. Since most of these scripts run unattended it is necessary to set up the ability for them to run without being prompted for a password. The way to do this is by setting up sudoers parameters.

It is a bad idea to edit the main sudoers script. Instead add an extra file to /etc/sudoers.d with the necessary entries. In my case the file was called mythtv, and contained:

pvr ALL=NOPASSWD: /usr/local/bin/mythtv* mythtv ALL=NOPASSWD: /usr/local/bin/mythtv*

These lines mean that any script starting with mythtv, placed in /usr/local/bin, will not ask for a password when run by pvr or mythtv.

There are however some gotchas in this: the file needs specific permissions, it checked for in real time, and if you get it wrong all future sudo'ing will fail, which may very well lock you out from doing anything and you may only be able to sort it out from a bootable CD. You do not find any of this out until it is too late. The way to avoid it is:

  • First start another terminal window, and enter sudo su. This will leave that terminal running as root, and it can be used to sort out mistakes (ie delete any duff files in /etc/sudoers.d).
  • Only ever edit the file with visudo which is a version of vi modified to get it right, so to add/edit a new file called mythtv, the command is sudo visudo -f /etc/sudoers.d/mythtv.
  • Start the editor from a command line terminal (NOT in the sudo su terminal above, you need to keep that for emergencies), edit the file, write out changes (they'll be written to a temp file, which you must confirm), then exit. All should be well, but if it isn't, you've still got that root terminal window - use that to remove the duff file and you can have another go.

Playing commercial DVDs

To play commercial DVDs with content scrambling requires some extra installs. The process for Ubuntu 14.04 is as follows:

Firstly libdvdread4 and libdvdnav4 must be installed - sudo apt-get install libdvdread4 libdvdnav4.

Then install libdvdcss2 by running /usr/share/doc/libdvdread4/install-css.sh.

Finally under Applications >> Preferences >> Removeable Drives and Media make sure 'Mount removeable media when inserted' is ticked. I also added the following line to /etc/fstab (after creating the mount location - sudo mkdir /media/cdrom0)

/dev/sr0 /media/cdrom0 udf,iso9660 user,exec,utf8 0 0

and the following was added to /etc/samba/smb.conf:

[DVD] comment = DVD path = /media/cdrom0 public = yes writable = no create mask = 0660 directory mask = 0770 force user = mythtv force group = mythtv

The former to mount it automatically and the latter to make it shareable so it can be watched using a SMB //.../DVD share on a remote kodi installation (set it up using Video >> Add Files ..., and you need to browse to the root VIDEO_TS.IFO file in the VIDEO.TS folder).

After that commercial DVDs should play in VLC and Kodi.

Watching from websites (eg iPlayer)

This is really why I installed Chrome. Whilst there are lots of add-ons for Kodi, most things can be accessed from a browser.

In order to stop the screen saver kicking in while watching something using Chrome, two additional scripts were written and placed in /usr/local/bin, and made executable (sudo chmod +x /usr/local/bin/....):

mythtv-runchrome:

#!/bin/bash #runs google chrome (replaces /usr/bin/google-chrome-stable %u in menu) # param 1 - URL passed on command line sudo mythtv-chromeiss & google-chrome-stable $1

mythtv-chromeiss:

#!/bin/bash #inhibit screen saver while chrome running # LOGFILE="/var/log/mythtv/chrome-iss.log" # LOGFILE="/dev/stdout" LOGFILE="/dev/null" let "count = 0" while [ $(pidof -x mythtv-runchrome) ] ; do let "count = $count + 1" echo "Chrome running ($count)" >> $LOGFILE if [ $count -ge 25 ] ; then let "count = 0" if [ $(pidof -x xscreensaver) ] ; then echo "Ping screen saver" >> $LOGFILE xscreensaver-command -deactivate >> $LOGFILE else echo "No screensaver running" >> $LOGFILE fi fi sleep 2 done echo "Chrome not running - exiting" >> $LOGFILE exit 0

The first just starts Chrome, but it also runs the second as a background script. The purpose of the second is to keep kicking the screen saver while Chrome is still running, then it exits on its own.

Having done that the main menu editor was used to replace the command line to start Chrome with the script (/usr/local/bin/mythtv-runchrome %u).

Miscellaneous

Chrome (using the script above) and Kodi were added to the desktop for convenience (right click on screen, select Create Launcher ...).

Next: HDMI monitor and overscan


(c) Nightshade Arts 2016
nick@mistoffolees.me.uk