Category Archives: FreeBSD

Installing Ubuntu Server 16.04 in FreeNAS 9.10 Beehyve

Emulation Be Gone!

Well I had enough of trying to update the CrashPlan plugin and getting it working with CrashPlan 4.7. I even tried installing a standard jail and using the FreshPorts to get it installed. I got close – I  had CrashPlan downloaded but the make script wanted “jdk-8u92-linux-i586.tar.gz” even though that has known vulnerabilities and it wouldn’t take the latest version “jdk-8u102-linux-i586.tar.gz”. I forced the old Java version (security issues and all) and got everything built but then ran into problems with kernel modules, which given a month of Sundays I might have resolved, but I only want to devote half a Sunday to this, so backed out of that when I realised that I was at that cul-de-sac dead end of frustration I’m sure that you know all too well.

Beehyve to the Rescue

So I backed out of the CrashPlan plugin Jail; gave up on the Crashplan standard Jail, and have gone in a whole new direction with FreeBSD’s “Beehyve” which is accessible under FreeNAS 9.10. This is a hypervisor which has kernel support, so you could say it’s type 1, but probably emulates a lot of stuff, so just how “type 1” is for others to say.  In any case, it seems to perform flawlessly for me so I’m a happy camper.

Emulating Linux ABI on FreeBSD to me always felt like shoving a square peg through a round hole. Why emulate parts of Linux to run CrashPlan, when you can instead virtualize a whole Linux instance, and run CrashPlan native? This will surely keep compatibility problems to a minimum. Not only that, but I can move my TVHeadend to it as well, and anything else that I need to run on a Linux server. I can’t see myself ever going back to the plugin setup for CrashPlan.

Setting up the Beehyve Environment

It was reasonably straightforward setting up Ubuntu Server 16.04 (“Xenial Xerus”), which I will use to host my CrashPlan server, and also my TVHeadend server, and anything else that I really need Ubuntu for.

Speedy Alias – “iohyve” becomes “io”

You can configure beehive directly, but you’re far better served by using the “iohyve” scripts. Now here’s the thing – I hate typing. I am also a clumsy typer with bent fingers, and find “iohyve” particularly annoying to type. You can do what I do and alias “iohyve” to “io” to make things easier. Send a “which io” to make sure that the alias isn’t used in your path already, and then add it to your “~/.bashrc” if you’re using bash:

sarlacc# which io  #make sure that 'io' isn't used for any other commands
sarlacc# cat ~/.bashrc | grep iohyve
alias io='iohyve'    # the alias I added to ~/.bashrc

After adding the alias, log out and log back in, or just source the rc file: . ~/.bashrc

All my subsequent “iohyve” commands will just show “io”.

Initial Parameters

Beehyve needs to know 3 things:

  • Where to store its files?
  • Which NIC to bridge to?
  • If it should start up the kernel modules? (yes… yes it should!)

Configure the answer to those three questions with the following:

io setup pool=<ZFS pool> kmod=1 net=<bridged NIC>    #kmod=1 means yes, 0 means no.

e.g.
io setup pool=volume1 kmod=1 net=vlan10
Setting up iohyve pool...
On FreeNAS installation.
Checking for symbolic link to /iohyve from /mnt/iohyve...
Symbolic link to /iohyve from /mnt/iohyve successfully created.
Loading kernel modules...
bridge0 is already enabled on this machine...
Setting up correct sysctl value...
net.link.tap.up_on_open: 0 -> 1

Some older docs say that on FreeNAS you need to ln -s /mnt/iohyve /iohyve but as you can see above that’s already added. If you add the symlink manually it’ll create a weird circular sym linking.

Files and Folders

Run this to see that the folder structure is setup:

sarlacc# zfs list | grep iohyve
volume1/iohyve                                              21.4G  2.46T   140K  /mnt/iohyve
volume1/iohyve/Firmware                                      140K  2.46T   140K  /mnt/iohyve/Firmware
volume1/iohyve/ISO                                           771M  2.46T   151K  /mnt/iohyve/ISO
volume1/iohyve/ISO/FreeBSD-10.3-RELEASE-amd64-bootonly.iso   116M  2.46T   116M  /mnt/iohyve/ISO/FreeBSD-10.3-RELEASE-amd64-bootonly.iso
volume1/iohyve/ISO/ubuntu-16.04.1-server-amd64.iso           655M  2.46T   655M  /mnt/iohyve/ISO/ubuntu-16.04.1-server-amd64.iso
volume1/iohyve/ubusrv16                                     20.6G  2.46T   140K  /mnt/iohyve/ubusrv16
volume1/iohyve/ubusrv16/disk0                               20.6G  2.48T  2.66G  -

