Setup Guide for Plex on Raspberry Pi

mattjbones

Matt 🦕

Posted on November 26, 2020

Setup Guide for Plex on Raspberry Pi

Media streaming isn't a new thing and since the early days of the internet home media setups have been fairly common. What has changed is the hardware needed powering such a setup. The RasperryPi 4 is a powerful, pocket-sized, computer which can be setup as a home media server with very little cost or effort.

For this setup you'll need a RaspberryPi (4 if possible), a microSD card and an external drive of your media.

Starting simple

Steps

1. Flash SD Card with DietPi

2. Configure DietPi Automations

3. First boot

4. Configure Plex and Tautulli

Flash SD Card with DietPi

DietPi is my goto image when I'm working on RaspberryPi projects (I've written a little about this in the past as it offers a great base image, a simple software configuration and a ton of guides in their docs which is super helpful for getting started.

Head over to the website and download the DietPi image for your device (there are lots of platforms on offer). Each version of the RaspberryPi is catered for in one image:

DietPi image for RaspberryPi

Flashing the SD card can be done a number of different ways though I prefer the command line and there's a great guide on raspberrypi.com for macOS (and other plaforms).

Command Line

In short, use diskutil list to find the SD card, then unmount with diskutil unmountDisk /dev/diskN where diskN is the SD card. e.g

DietPi_RPi-ARMv6-Buster-3 % diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI ⁨EFI⁩                     314.6 MB   disk0s1
   2:                 Apple_APFS ⁨Container disk1⁩         498.7 GB   disk0s2
   3:       Apple_KernelCoreDump ⁨⁩                        1.3 GB     disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +498.7 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     333.7 GB   disk1s1
   2:                APFS Volume ⁨Preboot⁩                 428.0 MB   disk1s2
   3:                APFS Volume ⁨Recovery⁩                1.2 GB     disk1s3
   4:                APFS Volume ⁨VM⁩                      4.3 GB     disk1s4
   5:                APFS Volume ⁨Macintosh HD⁩            23.8 GB    disk1s5
   6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 23.8 GB    disk1s5s1

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *63.9 GB    disk2
   1:             Windows_FAT_32 ⁨boot⁩                    268.4 MB   disk2s1
   2:                      Linux ⁨⁩                        63.6 GB    disk2s2
Enter fullscreen mode Exit fullscreen mode

In my case this is disk2 as the other disks are APFS macOS Volumes and contain boring things like the operating system and my photos.

