Plex Media Server on Raspberry Pi 3 using Raspbian Lite (Jessie)

Neha M
12 min readMar 13, 2017

--

UPDATE: I have an updated version of this blog here — https://medium.com/@nem25/plex-media-server-on-raspberry-pi-3-using-raspbian-lite-stretch-feace75f2b1d

If you want to update from Jessie to Stretch, I found this tutorial but I haven’t tried it as I didn’t need it — http://baddotrobot.com/blog/2017/10/26/upgrade-raspian-jessie-to-stretch/

This is a step by step guide to set up your own media server using Plex on a Raspberry Pi 3 with an external HDD containing all the media files.

Note: The guide might be a bit lengthy as I have added explanations to some of the steps as well. I did this tutorial while learning myself and I thought it would be useful for people to know what some of the commands mean.

You will need…

  • Raspberry Pi 3 (with its power adaptor)
  • Larger than 8GB micro SD card for the pi
  • Monitor (initial setup of the pi) — HDMI connection
  • Keyboard (initial setup of the pi)
  • Mouse (initial setup of the pi)
  • External HDD with its own power source
  • Internet connection (This tutorial is for a WiFi setup on the pi)
  • A laptop or computer that has a memory card reader (or an external memory card reader)

Topics being covered…

  1. Setting up Raspbian (a Raspberry Pi OS) on the SD card
  2. Connecting all the components of the pi
  3. Connecting the pi to WiFi
  4. Fixing the IP address of the pi
  5. Using SSH to connect to the pi with a Linux computer
  6. Setting up Plex on the pi
  7. Connecting external HDD
  8. Managing metadata of Plex on HDD (optional)
  9. Adding Plex libraries
  10. Setting up samba share for the external HDD (optional)
  11. Updating your Plex server

Setting up Rasbian on the SD card

Before connecting the raspberry pi to any power source, we must install an operating system on the pi — Raspbian. For this you will need a computer or laptop that has a memory card reader or you will need to connect an external memory card reader.

Note: For this tutorial, I used the Lite version of Raspbian as most of the setup is via the terminal but you can also download the full version which comes with a GUI and then use a terminal for the instructions.

Download a Raspbian image

Install etcher.io

It will help you install Raspbian on the SD card.

Flash SD card

  • Insert SD card into reader
  • Format SD card using Fat32 format
  • Launch etcher on your computer
  • Select the Raspbian image you just downloaded
  • Etcher should automatically find your SD card
  • And flash your SD card

Need more HELP?
If you need further assistance in installing Raspbian on the pi, you can use the NOOBS installer. More information is available here — https://www.raspberrypi.org/documentation/installation/installing-images/README.md

Connecting up the pi

  1. Connect the monitor, keyboard and mouse to the pi
  2. Insert the SD card
  3. Connect the power adaptor. Make sure this connection is done last as the pi will start once the power is on
  4. Put the power on
  5. If the OS was installed properly, you should see it starting up :)
  6. A lot of text will scroll up on your screen; this is normal
  7. Next, it will ask you for a login
    username: pi
    password: raspberry
  8. That’s it! You are in

Note: If you installed the full version of Raspbian, you will see a GUI. Please open a terminal for the following steps

Connecting to the internet (WiFi)

The first thing we need to do is connect the pi to the internet so you can SSH into it from your everyday computer without the need of connecting the pi to a monitor, keyboard and mouse. And we will need the internet to download all the software and get Plex running on your home network.

Note: If you are directly connecting the pi via an ethernet cable, you can skip this section and go straight to fixing your IP address

Find your network

First, we need to find the details (ESSID and Encryption) of your WiFi network. This will be very similar to the name of your WiFi.

  1. Enter the following in your terminal:
sudo iwlist wlan0 scanning | egrep 'Cell |Encryption|ESSID'

Note: This is a modified version of sudo iwlist wlan0 scan which has a lot of additional information. We only need the ESSID and Encryption type.

2. Note down the ESSID and make sure you have your WiFi password handy.

3. Check the encryption of your network; it should be WPA2. Other encryption types are out of scope for this tutorial.

Add network to your pi’s configuration

  1. In the terminal:
wpa_passphrase "MyWiFiESSID" "MyWiFiPassword" >> /etc/wpa_supplicant/wpa_supplicant.conf

Two things are happening here:

wpa_passphrase "MyWiFiESSID" "MyWiFiPassword" will create a network profile with your password replaced by a token so that it is not saved as plain text.

>> /etc/wpa_supplicant/wpa_supplicant.conf will add the network profile to your configuration file.

2. Now we need to remove the plain text password that also gets copied into the config file. In the terminal:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

3. Scroll down to your profile; it should be write at the end and will look like this:

network={
ssid="MyWiFiESSID"
#psk="MyWiFiPassword"
psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
}