You should just have the first three paths – the rest is stuff I’ve setup later on in this guide.

The Kernel Modules

You can check that the kernel modules are loaded with this:

sarlacc# kldstat
Id Refs Address            Size     Name
 1   94 0xffffffff80200000 18b4000  kernel
 2    1 0xffffffff81d9f000 ffd8c    ispfw.ko
 3    1 0xffffffff82021000 f947     geom_mirror.ko
 4    1 0xffffffff82031000 46a1     geom_stripe.ko
 5    1 0xffffffff82036000 ffca     geom_raid3.ko
 6    1 0xffffffff82046000 ec6a     geom_raid5.ko
 7    1 0xffffffff82055000 574f     geom_gate.ko
 8    1 0xffffffff8205b000 4a33     geom_multipath.ko
 9    1 0xffffffff82060000 5718     fdescfs.ko
10    1 0xffffffff82066000 89d      dtraceall.ko
11   10 0xffffffff82067000 3ad67    dtrace.ko
12    1 0xffffffff820a2000 4638     dtmalloc.ko
13    1 0xffffffff820a7000 225b     dtnfscl.ko
14    1 0xffffffff820aa000 63d7     fbt.ko
15    1 0xffffffff820b1000 579a4    fasttrap.ko
16    1 0xffffffff82109000 49cb     lockstat.ko
17    1 0xffffffff8210e000 162f     sdt.ko
18    1 0xffffffff82110000 d8d8     systrace.ko
19    1 0xffffffff8211e000 d494     systrace_freebsd32.ko
20    1 0xffffffff8212c000 4da3     profile.ko
21    1 0xffffffff82131000 7fdf     ipmi.ko
22    1 0xffffffff82139000 b3c      smbus.ko
23    1 0xffffffff8213a000 1a62a    hwpmc.ko
24    1 0xffffffff82155000 2b80     uhid.ko
25    2 0xffffffff82158000 2b32     vboxnetflt.ko
26    2 0xffffffff8215b000 45320    vboxdrv.ko
27    1 0xffffffff821a1000 41ca     ng_ether.ko
28    1 0xffffffff821a6000 3fd4     vboxnetadp.ko
29    1 0xffffffff821aa000 3567     ums.ko
30    1 0xffffffff821ae000 a684     linprocfs.ko
31    1 0xffffffff821b9000 670b     linux_common.ko
32    1 0xffffffff821c0000 1b140b   vmm.ko
33    1 0xffffffff82372000 2ebb     nmdm.ko
34    1 0xffffffff82375000 1fe1     daemon_saver.ko

If vmm.ko and nmdm are there, you’re golden.

MTU – Danger Will Robinson!

Now the “bridged NIC” is the physical or logical NIC that carries the IP address of the network that you want your virtual machine to bridge to – not the bridged interface. For my home setup I share a VLAN10 (data) and a VLAN99 (management) on a single physical interface – bge0. Why do I do this? Well my switches and routers only have management IPs on VLAN99, and my computer is the only one on VLAN99, so that’s added security. Plus I do it, because I am a network engineer, and because I can 🙂

Now when you have VLAN interfaces you can run into MTU problems, unless you up the MTU to account for the extra 4 bytes of VLAN tag overhead. In FreeNAS GUI, I set “mtu 1504” on any interface I run VLANs on, so that the VLANs can get 1500 bytes MTU.

The automatically created bridge0 interface interits this MTU:

sarlacc# ifconfig bridge0          
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1504
        description: iohyve-bridge
        ether 02:f3:f6:80:91:00
        nd6 options=1<PERFORMNUD>
        id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
        maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
        root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
        member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 9 priority 128 path cost 2000000
        member: epair2a flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 12 priority 128 path cost 2000
        member: epair1a flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 11 priority 128 path cost 2000
        member: epair0a flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 10 priority 128 path cost 2000
        member: vlan10 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 6 priority 128 path cost 20000