Next we need to unmount that disk and then copy the image (I've openned terminal inside the folder of the DietPi image)

diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=DietPi_RPi-ARMv6-Buster.img of=/dev/rdisk2; sync
Enter fullscreen mode Exit fullscreen mode

If you have issues running this command the RaspberryPi guide has some suggestions.

balenaEtcha

Alternatively DietPi recommends using balenaEtcha to flash the drive which offers a more friendly UI to select images, disks and flashes the SD card for you.

Either balenaEtcha or the command line should result in a flashed SD card that looks something like this:

Contents of the flashed DietPi SD

With the fresh DietPi SD card we're in a good position to plug in a monitor, keyboard and mouse, then start up the Pi. If you are curious and want to try configuring it for yourself then try it out, you'll be taken through the DietPi setup and their helpful software configuration.

However I much prefer to automate as much of the first setup as possible, it's far more reliable and requires less fiddling with DietPi.

Configure DietPi Automations

When I say automate I mean that we're going to configure the DietPi image with a baseline set of software (on top of what is already provided). To do this we need to add a few lines to the /boot/dietpi.txt file on the SD card we just flashed. We can also pre-configure Wifi too however for the purpose of this setup I'm assuming wired ethernet but the approach is similar.

Adding software

If you open the dietpi.txt you'll find a load of configuration options and to make things easier you'll probably find ⌘ + F is your friend here.

I recommend copying dietpi.txt to your desktop then making the changes there, don't forget to copy it back onto the SD card when you're done though.

From this list we need to find the corresponding codes for Plex (42), Tautulli (146), RPi Monitor (66). We'll also need some utilities to read exFAT drives (more on that later).

Add a AUTO_SETUP_INSTALL_SOFTWARE_ID line for each softare you're configuring, e.g:

...

# Software to automatically install
# - List of available software IDs: https://github.com/MichaIng/DietPi/wiki/DietPi-Software-list
# - Add as many entries as you wish, one each line.
# - DietPi will automatically install all pre-reqs (e.g. ALSA/X11 for desktops etc)
# - E.g. the following (without the leading "#") will install the LXDE desktop automatically on first boot:
#AUTO_SETUP_INSTALL_SOFTWARE_ID=23
#Plex
AUTO_SETUP_INSTALL_SOFTWARE_ID=42

#Tautulli
AUTO_SETUP_INSTALL_SOFTWARE_ID=146

#RPi-Mon
AUTO_SETUP_INSTALL_SOFTWARE_ID=66

...
Enter fullscreen mode Exit fullscreen mode

These changes will automatically install the above software when DietPi runs its first time setup.

Next we need to create a small install script to allow the Pi to read from exFAT and other windows partitions (we're likely adding an external harddrive which will have some flavour of Windows filesystem). To do this we need to create a text file called Automation_Custom_Script.sh on the /boot/ drive. The script will only have one line:

#!/bin/bash
apt-get install -y exfat-fuse exfat-utils ntfs-3g 
Enter fullscreen mode Exit fullscreen mode

To enable this setup script we again need to modify dietpi.txt, find AUTO_SETUP_CUSTOM_SCRIPT_EXEC and change it to 1, e.g:

# Custom Script (post-networking and post-DietPi install)
# - Allows you to automatically execute a custom script at the end of DietPi install.
# - Option 0 = Copy your script to /boot/Automation_Custom_Script.sh and it will be executed automatically.
# - Option 1 = Host your script online, then use e.g. AUTO_SETUP_CUSTOM_SCRIPT_EXEC=https://myweb.com/myscript.sh and it will be downloaded and executed automatically.
# - Executed script log: /var/tmp/dietpi/logs/dietpi-automation_custom_script.log
AUTO_SETUP_CUSTOM_SCRIPT_EXEC=1
Enter fullscreen mode Exit fullscreen mode

Finally we need to let DietPi know to use all our automations so, find AUTO_SETUP_AUTOMATED and change it to 1.

You can download both dietpi.txt and Automation_Custom_Script.sh if you please.

Finishing Touches

There are a bunch of other options for the setup of the system so feel free to have a play. One line which might be worth changing is AUTO_SETUP_NET_HOSTNAME which defaults to "DietPi".

First Boot

If you've decided to setup the automations from the previous section then this step should be seamless. Plug you SD card into your pi, make sure there's ethernet, and the power it up. The setup process can take a bit of time but after about ~10 minutes you should be able to visit the IP address of the Pi on port 8888, e.g. 192.168.0.151:8888.

If you're impatient / worried, like I was, you can always try SSH'ing to the Pi to make sure it's behaving ssh dietpi@192.168.0.153 with the password dietpi. You should see something that looks like this:

Impatient Pi

After some time the setup should complete, once you're able to visit the RPI-Mon page (192.168.0.153:8888 in my case) you should be able to move onto the next, and final, step.

DietPiMon status

It's worth SSH'ing into the Pi to check the first time setup has completed too (otherwise it will reboot as you're configuring the other services)

Configure Plex and Tautulli

We can configure Plex and Tautulli. To do so we simply need to hit the local webservers for each of these services i.e the local webservers we just installed on the Pi.

For Plex visit: http://192.168.0.151:32400/web/index.html

For Tautulli visit: http://192.168.0.151:8181

(You IP address is likely to be different)

During the Plex setup it will ask you to add a library for your media, at this point you should connect your USB drives and click Browse. What you should see is a bunch of directories none of which are your drive, why? Well Linux needs to mount USB drives to make them available to the operating system.

Ideally this would be handled automatically, howecer I've yet to find a good solution for this, though usbmount looks promising.

Mounting Drives for Plex

To mount a drive on the Pi first SSH over to the machine ssh dietpi@192.168.0.151 with the password dietpi.

Once logged in we first need to create a folder for the drive to be mounted, run sudo mkdir /media/my_drive to create the folder. Next we need to mount the actual drive, run sudo fdisk -l and look for your drive (hint Disk model is usually provied for USB drives).

Disk /dev/sda: 57.3 GiB, 61530439680 bytes, 120176640 sectors
Disk model: Ultra Fit       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbba82a87

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1          32 120176639 120176608 57.3G  7 HPFS/NTFS/exFAT
Enter fullscreen mode Exit fullscreen mode

When you've identified the drive we need to instruct linux where to mount it

sudo mount /dev/sda1 /media/my_drive
Enter fullscreen mode Exit fullscreen mode

All things being well the Pi should mount your drives and they will be available under /media/ when you go back to Plex (refresh first).

Make sure to login with your Plex account, if you're lucky you'll be able to configure remote access (the port forwarding needed differs across routers but some will do it automatically.)

Tautulli

Once your Plex server is up and running you can start Tautulli.

Tautulli is a service that look at all the Plex server metadata to give you an overview of how much media is being watched, by whom and on what device - especially useful when sharing your Plex server with friends and family.

Sit back and enjoy

That's it, you should now be able to watch your media anywhere via one of the many Plex apps!

I hope you enjoyed this guide, I would like it to be an entirely plug and play experience with the USB drives and I suspect I will do a followup post when I figure that part out. Feel free to reach me on Twitter with any feedback and enjoy your Pi powered media server.

First appeared on my blog, published 26th November 2020

💖 💪 🙅 🚩
mattjbones
Matt 🦕

Posted on November 26, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Setup Guide for Plex on Raspberry Pi
raspberrypi Setup Guide for Plex on Raspberry Pi

November 26, 2020