4. Remove #psk="MyWiFiPassword"

5. Ctrl+O (to write your changes), Ctrl + X (to exit)

Check your connection

Let’s make sure your pi is connected to the internet

ifconfig wlan0

Look for the field inet addr If it has an address beside it, then you are connected, otherwise check your network profile again.

Need more HELP?https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

Fixing your IP address

Or providing your pi with a static address. This is important because when your pi restarts, a new ip address will get assigned. This will make it difficult to SSH into it and accessing the Plex server, both of which need an IP address.

We need three pieces of information to set a static address:

  • Quite obviously, your pi’s current IP address
  • Address of your gateway/router
  • Address of your nameserver
  1. IP address
    Enter ifconfig wlan0
    Note down the address at inet addr
  2. Gateway address
    Enter ip route | grep default
    Note down the address
  3. Nameserver
    Enter cat /etc/resolv.conf
    This will output the contents of the resolv.conf file. Note down the address by nameserver

Now we need to add this to the dhcpcd.conf file. Open the file for editing…

sudo nano /etc/dhcpcd.conf

Scroll all the way to the bottom of the file and add the following…

interface wlan0
static ip_address=<ip address>/24
static routers=<gateway address>
static domain_name_servers=<nameserver address>

Make sure that the IP address has /24 at the end of it. Below is an example profile:

interface wlan0 
static ip_address=10.1.1.31/24
static routers=10.1.1.1
static domain_name_servers=10.1.1.1

Note: The new Raspbian Jessie requires using the dhcpcd.conf file to fix the IP address. Older methods no longer work.

Now sudo reboot the pi and make sure the IP address doesn’t change after it restarts.

Using SSH to connect to the pi

It’s not always convenient to connect the pi to a monitor and the rest of the peripherals to use it. Ideally, we connect to it remotely through our regular computers. This is done via SSH.

In the recent version of Raspbian, SSH is disabled by default. So first we need to enable it. Enter…

sudo raspi-config

This will open Raspbian’s configuration options.

  1. Select Interfacing options
  2. Enable SSH

Note: In older versions of Raspbian Jessie, the SSH option is under Advanced.

Now we will connect to the pi remotely using our eveyday laptops or computers. I used a Linux machine to connect to my pi, but for Windows users, you will need to install an additional tool — Putty, in order to SSH into another computer.

On a Linux computer, it’s very straightforward. Open a terminal and enter…

ssh pi@<static ip address>

Here you need to enter the static IP address that we set in the previous step. The first time you connect, it will ask you if you trust this fingerprint. Select ‘Yes’.

You will need to enter your pi’s password, which should be raspberry unless you changed it.

If you connect successfully, your terminal’s prompt will change to pi@raspberrypi Now you can remove the monitor, keyboard and mouse from the pi as you no longer need them. And the rest of the instructions are done from your regular computer by SSH’ing into it.

Note: For more information on setting up SSH — https://www.raspberrypi.org/documentation/remote-access/ssh/README.md

Setting up Plex on the pi

Finally, we are all set with the pi setup and we can start installing and configuring the Plex Media Server.

First, let’s make sure the pi is up to date…

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get update && sudo apt-get dist-upgrade

Now we install HTTPS download transport for APT so that we can access metadata and packages over HTTPS

sudo apt-get install apt-transport-https -y --force-yes

Next, we need a key to authenticate the Plex download

wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key  | sudo apt-key add -

Let’s add the Plex repository to our sources list

echo "deb https://dev2day.de/pms/ jessie main" | sudo tee /etc/apt/sources.list.d/pms.list

Update again

sudo apt-get update

Install Plex Media Server

sudo apt-get install -t jessie plexmediaserver -y

Now we restart the pi, to make sure Plex is running

sudo reboot

To access Plex from your computer, open your favourite browser and enter the following

<static ip address>:32400/web

Here, <static ip address> is your pi’s IP address.

If you see the Plex dashboard come up, then everything is installed properly and Plex is running on your pi. You probably won’t see any media files since no libraries have been added yet.

Connect External HDD

The raspberry pi’s SD card does not have much memory to hold your media files so it’s always best to connect a larger external HDD (which has its own power source) to manage all your media files.

  1. Connect the HDD to your pi
  2. Make sure that the HDD is connected and note down the HDD’s path. If your drive already has a label simply run
sudo blkid

This will give you a list of all the drives connect to your pi and their locations. In most cases this should be /dev/sda1

If you are not sure about your HDD’s label and need to look at disk sizes as well, then use

sudo fdisk -l

3. Now we need to create the directory where we wish to mount the HDD

sudo mkdir /mnt/library

4. Give the correct permissions to the directory

sudo chmod 775 /mnt/library

5. Now we need to mount the drive to that location.