sarlacc# ifconfig tap0 
tap0: flags=28943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST,PPROMISC> metric 0 mtu 1504
 description: iohyve-ubusrv16
 options=80000<LINKSTATE>
 ether 00:bd:1b:3e:01:00
 nd6 options=9<PERFORMNUD,IFDISABLED>
 media: Ethernet autoselect
 status: active
 Opened by PID 3694

That tap0 is originally created by iohyve as 1500 bytes, and fails to add to the bridge0 because of the MTU mismatch. In order to get it into the bridge0, I had to do this:

ifconfig tap0 mtu 1504
ifconfig tap0 promisc       # not sure if this was necessary but added anyway
ifconfig bridge0 addm tap0

Surviving Reboots

You want these settings to survive reboots, so add these in the GUI to your “System” > “Tunables”.

iohyve_enable iohyve_flags

Unfortunately I haven’t worked out how to do the tap0 MTU fix just yet, so I’m manually doing that at reboot just for now. I’d like this to be “fixed” by iohyve, but if all else fails I could add a pre or post init script that just runs the commands that way.

Installing Ubuntu 16.04 “Xenial Xerus”

Either FTP fetch the install media or add the path:

io fetch ftp://ftp.iinet.net.au/pub/ubuntu-releases/16.04.1/ubuntu-16.04.1-server-amd64.iso
io cpiso /mnt/volume1/files/software/ISOs/Ubuntu/ubuntu-16.04.1-server-amd64.iso

Once downloaded or copied see that it’s listed:

sarlacc# io isolist
Listing ISO's...
FreeBSD-10.3-RELEASE-amd64-bootonly.iso
ubuntu-16.04.1-server-amd64.iso

Now create the VM and set its parameters (I call my VM ubusrv16 for Ubuntu Server 16.x):

sarlacc#io create ubusrv16 20G
sarlacc#io set ubusrv16 loader=grub-bhyve os=d8lvm ram=2G cpu=1 con=nmdm1
sarlacc#io list
Guest     VMM?  Running  rcboot?  Description
ubusrv16  NO    NO       NO       Sun Jul 24 11:04:26 AEST 2016

Use “os=debian” if not using LVM. If using LVM, use “os=d8lvm”

I just give it one CPU, and 2Gigs of RAM. The console will be nmdm1 if it’s the first VM.

Do the install, and use another SSH session to attach to the console:

io install ubusrv16 ubuntu-16.04.1-server-amd64.iso
io console ubusrv16  #handy to do this in another window

Configuring VM to Start at Reboot

One criticism I’ve heard of VirtualBox is that you can’t start the VMs on reboot. I haven’t verified this though. The good thing with Beehyve is that you can start a VM on reboot:

io set ubusrv16 boot=1

🙂

Let me know you you go in the comments.

Setting up a Crashplan FreeNAS Plugin Jail

Overview

I backup about 400 Gigabytes of photo RAW files and Lightroom (LR) catalogs to the cloud using CrashPlan. I used to have these files on a single hard drive inside my computer – dangerous!

I realised that I needed my photo files on a RAID array so that I don’t lose everything in case of a single disk failure. Instead of putting a RAID array inside my PC, or directly attaching a RAID array to it using USB or Thunderbolt (called a “DAS” for “directly attached”), I realised I didn’t need to spend money when I already have a perfectly good RAID box already – my NAS running FreeNAS!

I had a rude shock though when it came to backing up with CrashPlan running on my PC, and having my work files on a mapped network drive. CrashPlan refused to touch the files on the mapped network drive! I then to take the plunge and move the CrashPlan engine to my NAS, and do backups from there. Brilliant!

About Running CrashPlan “Headless”

CrashPlan has two basic parts – the CrashPlan application, and the CrashPlan engine. The engine runs continuously and backups up even when the client isn’t running. The client just checks the engine status, and is used to configure it. The Client app is designed to connect to an engine on the local machine and not on a remote machine. Luckily it uses TCP ports, so we can hack the configuration in order to get it to connect to a remote (headless) machine.

Install the CrashPlan Plugin Jail

Setup you jail configuration, if you haven’t already. Mine is as follows:

jail configuration

Install the CrashPlan plugin jail by going to “Plugins > Available” and then highlighting “CrashPlan” and then clicking the “Install” button.

