MythTV is is one of the most well-known open source LiveTV/PVR servers, and worth trying out and comparing to Tvheadend for serving up live TV to Kodi. I have previously given some background info on both of them. Here’s how you can install the MythTV backend in a FreeNAS jail.
Creating your Jail
First make sure your jail environment is set-up correctly:
I’ve carved out a range of IPs from my local LAN /24 subnet of 10.69.10.0/24
Next, go to the Jails tab and “Add Jail”. Click on “Advanced Mode” if not already.
I like to call my MythTV Jail “mythserver” – I feel this is preferable to calling it say “mythtv” because if the name is too close to the program name, it can get confusing later on in system log files.
I let it auto-select the next available free IP address, and then manually add the “IPv4 default gateway” – the router’s LAN IP which for me is 10.69.10.1.
I leave “autostart” and “VIMAGE” selected.
Once you hit “Ok” you can edit the jail you just created, and you should see that it’s added a MAC address, and for FreeNAS 9.3 it’s also added “allow.raw_sockets=true” in the “Sysctls” section. If this is your first jail, it’ll take a while as it downloads the jail template from FreeNAS, before it finalises setting up the jail.
You’ll want to map some extra storage into your jail for recordings. I give it full permissions:
I limit it to 40 Gigs in the Options:
Then I mount it into the jail:
SSH to your FreeNAS and list your jails:
root@sarlacc# jls JID IP Address Hostname Path 1 - dhcp_dns /mnt/volume1/jails/dhcp_dns 2 - mythserver /mnt/volume1/jails/mythserver
My MythTV jail called “mythserver” is jail ID #2 at the moment. Log into the jail:
jexec 2 /bin/csh
pkg update pkg upgrade
The “pkg update” is redundant as the upgrade does an update first, but I still like to do it regardless. Just say yes to all the upgrade prompts. You can run the same commands again after the upgrade, just to confirm the software is now current.
If you prefer Bash like I do, install it tweak it.
pkg install bash vi ~/.bashrc
and add some aliases…
# some useful aliases alias h='fc -l' alias j=jobs alias m=$PAGER alias ll='ls -laFo' alias l='ls -l' alias g='egrep -i'
Log out and back in with bash:
exit jexec 2 /usr/local/bin/bash
That’s if jail ‘2’ is your myth jail. You may only need to type
jexec 2. Try it and see.
Install “GNU Make” for compiling LAME:
pkg install gmake
Install the FreeBSD Ports tree and compile the LAME encoder:
cd /usr/ports portsnap fetch extract cd /usr/ports/audio/lame make install clean cd /
NB: Even though the directories are there, if you don’t do a fresh “extract” then the system will complain, so you have to run this the first time after creating the jail. If you are doing further installs some time in the future (say next week), all you need to run before compilation is
portsnap fetch update
Install the graphical packages. You’ll need these for configuring MythTV by the setup GUI which runs on the X-Windows system. Note the upper case X in libXv:
pkg install libXv pkg install qt4-webkit pkg install xauth pkg install xorg-fonts
pkg install mythtv
You have time to go grab a coffee now, as it’ll take a while. You’ll see a message at the end like:
********** MythTV has now been installed, but it still needs to be configured. 1. To create the database, use the following command: mysql -uroot -p < /usr/local/share/mythtv/database/mc.sql 2. Next, run mythtv-setup. See http://www.mythtv.org/docs/ for more information. **********
You’ll get to do (1.) and (2.) later. For now, update
/etc/rc.conf with the following:
sshd_enable="YES" #change the existing "NO" entry to "YES" mysql_enable="YES" mythbackend_enable="YES"
I found that the hostname was in that file twice, so I deleted the duplicate.
Tip: You can quickly update system variables with the following:
sysrc sshd_enable=YES sysrc mysql_enable="YES" sysrc mythbackend_enable="YES"
Of course we don’t have MySQL installed yet, so we need to grab that too, and start it up:
pkg install mysql56-server service mysql-server start
Populate mysql with the MythTV database:
mysql -uroot -p < /usr/local/share/mythtv/database/mc.sql
Just hit the “enter” key at the password prompt, as a password isn’t yet set. Out of interest, this does the following:
========== CREATE DATABASE IF NOT EXISTS mythconverg; GRANT ALL ON mythconverg.* TO mythtv@localhost IDENTIFIED BY "mythtv"; FLUSH PRIVILEGES; GRANT CREATE TEMPORARY TABLES ON mythconverg.* TO mythtv@localhost IDENTIFIED BY "mythtv"; FLUSH PRIVILEGES; ALTER DATABASE mythconverg DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ==========
Login into mysql (hit enter at the password prompt) and check that “mythconverg” is in there.
mysql -p show databases; exit
MySQL Timezone Update
Update timezone info with:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
I found I got the “Data too long for column ‘Abbreviation’ Error” so I did the following:
mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/timezonefix vi /tmp/timezonefix
I searched through the file and found the stanza (parts between two semicolons) that contain “use tzsetup” and edited out the following lines:
; INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); SET @time_zone_id= LAST_INSERT_ID(); INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('Factory', @time_zone_id); INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 0, 0, 'Local time zone must be set--use tzsetup') ;
I then ran:
cat /tmp/timezonefix | mysql -u root -p mysql
This now completed without error.
Set MySQL Password
mysqladmin -u root password <yourpassword> e.g mysqladmin -u root password letmein
You should have to put in that password now. Type “exit” to quit out.
Setup X11 Forwarding
/etc/ssh/sshd_config with the following updates, replacing the IP address below with your IP:
ListenAddress 10.69.10.22 PermitRootLogin yes PasswordAuthentication yes X11Forwarding yes X11UseLocalhost no
Now start sshd:
service sshd start
This generates keys and starts the SSH server. I like to test the server with a
service sshd restart , to make sure it starts cleanly now that the keys are present.
Set a root password, and test the password along with external connectivity to the mythtv-setup script. If all’s successful, it’ll time out and say that it cannot connect to the X server. That’s the desired outcome, as you want to connect to an X server on another machine. Remember to update the IP address below to that of your jail.
[root@mythserver /]# passwd Changing local password for root New Password: Retype New Password: [root@mythserver /]# exit [root@mythserver /]# ssh -Y email@example.com /usr/local/bin/mythtv-setup Password: mythtv-setup: cannot connect to X server
Setup Remote X Server
1) Install Xming server and start it
2) Install PuTTY on your local machine
3) Configure the default profile in PuTTY with the IP and SSH port of your MythTV Server
4) Go to the Connection panel then select ssh and enable compression, then the x11 tab and check “Enable x11 Forwarding” box, then enter localhost:0 in the “X Display Location” and check “MIT-Magic-Cookie-”
5) Go to “Session”, type “MythTV Server” in the Saved Sessions, and hit the Save button.
With the Xming server started, open the PuTTY session you saved and login (with the user you created earlier) to the myth server, then type….
This will open an Xwindow on your local screen and load the myth setup screen. You might have to run this a second or third time, as it might quit after a country and language update, and also after a database schema update. You’ll get there eventually.
I recommend you follow the MythBuntu setup guide here, skipping right down to the “MythTV Backend Setup” section, and taking it from there.
Start the Backend
The backend service now needs to be started if not already:
service mythbackend start
Also make sure it’s filled with your config settings:
Congratulations – you’ve now configured MythTV backend on FreeNAS in a jail.
If you have any issues, check where the logserver stores its files and check the logs.
[root@mythserver /var/log/mythtv]# ll total 12988 drwxr-xr-x 2 root wheel - 5 Apr 21 03:00 ./ drwxr-xr-x 3 root wheel - 22 Apr 21 03:01 ../ -rw-r--r-- 1 root wheel - 219163 Apr 21 03:00 mythbackend.20150420163447.83755.log -rw-r--r-- 1 root wheel - 12917053 Apr 21 19:40 mythbackend.20150420170022.85871.log -rw-r--r-- 1 root wheel - 4998 Apr 21 03:00 mythlogserver.20150420163448.83757.log [root@mythserver /var/log/mythtv]#
tail the latest backend log file:
[root@mythserver /var/log/mythtv]# tail -5 mythbackend.20150420170022.85871.log 2015-04-21 19:41:31.854481 E [85871/101782] HttpServer107 servicehost.cpp:426 (ProcessRequest) - No Security Pin assigned. Run mythtv-setup to set one. 2015-04-21 19:41:31.862285 I [85871/101739] ProcessRequest mainserver.cpp:1420 (HandleAnnounce) - MainServer::ANN Monitor 2015-04-21 19:41:31.862295 I [85871/101739] ProcessRequest mainserver.cpp:1422 (HandleAnnounce) - adding: kodi as a client (events: 0) 2015-04-21 19:41:31.875402 E [85871/101782] HttpServer114 servicehost.cpp:143 (Invoke) - MethodInfo::Invoke - An Exception Occurred: No Security Pin assigned. Run mythtv-setup to set one. 2015-04-21 19:41:31.875436 E [85871/101782] HttpServer114 servicehost.cpp:426 (ProcessRequest) - No Security Pin assigned. Run mythtv-setup to set one. [root@mythserver /var/log/mythtv]#
ooops – didn’t add a security pin – have to set that up!
- Go to another box and “telnet <your myth IP> 3306” to make sure your MySQL database is working and allowing connections.
- Got to http:<your MythTV IP>:6544 to make sure you have web connectivity
- All else fails – RTFM: MythTV Wiki, and the User Manual.
It’s advisable you setup MythWeb for managing your TV recordings.