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 new location
##################################

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

Raspberry Pi Zero W Cloud Printer

I have always wished I could print things from anywhere. Last week my wish came true. I received an email from buyapi.ca that Raspberry Pi Zero W’s were back in stock. This little $14 computer was going to be the heart of my remote printing solution.

Here are the steps I followed to set up a Google Cloud Printer using a Raspberry Pi Zero W.

My Setup:

  • Raspberry Pi Zero W
  • 32GB Class 10 SD card
  • Raspbian Jessie with PIXEL (full install)
  • SSH and VNC turned on in Pi Settings
    • raspberry icon top left > preferences > raspberry pi configuration
  • Assigned IP address to Pi in router
  • Connected to home network via WiFi
  • Change default pi password in Pi settings (it will be online so it is a good idea to change this)
    • raspberry icon top left > preferences > raspberry pi configuration

Steps:

  • Update the Pi
sudo apt-get update
sudo apt-get upgrade
  • Install printer software
sudo apt-get install cups cups-client "foomatic-db"
  • Add user ‘pi’ to printer users
sudo usermod -a -G lpadmin pi
  • Configure to print remotely
sudo nano /etc/cups/cupsd.conf
  • Change config to the following
# Only listen for connections from the local machine
# Listen localhost:631
Port 631
< Location / >
# Restrict access to the server...
Order allow,deny
Allow @local
< /Location >
< Location /admin >
# Restrict access to the admin pages...
Order allow,deny
Allow @local
< /Location >
< Location /admin/conf >
AuthType Default
Require user @SYSTEM
# Restrict access to the configuration files...
Order allow,deny
Allow @local
< /Location >

Reboot the Pi.

  • Add printer to the system.
    • Use the Chromium browser to set up the printer
    • Go to 192.168.x.x:631
      • click Administration
      • click Add Printer (ignore warning)
      • log in using your pi username and password
      • Look for your printer under ‘Local Printers’
      • Select the printer driver and test to see if it prints
        • Remember that printing is one of the most challenging parts of Linux. I had the best luck with the Foomatic drivers.
      • Add a location and add check box to sharing.
  • Go to Chromium setting and scroll to the bottom and check ‘show advanced settings’
    • click ‘Manage’ under Google Cloud Print
    • login to your Google Account
    • click ‘add classic printer’
    • select your printer
    • once added, click the share button and share to other Google Accounts
    • everyone you shared with will now have this cloud printer to print from.

It took me a little while to tweak things to get my printer to work. After a bit of Googleing it now works like a charm and I can print to my home printer from anywhere.

Good luck and a special thanks to Jason Fitzpatrick who’s blog post helped me fix my printer woes.

Making with a Raspberry Pi

Pi as a Time Machine via TechRadar
Pi as a Time Machine via TechRadar

I have always had a fondness for the Raspberry Pi microcomputer for maker type projects. For example, two years ago I made an Apple Time Machine to wirelessly backup two Macbooks in our home using the original Raspberry Pi and a 1TB hard drive. I wrote a “how-to” blog post about it on a website that has been retired. Since then, there have been 2 major revisions to the Raspberry Pi and a Raspian upgrade (the Raspberry Pi version of Linux). After a quick search I found that there were some really well written instructions out there, so there was no need to create a new “how-to”. Personally I like the one from TechRadar.

The Time Machine backup device is in a closet in the basement and is only accessible via my home network. In order to keep the software patched and up-to-date, I use SSH (secure shell) to log into the Raspberry Pi. On a Mac you can use the terminal to access the Pi but I also use a Chromebook. To access the Pi via the Chromebook I use Secure Shell from the Chrome Web Store. I also use it to access the server for this site and run this “Update and Clean” script:

echo "Update and Clean" &&
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

However, since the Pi is sitting in the closet without a monitor or keyboard, I have no way to use it for its intended purpose, to learn about coding. I found that I could install VNC (Virtual Network Computing) onto the Raspberry Pi and use the desktop interface remotely. I followed the instructions from Adafruit about how to install VNC on the Pi and how to make it autostart after a reboot. I can now use a VNC client to access the desktop of the Pi. There is even a Chromebook VNC client so I can use the Pi from my Chromebook.

Pi Desktop via adafruit
Pi Desktop via adafruit

Because we never stop learning, today I learned that there is already a VNC client in my Macbook. I followed these instructions, here and here, to create a “share screen” button that now appears in the Finder of my Macbook and it allows me to remotely access the desktop of my Pi.

Now my Pi is serving a dual purpose. I am using it back up my Macbook and I am also remotely accessing it to learn about Linux and explore the coding apps found on the Raspberry Pi.

One more thing, Adafruit is one of my favourite “go-to” sites for everything Raspberry Pi and Limor “Ladyada” Fried at Adafruit is a fascinating role model for coding and building.