After it has installed, map the files you want to backup into the jail under “View Jails > Storage”. You’ll find detailed instructions on this on the FreeNAS documentation homepage.

My jail storage is as follows:

jail storage

“volume1” is my raid array volume, and “lacie” is an external 12TB USB3.0 drive volume. I initially decided to use CrashPlan to backup all my files (software, multimedia and music) to my external drive, but I found that too slow. Now I just have a backup set to back up my “RAW files” and “Calalogs”, which are contained within my “/software/photography”, as I didn’t want to create another dataset just for those two.

It makes sense to only map your source files as read-only as I have done here – no need to give CrashPlan more permissions than it needs to do its job, and safeguards the files in case something goes drastically wrong. Mapped like this – you can only trash your backups, and not the source.

Update the Plugin Jail

I usually run the following for any new jail to get it up to date:

pkg clean     # clean out old cache
pkg update    # gets the latest list of files
pkg upgrade   # updates the jail software

I also like to install bash with “pkg install bash” and then log out and back into the jail under bash:

sarlacc# jls
 JID IP Address Hostname Path
 1 - crashplan_1 /mnt/volume1/jails/crashplan_1
 2 - dnsmasq /mnt/volume1/jails/dnsmasq
 3 - plexmediaserver_1 /mnt/volume1/jails/plexmediaserver_1
 4 - sabnzbd_1 /mnt/volume1/jails/sabnzbd_1
sarlacc# jexec 1 bash
[root@crashplan_1 /]#

Configure SSH in the Plugin Jail

You’ll need SSH in order to connect your PC to the CrashPlan engine running on the NAS. This is quite straightforward:

Edit “/etc/ssh/sshd_config" and uncomment/edit as follows:

PermitRootLogin yes
PasswordAuthentication yes
AllowTcpForwarding yes

For more security you can create another user such as “adduser crashplan” or “adduser backupuser” etc, but I don’t bother – I just use the root user and set a strong root password (in the jail) with “passwd root” command.

Next get sshd going:

sysrc sshd_enable=YES  # allows sshd to be started as a service
service sshd keygen    # generate sshd keys
service sshd start     # start the sshd service
service sshd status    # check sshd service status - should return the process ID

Update and Start CrashPlan Engine in Plugin Jail

The current problem we face is that the plugin is only version 3.6.3_1, and that’s way behind the exiting GUI version of 4.7, and there are compatibility issues. No problem – just manually update the jail:

su -                    # if not already root
cd /usr/pbi/crashplan-amd64/share/crashplan
wget --no-check-certificate https://download.code42.com/installs/linux/install/CrashPlan/CrashPlan_4.7.0_Linux.tgz
tar -xf CrashPlan_4.7.0_Linux.tgz
cd crashplan-install
cpio -idv < CrashPlan_4.7.0.cpi
service crashplan stop
cd ..
rm -r lib*
cp -r crashplan-install/lib* .
sysrc crashplan_enable=YES

The above assumes that 4.7 is the latest version, and that the crashplan TARGETDIR is “/usr/pbi/crashplan-amd64/share/crashplan“. Check the install vars here:

root@crashplan_1:/usr/pbi/crashplan-amd64/share/crashplan # cat install.vars 
TARGETDIR=/usr/pbi/crashplan-amd64/share/crashplan
BINSDIR=/usr/pbi/crashplan-amd64/share/crashplan/bin
JAVACOMMON=/usr/pbi/crashplan-amd64/linux-sun-jre1.7.0/bin/java
APP_BASENAME=CrashPlan
DIR_BASENAME=crashplan
JRE_X64_DOWNLOAD_URL=http://download.code42.com/installs/proserver/jre/jre-7u45-linux-x64.tgz
JRE_I586_DOWNLOAD_URL=http://download.code42.com/installs/proserver/jre/jre-7u45-linux-i586.tgz

you may have to change “JAVACOMMON=/usr/pbi/crashplan-amd64/share/crashplan/jre/bin/java” to: “JAVACOMMON=/usr/pbi/crashplan-amd64/bin/java” if you get an error message in /var/log/crashplan/engine_error.log complaining about “libjli.so”

How I found the correct java:

[root@crashplan_1 /usr/pbi/crashplan-amd64/share/crashplan]# find / -name "java"
/usr/pbi/crashplan-amd64/linux-sun-jre1.7.0/bin/java
/usr/pbi/crashplan-amd64/share/java
/usr/pbi/crashplan-amd64/share/crashplan/jre/bin/java
/usr/pbi/crashplan-amd64/bin/java

/usr/pbi/crashplan-amd64/linux-sun-jre1.7.0/bin/java -version   Java(TM) SE Runtime Environment (build 1.7.0_51-b13) 
/usr/pbi/crashplan-amd64/share/java -version  directory
/usr/pbi/crashplan-amd64/share/crashplan/jre/bin/java -version   - breaks with libjli.so issue
/usr/pbi/crashplan-amd64/bin/java -version   (build 1.7.0_51-b13)

Go to Plugins > CrashPlan, in the left hand side tree menu in order to accept the Java licence agreement. This trips a lot of people up.

Now start Crashplan

 service crashplan start

You can check that CrashPlan is running with the following:

root@crashplan_1:/mnt/lacie # sockstat -4 | grep java
root java 4859 88 tcp4 10.69.10.24:10303 103.8.239.9:443
root java 4859 105 tcp4 127.0.0.1:4243 *:*
root java 4859 108 tcp4 127.0.0.1:4243 127.0.0.1:12317
root java 4859 119 tcp4 10.69.10.24:56178 216.17.8.11:443

Line 2 is a connection to 103.8.239.9, which is Code42 Australia, where I am backing up some files to.
Line 3 is listening on the local server for new connections.
Line 4 is a an SSH port map from my Windows PC where I run the GUI. We’ll get to that.
Line 5 is a connection to  216.17.8.11 , which is Code42 (makers of CrashPlan) in the USA. Possibly a license server.

Don’t be alarmed when you see “crashplan is not running”, when issuing a “service crashplan status”. If Java is listening on the 4243 port then it should be fine. 🙂

Configure SSH in Windows

I use a program called SecureCRT to easily setup the portmap, connecting to my jail IP of 10.69.10.24, and CrashPlan port of 4243, using local Windows port of 4200:

Crashplan port forward secure CRT with crashplan settings

It’s handy to create a save a session for this, and then create a desktop shortcut to the session, so you can just double-click the icon and start it. I like to start it minimised. The target for the shortcut for me is “C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe" /S "CrashPlan

NB: Check that 4243 is actually your CrashPlan engine port, with the “sockstat -4 | grep java” command above.

Connecting Windows CrashPlan Client to FreeNAS CrashPlan Engine

After setting up the portmap, we need to finish off by connecting the Windows Client to the FreeNAS server. To do this we need to update the following file:  “C:\ProgramData\CrashPlan\.ui_info” changing port and API key.

e.g. from:

4255,736d39b8-5de2-4aa7-9ef9-67bc5d7177e5,127.0.0.1

to

4200,e047e36f-beef-42a4-babe-3b8eff05cafe,127.0.0.1

The format is <local port>,<api key>,<IP address>. Where is the API key you might ask? Answer – from the server’s .ui_info file. Run this on the FreeNAS box to check:

cat /var/lib/crashplan/.ui_info

You can double check the server’s port config there.

Once the Windows “.ui_info file” is saved, you should now be able to start the CrashPlan application on your PC and connect to the server.

The .ui_info file reverts back to the previous settings on every reboot of Windows. It is therefore important to create a .bat file to update this on reboot.

Windows Batch File

  1. Copy your newly configured “.ui_info” file to a new file called “freenas.ui_info” in the same directory.
  2. Create a file called “cpcfg.bat” (short for “crashplan configuration”) in the same directory, with the following contents:
    copy C:\ProgramData\CrashPlan\FreeNAS.ui_info C:\ProgramData\CrashPlan\.ui_info
  3. Create a shortcut to that same cpcfg.bat file in the same folder.
  4. Once the shortcut has been created, right-click the file and select Cut.
  5. Press the WindowsKey+R to get to the “Run” dialog box.
  6. Type “shell:startup” in the Run dialog box and hit “OK”.
  7. Paste your “cpcfg.bat” shortcut into that folder.
  8. Right-click on the shortcut and go to “Properties > Shortcut (tab) > Advanced, and click “Run as Administrator”, and then OK, Apply, OK, to save.

Now everytime you reboot, that file will have the correct info. If that doesn’t work then you’ll have to just manually run the .bat file.

