Plex Media Server on a Raspberry Pi 3

It has been a while since I wrote up a “how-to” for the Raspberry Pi and I thought I would share my latest project with you. I purchased a Raspberry Pi 3B+ to replace my RPi 2 as a media server. In case you are new to the Raspberry Pi. Here are the specs for the 3B+:

  • SOC: Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC
  • CPU: 1.4GHz 64-bit quad-core ARM Cortex-A53 CPU
  • RAM: 1GB LPDDR2 SDRAM
  • WIFI: Dual-band 802.11ac wireless LAN (2.4GHz and 5GHz ) and Bluetooth 4.2
  • Ethernet: Gigabit Ethernet over USB 2.0 (max 300 Mbps). Power-over-
  • Ethernet support (with separate PoE HAT). Improved PXE network and USB mass-storage booting.
  • Thermal management: Yes
  • Video: Yes – VideoCore IV 3D. Full-size HDMI
  • Audio: Yes
  • USB 2.0: 4 ports
  • GPIO: 40-pin
  • Power: 5V/2.5A DC power input
  • Operating system support: Linux and Unix

I have tried and tested many tutorials that I have found online, but this Medium post from Niha M is fantastic, Plex Media Server on Raspberry Pi 3 using Raspbian Lite (Stretch).

I followed all of Niha’s instructions but I had the following modifications:

  1. I am using a wired gigabit network and will not be using Wifi.
  2. I reserved a static IP address through DHCP reservation in my router.
  3. I left the metadata on the SD card.
  4. I attached a 2GB HDD and set up the SAMBA share to make it easier to transfer video, audio, and pictures from my laptop to the server.

I additionally set up a backup script for the SD card since I have had them go bad in the past. I followed the instructions from GrammatonCleric on the Ubuntu Forums.

What I did:
Filled the SD card with zeros because when I compress the image it will shrink down considerably.

dd if=/dev/zero of=/tmp/disk_zero_fill.tmp bs=8M; rm -f/tmp/disk_zero_fill.tmp

I then copied the entire drive to an image and compressed it, by creating an executable script.

bakup_sdcard.sh

####################
# set date variable
####################

tdy=`date +%m%d%Y`

##################################
# Remove img.gz files older than 21 days
##################################

find /path/to/usbdrive/pi_image_bkup.*.img.gz -type f -mtime +21 exec rm {} \;

##################################
# consider zeroing unused space before imaging.
#
# remove # in front of line below enable this function
#
# this step it will reduce the lifespan of the SD card
##################################

# dd if=/dev/zero of=/dev/mmcblk0/disk_zero_fill.tmp bs=8M; rm -f /dev/mmcblk0/disk_zero_fill.tmp

##################################
# image server to
##################################

dd bs=8M if=/dev/mmcblk0 conv=sync,noerror | "gzip > /path/to/usbdrive/pi_image_bkup.$tdy.img.gz

I automated the script to backup once a week by adding a Cron Job that runs on Sundays at 2AM.

0 2 * * 0 /path/to/script/bakup_sdcard.sh > /dev/null 2>&1

Now if the SD card goes bad; I can ungzip the latest image on the HDD and burn it to a new SD card and not have to rebuild the Plex server. I have also backed up all my media to a second external drive (just in case).

Bonus: My clean-up script that I run once a week.

echo "Cleaning Up" &&
sudo apt-get update &&
sudo apt-get -y upgrade &&
sudo apt-get -f install &&
sudo apt-get autoremove &&
sudo apt-get -y autoclean &&
sudo apt-get -y clean &&
sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz$' -delete

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.