Creating your personal media server with Raspberry Pi and Plex

Creating your personal media server with Raspberry Pi and Plex

ยท

5 min read

Introduction

For some time now, I had been planning to create a personal media server, something which would allow me to access personal media from anywhere, at any time. Ease of use was also something very important to me since my family would be using it as well. I had heard about Plex before but never got around to actually using it. I had a Raspberry Pi 4 which was collecting dust, and I decided to repurpose it as the brains of my personal media server.

Why Plex?

For the uninitiated, Plex is a popular media server software which allows you to stream and organize your media files. It has a great user interface and is super easy to set up. It can transcode media content on the fly which means you probably won't run into compatibility issues with your files. It also is completely cross-platform which adds to the ease of use.

What's a Raspberry Pi?

You probably may have heard about Raspberry Pi before, quite possibly from the TV show Mr Robot. Here's a great hacking scene from the show, where the Raspberry Pi was heavily used.

Essentially, it's a credit-card-sized single-board computer which has gained popularity among hobbyists due to its versatility and plentiful use cases.

Prerequisites

  1. Raspberry Pi 4 (4GB ram recommended)

  2. USB Pendrive (16GB recommended)

  3. Windows 10/11 with WSL enabled (for Rsync)

Setting up Plex and Raspberry Pi

Connecting with SSH

I won't be going over the initial setup of the Pi and the installation of Raspbian OS since you'll find many articles for the same. Here's a great guide on getting started with the Pi. I'll show the steps to set up SSH which will help us connect to our Pi remotely.

  1. Find the IP address by typing, hostname -I in the terminal, on your pi device.

  2. On your computer, open up a terminal or a command prompt, and enter,

    ssh pi@ip_address (replace ip_address with your Pi device IP).

  3. You'll be asked to enter a password, go ahead and enter 'raspberry'.

Installing Plex Media Server

  1. Before we get into installing Plex, make sure you have the latest packages and your operating system is up to date, with the following commands:
    sudo apt-get update && upgrade -y

  2. Once the update finishes, we'll need to install the 'apt-transport-https' package, which will allow us to retrieve packages over the https protocol.

    sudo apt-get install apt-transport-https

  3. We'll now be adding the Plex repositories to the "apt" keyrings directory. You can learn more about keyrings here.

    curl https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor | sudo tee /usr/share/keyrings/plex-archive-keyring.gpg >/dev/null

  4. Finally, we'll add the official plex repository to the sources list and also run an "update" to refresh the packages.

    echo deb [signed-by=/usr/share/keyrings/plex-archive-keyring.gpg] https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list

    sudo apt-get update

  5. We can now go ahead and install plexmediaserver

    sudo apt install plexmediaserver

Setting a Static IP Address

To make sure, your Plex Media Server is always found at the same address, we'll be using a static IP address.

  1. We need to open the cmdline.txt file with nano or any other text editor:

    sudo nano /boot/cmdline.txt

  2. We add the following line with the IP of our Raspberry Pi.

    ip=IP_ADDRESS

  3. If you've used nano, close the file using Ctrl + X and save with Y

With our Pi device running, we'll go ahead and open the Plex web interface in our browser. The address will be the IP of your Raspberry Pi, followed by port 32400. If you haven't already, create a Plex account and log in.

Automounting USB drive

The USB drive which you insert into the Pi will contain all the multimedia that you want to share. We'll be setting up automount for that drive, which will help us access our media on Plex, without the need to mount the drive every time we start the Pi.

  1. Once you've inserted your device, run the following command to see a list of all connected devices.

  2. Identify your USB drive, and run the following command to retrieve additional information regarding your drive. Note down the UUID mentioned in the output.

  3. Now we'll go ahead and create a folder and also assign permissions.

    sudo mkdir -p /mnt/usb

    sudo chown -R pi:pi /mnt/usb

  4. Next, we need to modify the fstab file with the UUID of our drive. Modify the file like the image below, and make sure to replace 'ntfs' if you have a different filesystem on your drive.

    sudo nano /etc/fstab

  5. Finally, we need to unmount our drive and mount it again for our changes to take effect.

    sudo umount /dev/sda1

    sudo mount -a

Finally, on the Plex web interface, we can now add the folder that we created in the last step and start streaming our files!

Optional

Setting up Rsync

Rsync is a file transfer and synchronization tool which will allow us to easily transfer files to our USB drive on the Pi. If you are using Windows, you'll need to set up WSL2. Here's a guide for installing Ubuntu on WSL2.

  1. Once you have Ubuntu set up on WSL2, make sure to update your packages.

    sudo apt update

  2. Install rsync with the following command.

    sudo apt install rsync -y

  3. Run the following command to transfer your file to your USB drive.

    rsync -avp /mnt/c/Videos/down-a-highway.mp4 pi@192.168.29.56:/media/usb

  4. Scan the library files on Plex Media Server, and you'll be able to notice the transferred files.

Conclusion

You should now be able to stream your videos, pictures and songs through the Plex Media Server! Hopefully, this has been a fun project for you and now have a central hub for all your media content.

Thank You For Reading ๐Ÿ‘

Check out my other articles or get to know me at vinaybomma.github.io

ย