Troubleshooting and Tips

I did the following when I was troubleshooting, just following tips on forums, as you do. I’m not sure if they made my setup work or not, but if you have trouble, then it doesn’t hurt to try the following on the server, within the CrashPlan plugin jail:

ln -s /usr/local/bin/bash /bin/bash
/usr/bin/cpuset -l 0 /usr/local/share/crashplan/bin/CrashPlanEngine restart

In the GUI you can doubleclick on the CrashPlan “House” and logo on the top right and bring up the GUI CLI. Type “connection.info” and you should see something like this:

connection.info 

Address=127.0.0.1
Port=4242
UI Port=4243
HTTP Port=4244

Address=127.0.0.1 and UI Port=4243 is correct if you’re mapping local port 4200 to server port 4243

CPU

Big tip here is to set the CPU usage to 100% (for user present and idle) in the FreeNAS GUI. This is because FreeNAS does CPU management for jails, and 100% within the jail means about 60% overall. The more CPU you throw at it, the better.

It does help to have a very grunty box when doing local backups at speed. I found that my speeds went up, the more I ramped CPU up to 100%, so it’s definitely CPU-bound. I get about 325Mbps  (bits not bytes) to my external Lacie 12TB box over USB3.0 (5Gbps throughput). That would definitely go up with more CPU clock cycles.

Compression

There’s no need to compress your files within the jail, if you’ve already turned compression on at the dataset level. You’re just wasting your time and CPU otherwise. It is good to compress when going over the Internet though, so save your network bandwidth.

Credits

This draws heavily from these two links:
Using CrashPlan On A Headless Computer
FreeNAS Forums: CrashPlan 4.5 Setup

 

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.

Installing Mythweb into Your FreeNAS MythTV Jail

In my last blog I showed how I installed a MythTV backend PVR server into a FreeNAS Jail.

A must-have for usability is the Mythweb HTTP-based configuration tool. There’s a lot of hoops to jump through, but you should hopefully make it through unscathed!

Install Mythweb and Dependencies

pkg install mythplugin-mythweb

For me this says that it will install the following:

New packages to be INSTALLED:
 mythplugin-mythweb: 0.27_1
 php56-session: 5.6.7
 php56: 5.6.7
 apache24: 2.4.12
 php56-posix: 5.6.7
 php56-json: 5.6.7
 php56-mysql: 5.6.7

Since it is installing PHP 5.6, you’ll need the “56” version of mod_php as well:

pkg install mod_php56

There are important messages from the installs (shown here) which we’ll address below:

Message for apache24-2.4.12:
To run apache www server from startup, add apache24_enable="yes"
in your /etc/rc.conf. Extra options can be found in startup script.

Your hostname must be resolvable using at least 1 mechanism in
/etc/nsswitch.conf typically DNS or /etc/hosts or apache might
have issues starting depending on the modules you are using.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- apache24 default build changed from static MPM to modular MPM
- more modules are now enabled per default in the port
- icons and error pages moved from WWWDIR to DATADIR
 If build with modular MPM and no MPM is activated in 
 httpd.conf, then mpm_prefork will be activated as default
 MPM in etc/apache24/modules.d to keep compatibility with 
 existing php/perl/python modules!
Please compare the existing httpd.conf with httpd.conf.sample
and merge missing modules/instructions into httpd.conf!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Message for mythplugin-mythweb-0.27_1:
mythweb has been installed into:
 /usr/local/www/mythweb
You need to configure mythweb now according to the instructions in
 /usr/local/www/mythweb/INSTALL
For lighttpd you should have a look at the MythTV Wiki
 http://www.mythtv.org/wiki/MythWeb_on_Lighttpd

Message for mod_php56-5.6.7:
***************************************************************
Make sure index.php is part of your DirectoryIndex.
You should add the following to your Apache configuration file:
<FilesMatch ".php$">
 SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".phps$">
 SetHandler application/x-httpd-php-source
</FilesMatch>
***************************************************************

Server-Wide Config

Update “/etc/rc.conf" with the following:

apache24_enable="YES"

Update “/etc/hosts" to something similar to the below – changing the parts in red to suite your IP, hostname and domain:

127.0.0.1 localhost localhost.localdomain mythserver mythserver.gavowen.local
10.69.10.22 mythserver mythserver.gavowen.local

