Getting kodi to run nicely on Raspbian

This blog post is about getting Kodi up and running with Netflix on Raspbian. This is not a tutorial, more a collection of notes for myself in order to reproduce the setup.

Basic install

Get a recent version of Raspbian from the Raspberry Pi website. (Or my ftp mirror). Extract it to a fresh micro-SD card and get the system ready. Follow this guide, if you need help. Boot into the system and run a update and install some handy tools

sudo apt update && sudo apt upgrade
sudo apt install git tmux screen htop iftop iotop
useradd kodi
usermod -aG audio,video kodi

Next, we are gonna harden the system. For that do the following

  • Set root password
  • Rename user pi to something else
  • Remove the NOPASSWD for user pi
  • Permit root-ssh login only via public key

Install Kodi

First add the following repository

# editor /etc/apt/sources.list.d/pipplware_unstable.list
deb http://pipplware.pplware.pt/pipplware/dists/unstable/main/binary /

Now install kodi

sudo apt update
sudo apt install kodi

Autostart Kodi

Ok, kodi is installed, now we need to start kodi. For that we create a systemd service by putting the following to /etc/systemd/system/kodi.service

[Unit]
Description=Kodi standalone
After=systemd-user-sessions.service network-online.target sound.target mysqld.service
Requires=network-online.target
Conflicts=getty@tty1.service

[Service]
User=kodi
Group=kodi
PAMName=login
TTYPath=/dev/tty1
ExecStart=/usr/bin/kodi-standalone
Restart=on-abort
StandardInput=tty

[Install]
WantedBy=graphical.target

Install the Netflix Plugin

The Netflix Plugin is hosted on GitHub. Download the plugin and install the zip-file. Best option seems to be to put it on a USB-Stick and install it from there. This plugin needs parted or fdisk, you install them on your kodi and then let the plugin install the widevine library, necessary for the DRM. The DRM is by the way also the thing, that was in the way of getting Netflix work in the first place. And it’s still a bit of a mess, since we are using here a extraction of the libwidevine from the chromecast.

Well, as long as it works, but it’s not nice and probably creating causing one or two times headache until it finally works.

Allow Kodi to reboot and shutdown

This is now more a quick fix, based on the suggestion from here. The original clue was posted long time ago on the kodi forums, but those posts were only of limited help. So, create the following file

# editor /etc/polkit-1/localauthority/50-local.d/all_users_shutdown_reboot.pkla
[Allow all users to shutdown and reboot]
Identity=unix-user:*
Action=org.freedesktop.login1.*;org.freedesktop.upower.*;org.freedesktop.consolekit.system.*
ResultActive=yes
ResultAny=yes
ResultInactive=yes

Finetuning

I encountered the problem, that if Kodi runs for too long (multiple days), the Netflix plugin stopped working. No errors given, it just won’t play a movie again. A quick fix is to schedule a reboot every night using a cronjob

crontab -e

# Reboot the system every night at 5am
0 5   *   *   *    /sbin/shutdown -r now

Further work

This is of course just the basic installation. You will need to configure Kodi to your needs (Skins, Addons, Timezone, connect your NAS, …)

Also, I might create an ansible-playbook to setup this procedure. This looks like a fun project to do on a really really rainy Sunday.


Now, if you execuse me, I’ve got some serious Netflix to do :-)

Licensed under CC BY-NC-SA 4.0
Last updated on Apr 04, 2019 19:58 UTC