Installing TVHeadend on RPi2 with Arch Linux
A Raspberry Pi is perfectly suited to run a TVHeadend server - for receiving live TV, for example. In this post, I explain how such a server can be run on an RPi2 with Arch Linux ARM.
I would like to receive live TV via DVB-T2 and stream it into my LAN. As streaming server, I would like to use TVHeadend. In my setup, the DVB-T2 signal is received by an antenna, which is connected to a USB tuner, which in turn is connected to the RPi. The RPi is connected to the LAN and streams the live TV.
Often, Raspbian is used as OS for an RPi, but since I am a fan of Arch Linux, I wanted to use it as the basis for my server. For this project I use the ARM port of Arch Linux. In a nutshell, the following steps need to be executed:
- Install Arch Linux ARM
- Configure Arch Linux ARM
- Install Yay to be able to install packages from the Arch Linux User Repository (AUR)
- Install TVHeadend from AUR
- Configure TVHeadend and run it as a service
I use an RPi model 2, but these instructions could also be used to install Arch Linux ARM and TVHeadend on other computers with an ARM board. Just download the appropriate version of Arch Linux ARM and follow the corresponding installation guidelines for that version.
This how-to only contains the steps to set up the TVHeadend server. Since the configuration of DVB-T2 in TVHeadend depends on the country, it is not covered here. A good guide for Germany is provided in the Arch Linux wiki1.
Since I was asked which hardware I am using besides the RPi: As USB TV tuner, I use the DVBSky T330 receiver, which is currently sold in a bundle with a small antenna. The USB receiver is recognized by Arch Linux ARM out of the box, but it additionally needs firmware modules. They can be downloaded from the manufacturer's web site2. After you have gone through the entire installation instructions below, just unzip the downloaded firmware archive and copy the *.fw files via scp to the directory /lib/firmware on the RPi. Reboot and you should be done.
Install Arch Linux on Raspberry Pi 2
Arch Linux ARM is installed on the RPi2 according to these instructions3. Replace sdX in the described steps with the device name for the SD card as it appears on your computer.
Start fdisk to partition the SD card:
fdisk /dev/sdX
At the fdisk prompt, delete old partitions and create a new one:
- Type
o. This will clear out any partitions on the drive. - Type
pto list partitions. There should be no partitions left. - Type
n, thenpfor primary (that's the default),1for the first partition on the drive (that's also the default), press ENTER to accept the default first sector, then type+100Mfor the last sector. - Type
t, thencto set the first partition to typeW95 FAT32 (LBA). - Type
n, thenpfor primary,2for the second partition on the drive, and then press ENTER twice to accept the default first and last sector. - Write the partition table and exit by typing
w.
Format and mount the boot partition:
mkfs.vfat /dev/sdX1
mkdir boot
mount /dev/sdX1 boot
Format and mount the root partition:
mkfs.ext4 /dev/sdX2
mkdir root
mount /dev/sdX2 root
Download and extract the root filesystem:
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
sync
Move boot files to the boot partition:
cp -r root/boot/* boot/.
rm -rd root/boot/*
Unmount the two partitions:
umount boot root
Configure Arch Linux on RPi2
Insert the SD card into the Raspberry Pi, connect Ethernet, and apply 5V power. Use SSH to connect to the IP address given to the board by your router. Log in as the default user alarm with password alarm (the default root password is root).
ssh alarm@<ip-address>
Configure Pacman and upgrade system
Initialize the pacman keyring and populate the Arch Linux ARM package signing keys:
su
pacman-key --init
pacman-key --populate archlinuxarm
Upgrade the system:
pacman -Syu
Enable Sudo
Install sudo:
pacman -S sudo
Configure sudo:
nano /etc/sudoers
Remove the comment sign in front of the line
%wheel ALL=(ALL) ALL
Save the file (CTRL+O, ENTER) and exit (CTRL+X).
To allow user alarm to use sudo, add the user to group wheel:
gpasswd --add alarm wheel
Configure network
Set static IP address
Adjust the file /etc/systemd/network/eth0.network (replace eth0 with your interface):
nano /etc/systemd/network/eth0.network
Remove the line
DHCP=yes
Add the lines (replace the IP addresses with your addresses):
Address=192.168.0.100/24
Gateway=192.168.0.1
DNS=192.168.0.1
Save the file (CTRL+O, ENTER) and exit (CTRL+X).
Set host name
Edit the file /etc/hostname:
nano /etc/hostname
Replace the default host name with your host name. Save the file (CTRL+O, ENTER) and exit (CTRL+X).
Besides that, add the line
127.0.0.1 localhost
to /etc/hosts.
Reboot
Reboot the system:
reboot
Install Yay
These installation instructions are taken from the Yay README4.
Log in as the default user via SSH (now, you have to use the static IP address of the RPi):
ssh alarm@<static-ip-address>
Install Yay binary from AUR
sudo pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay-bin.git
cd yay-bin
makepkg -si
Install and set up TVHeadend
Install TVHeadend (this takes a while):
yay -S tvheadend-git
I used tvheadend-git instead of the stable version tvheadend since the stable version could not be built when I did the installation. tvheadend-git worked without problems.
Set up TVHeadend as a service and start it:
sudo systemctl enable tvheadend.service --now
You should now be able to access the browser UI of TVHeadend via the URL http://<static-ip-address>:9981.
Have fun with TVHeadend!