Mythweb Config

You can choose to put your mythweb into the root of the web server, but I prefer to put it off to the side it its own “mythweb” directory.

Copy the mythweb files to where the web server can use them:

mkdir /usr/local/www/apache24/data/mythweb
cp -R /usr/local/www/mythweb/* /usr/local/www/apache24/data/mythweb

Apache 2.4 runs as user and group “www” on FreeBSD/FreeNAS, so update the permissions accordingly:

chgrp -R www /usr/local/www/apache24/data
chmod -R g+rw /usr/local/www/apache24/data

TV Icons

I copied mine into my jail, then across to MythWeb’s TV icons directory:

cp /mnt/storage/channelicons/* /usr/local/www/apache24/data/mythweb/data/tv_icons

Mythweb Apache Config File

The Mythweb Apache config file (“/usr/local/www/apache24/data/mythweb/mythweb.conf.apache“) is a bit out of date for Apache 2.4 and PHP 5.6, so pull down the latest version directly to the directory you need it in.

cd /usr/local/etc/apache24/extra/
wget --no-check-certificate https://raw.githubusercontent.com/MythTV/mythweb/master/mythweb.conf.apache
cp /usr/local/etc/apache24/extra/mythweb.conf.apache /usr/local/etc/apache24/extra/mythweb.conf

Edit the “mythweb.conf" file and change the following:

<Directory “/var/www/html/data”>
to
<Directory “/usr/local/www/apache24/data/mythweb/data”>

and
<Directory “/var/www/html”>
to
<Directory “/usr/local/www/apache24/data/mythweb”>

My NAS has plenty of RAM, so I increase the PHP “php_value memory_limit” to 256M. Save the file and quit.

Make sure these lines are uncommented:

 setenv db_server "localhost" 
 setenv db_name "mythconverg" 
 setenv db_login "mythtv" 
 setenv db_password "mythtv"

Apache Config

Backup Apache’s original config file before editing “httpd.conf":

cp /usr/local/etc/apache24/httpd.conf /usr/local/etc/apache24/httpd.conf.original

Uncomment all these mods. The first two are usually on by default:

mod_env
mod_headers
mod_rewrite
mod_deflate
mod_auth_digest

Uncomment ServerName and change it to match what you’ve done previously in “/etc/hosts" e.g.:

ServerName mythserver.gavowen.local:80

In the “Supplemental Configuration” of the file, I place the following two lines:

# Mythweb configuration
Include etc/apache24/extra/mythweb.conf

Further down you’ll find the DirectoryIndex, where I add “index.php”

<IfModule dir_module>
 DirectoryIndex index.php index.html
</IfModule>

Directly below that part I add the following:

<FilesMatch ".php$">
 SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".phps$">
 SetHandler application/x-httpd-php-source
</FilesMatch>

Restart Apache:

service apache24 start

Now open a browser. Enjoy.

NB: Subsequent restarts of apache can be done with “apachectl graceful"

Troubleshooting

If the page doesn’t load try this:

create user 'mythtv'@'127.0.0.%' identified by 'mythtv'; 
create user 'mythtv'@'127.0.1.%' identified by 'mythtv'; 
set password for 'mythtv'@'127.0.0.%' = password('mythtv'); 
set password for 'mythtv'@'127.0.1.%' = password('mythtv'); 
connect mythconverg; 
grant all privileges on *.* to 'mythtv'@'127.0.0.%' with grant option; 
grant all privileges on *.* to 'mythtv'@'127.0.1.%' with grant option; 
flush privileges; 
exit;

There are other possible issues addressed at this link.

Time Issue

You might get a warning such as:

User Notice at /usr/local/share/mythtv/bindings/php/MythBackend.php, line 132:
 !!NoTrans: Failed to set php timezone to AEST Response from backend was Array ( [0] => AEST [1] => 36000 [2] => 2015-04-25T10:14:06Z ) !!
 Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /usr/local/www/apache24/data/mythweb/includes/errors.php on line 161

If that’s the case I find installing NTP a good solution:

pkg install ntp

Update “/etc/rc.conf" with the following:

ntpd_enable="YES"

Then start it with “service ntpd start". Issue “date" to see that it’s accurate. Then:

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

search for “date.timezone” and change it to suit. For me it’s date.timezone = "Australia/Melbourne"