In order to do this, we need to know what format our drive is in. You can use sudo blkid to check this.

In my case, my drive was formatted as NTFS. There is an additional step for this. We need to install a library that supports NTFS formatted drives.

sudo apt-get install ntfs-3g
sudo mount -t ntfs-3g /dev/sda1 /mnt/library

6. We need to make sure that every time the pi restarts, the external HDD is always mounted to the same location. This is important because you will be add your media libraries to Plex and we need to make sure that path does not change.

Edit the fstab file

sudo nano /etc/fstab

And enter the following line at the bottom of the list

/dev/sda1       /mnt/library    ntfs-3g defaults          0       0

This will auto mount the drive on a restart.

So, as always, let’s reboot and check :)

sudo reboot

Browse to /mnt/library and check if your HDD’s directories show up there.

Managing Plex metadata on the HDD (optional)

Plex metadata tends to get very large and so I felt more comfortable putting it on the external HDD rather than having it on the pi’s SD card, where it is located by default.

The Plex data is located at the following location on the pi:

/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/

First we make a backup of this folder,

sudo cp -r /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server /var/lib/plexmediaserver/Library/Application\ Support/server.backup

Now we create a directory on the mounted HDD to move the Plex data to

mkdir /mnt/library/plex-data

Let’s copy over the data from the current location to the new location we just created,

sudo cp -r /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server /mnt/library/plex-data

Make sure that the data has copied over at the new location by doing

ls /mnt/library/plex-data

There should be a folder called Plex Media Server if all has gone well :)

Now we need to symlink the original location to the new location on the HDD.

sudo ln -s /mnt/library/plex-data/Plex\ Media\ Server /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server

Make sure the symlink is created,

ls /var/lib/plexmediaserver/Library/Application\ Support

Note: More information here on things you can do to manage the Plex Server data directory-https://support.plex.tv/hc/en-us/articles/202529153-Why-is-my-Plex-Media-Server-directory-so-large-

Adding Plex Libraries

This is the easy bit. Go to your Plex Server — on your browser…

<static ip address>:32400/web

Since this is a fresh install of Plex, you will be asked to add a library. Select the type of library you want to create. For this tutorial, let’s select Movies.

Enter a name for your library,

And then click Browser for Media Folder. Here comes the interesting bit where we will now point to the mounted HDD that you created a few steps above… /mnt/library

Select your Movies folder and click Add. Do have a look at the Advanced setting as well before Adding the Library — they are self-explanatory.

Once you have added the library, Plex will download the metadata. Depending on the size of your media libraries, it might take some time. Now you can stream your media to any device that has a Plex player or you can browse to the server as well.

Setting up the external HDD as a samba share

In my case, I have a Windows desktop that I wanted to use to add media files to the external HDD connected to the pi — but disconnecting the HDD from the pi and connecting to the Windows machine is not an ideal solution :) So we set the HDD up as a samba share with read/write permissions so that any computer can access the HDD on your home network to copy and edit files.

sudo apt-get install samba samba-common-bin -y

Back up the samba config file,

sudo cp /etc/samba/smb.conf /etc/samba/smb.bak

Then we edit it,

sudo nano /etc/samba/smb.conf

Find the following lines,

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
# wins support = no

Uncomment the following line by removing the # and setting it to yes,

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
wins support = yes

Scroll down to the section that says Share Definitions and add the following profile.

[PLEXMEDIA] #Name of the share
comment = Plex media share
path = /mnt/library/
create mask = 0775
directory mask = 0775
read only = no
browseable = yes
public = yes
force user = pi
only guest = no

Ctrl+O (to write out) and Ctrl + X (to exit)

Next, we set a samba password, although the above configuration allows anyone on your home network to access the directory,

sudo smbpasswd -a pi

If you want to add authentication for the samba share, I haven’t tried it out yet but I have found these resources:

Once I try it out myself, I will update the post :)

And then, restart to check if you can access the share from your Windows machine…

sudo reboot

Updating your Plex server

In order to update your server, simply ssh into the pi,

ssh pi@<static ip address>

Then update & upgrade,

sudo apt-get update
sudo apt-get upgrade

Mnemonic: I always get confused as to whether it’s update first or upgrade, so here’s a mnemonic to remember the order. Look at the third letter of each word (basically both start with ‘up’ so we can remove those): ‘d’ and ‘g’. d comes before g in the alphabet, so update comes first and then upgrade .

Then, as always,

sudo reboot

Hope this guide was useful and if there are any comments/edits/problems/questions, please do ask away :) All feedback is welcome.

And if you have some steem, you can support the article here — https://steemit.com/tutorial/@neha-m/plex-media-server-on-raspberry-pi-3-using-raspbian-lite

References

Apart from the ones I cited through the tutorial, the raspberry pi and Plex documentation are very helpful as well. And…

--

--