Building a TV Server on a Raspberry Pi

Before you begin:

You will need to donate $20 to to get a version of the software that will run on your Synology if it uses an ARM processor and won’t run the standard x86 version that you can download from the site. The DS216+II in this tutorial has an Intel x86 / x64 processor so the standard x86 version will work just fine.

You will also need a subscription to Schedules Direct.

Download Rasbian Lite from the Rasbian website. The iscsi initiator service is missing from this image so you will need to recompile the kernel in order to add it. Once installed, you will need to do the following:

sudo raspi-config #Expand File system and enable SSH
sudo apt-get update
sudo apt-get upgrade

Next, we will need to install some packages for an on-device kernel recompile:

sudo apt-get install open-iscsi git gcc make python libncurses5-dev bc bison flex libssl-dev

Lets create a folder in which to keep the various content we’ll need for the kernel rebuild:

mkdir /home/pi/rpi
cd /home/pi/rpi

We now need to fetch the kernel sources to build from, this will take a while:

git clone --depth 1

Now take a copy of your current running kernel configuration, which we can then alter:

sudo modprobe configs
cd /home/pi/rpi/linux
zcat /proc/config.gz > .config

Now let’s load the system’s UI-based kernel configuration editor (these changes can be adjusted manually, but the UI is simple):

make menuconfig

Once the UI has loaded, navigate to the “Device Drivers” section (enter to navigate between pages, space to change an option), then “SCSI device support”, then “SCSI Transports”. Change the “iSCSI Transport Attributes” option twice (so that it shows a *) to build it into the kernel. Go back a page, hit space for “SCSI low-level drivers” to enable this option, then enter to descend into it, then space twice for a * on “iSCSI Initiator over TCP/IP”.

Once these options are enabled, exit the UI and save changes. To ensure these are set, run:

grep ISCSI .config

This should return the following:


With this in place, compile your new kernel:

– for mono core CPU :


– for 4 core CPU (Pi 2 B) :

make -j5

This process will take in the region of 4-6 hours to complete.

Once done, we need to generate an image of this kernel for the Pi to boot from, then replace your existing kernel:

First up, we need the mkimage python tool:

cd /home/pi/rpi
git clone

Now build the image:

cd /home/pi/rpi/tools/mkimage
sudo python /root/raspberrypi/linux/arch/arm/boot/Image

Now create a backup of your existing kernel, then replace the running kernel with the newly-generated one:

sudo cp /boot/kernel.img /boot/kernel.img-backup
sudo cp kernel.img /boot/kernel.img

With this done, reboot your pi into your new iscsi-enabled kernel:

sudo reboot

If you have any problems with booting at this point, you can always revert to your old kernel by mounting your SD card into a card reader on another system, then revert kernel.img-backup to kernel.img.

Now edit /etc/iscsi/iscsid.conf changing the following:

node.startup = automatic

Then start the service:

sudo service open-iscsi start

Assuming all has gone well, you can now use iscsiadm to discover then login to your iscsi target (though hopefully youll already be familiar with configuring an initiator to access a target), for example:

iscsiadm -m discovery -t st -p X.X.X.X

where the IP address in the above should be the address of your iscsi target, then once it has been discovered, login to the target with:

iscsiadm -m node

Next create the iscsi folder that will store all of the recordings:

sudo mkdir /recordings
sudo chown pi:pi /recordings
sudo chmod 777 /recordings

Now edit /etc/fstab adding the following line replacing ‘X’ with an unused device on your system (i.e. ‘sdb1’):

/dev/sdX1   /recordings   ext4   defaults,auto,_netdev   0   0

Install TVheadend server:

Now that your Raspberry Pi is fully up to date, you need to run the following commands:

sudo apt-get install dirmngr

This command may not need to be run, however, for me, TVheadend would not install without it.

sudo apt-key adv --keyserver hkp:// --recv-keys 379CE192D401AB61

More info about installing the GPG keys can be found here.

echo "deb raspbianstretch stable-4.2" | sudo tee /etc/apt/sources.list.d/tvheadend.list

Again, more info on where to get the correct repo for the RPi is here.
Check and make sure the correct one is used. This can update at times.

sudo apt-get update

In a nutshell, we are telling ‘apt-get’ to grab any updates from the repository we added above. This will then allow us to install TVheadend because it now knows where to ‘grab’ it from.

sudo apt-get install tvheadend xmltv-util

Select ‘Y’ and allow TVheadend to install. If you tried to run this command without doing the steps above, you would run into errors

During the install, you will be asked to set an administrator username and password. (See Screenshots below!) Be sure to set this correctly and remember. You do not get two chances to enter the password. I learned this the hard way!

If for some reason, you did stuff up the username and password. Uninstall tvheadend with:

sudo apt-get purge tvheadend


sudo apt-get autoremove

Then reinstall tvheadend again.

Now reboot:

sudo reboot

Log into TVheadend:

Open up a web browser and enter the IP address of your Raspberry Pi. Also, use the port number ‘9981’. For example (Your IP address for the RPi will be different.) Type ifconfig in the terminal screen to confirm RPi IP address.

When you first open Tvheadend, you will get the Wizard which will step you through setting up the tv tuners. Hopefully, you left them plugged in from the start. If not, plug them in and restart the Raspberry Pi. Go back into the web browser and log back into TVheadend.

Now find out where TVheadend saves all the settings. It’s usually saved within the HTS user’s home directory, but on my machine it happened to be saved under /var/lib/tvheadend. You will need to save an xml file inside the .xmltv folder using the tv_grab script file. I am in the US, so the script file I am using is tv_grab_na_dd. I first run tv_grab_na_dd –configure and accept all of the defaults. Then I run tv_grab_na_dd –out /var/lib/tvheadend/.xmltv/tv_grab_na_dd.xml. Now you should be able to set up the TV listings in TVheadend.