The recent Bank Holiday weekend in England provided me with a perfect opportunity to get on with some D.I.Y.
We have a collection of movie files, which I’ve stored on an external USB hard-drive. At the moment, these files are only accessible from the smart TV it’s plugged into.
I want to be able to stream these movies to the various Connected Devices we have around the house.
Time, once again, to call on my trusty Raspberry Pi 2 b-spec, running on Raspbian Jessie.
What I’m going to do is :
- Mount my USB Drive on the Pi
- Install Plex Server on the Pi to facilitate streaming
- Install Plex Client on relevant Connected Devices
- Create a Library containing all of my movies
- Stream a movie whilst I wait for it to stop raining
Hopefully after all that, I’ll be looking at something like this :
Before we do any of that however, we need to get the USB drive to work on the Pi…
The hard drive is powered through the USB port it’s connected to.
Unfortunately, the Pi does not provide sufficient power on it’s own.
Therefore, we need to use a powered USB hub to connect the two.
So, we plug the USB hub into the mains and then connect it to one of the USB ports on the Pi.
Then we plug the hard-drive into the hub :
Now that’s done, we can get on with making the files on the hard-drive available to the Pi.
A word on Software versions
The first thing to note is that I’m connected as pi for all of the steps that follow.
It would also be helpful to know the version of Raspbian that’s running on the Pi.
One way of determining this is to run the following in a terminal :
cat /etc/os-release |grep 'PRETTY_NAME'
…which, in my case, returns :
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
If you are using a different version of Raspbian (e.g. Wheezy), you may need to amend some of the commands that follow to use the appropriate repository for your version.
Finally, before we go making any software changes, it’s probably a good idea to make sure that we’re all up-to-date on the Pi :
sudo apt-get update sudo apt-get upgrade
Mounting the USB Drive on the Pi
In order to properly interact with the files on the external disk, we need to mount it.
First of all, we need to create a directory on which to mount the drive.
So, in the terminal…
cd /mnt sudo mkdir usbstorage sudo chown -R pi:pi /mnt/usbstorage sudo chmod -R 775 /mnt/usbstorage
We should now have a directory that looks like this :
ls -l total 4 drwxrwxr-x 2 pi pi 4096 Apr 1 13:52 usbstorage
Next, we need to know what type of filesystem the external disk is using.
To find this out we can run…
Alternatively, if you only have a single USB device connected to your Pi, you can filter out some of the noise…
sudo blkid |grep /dev/sda1
In my case, I get back :
/dev/sda1: LABEL="Seagate Backup Plus Drive" UUID="EC26E71826E6E316" TYPE="ntfs" PARTUUID="945986dc-01"
The “TYPE=” part of the output identifies the file system type you will need to specify when mounting the drive.
The “/dev/sda1:” part of the output confirms that our disk is currently mounted as this device.
Note that you may need to install an additional package to be able to mount ntfs disks ( although I already had this on my Pi). To make sure, you can simply run :
sudo apt-get update sudo apt-get install ntfs-3g -y
To test mounting the disk on the mount point we’ve just created…
sudo umount /dev/sda1 sudo mount /dev/sda1 /mnt/usbstorage
We should now be able to see the files on the disk…
In order to make sure that the disk is mounted in this way every time the Pi starts, we need to add an entry to the /etc/fstab file.
One way to specify the device to mount is to use the UUID, which you can find by running :
sudo ls -l /dev/disk/by-uuid/
…and looking for your device name (in my case /sda1) :
lrwxrwxrwx 1 root root 15 Apr 1 13:49 0A23-A597 -> ../../mmcblk0p5 lrwxrwxrwx 1 root root 15 Apr 1 13:49 5a632192-64d9-41fd-afe4-55a4d570cd8c -> ../../mmcblk0p3 lrwxrwxrwx 1 root root 15 Apr 1 13:49 accadb67-46be-46e3-9573-62f80f0cb652 -> ../../mmcblk0p6 lrwxrwxrwx 1 root root 15 Apr 1 13:49 BB43-8E16 -> ../../mmcblk0p1 lrwxrwxrwx 1 root root 10 Apr 1 14:14 EC26E71826E6E316 -> ../../sda1
The UUID is the hexadecimal number at the start of the listing ( in this case EC26E71826E6E316).
Now we edit the fstab…
sudo nano /etc/fstab
…by adding the line…
UUID=EC26E71826E6E316 /mnt/usbstorage ntfs nofail,uid=pi,gid=pi 0 0
To make sure that you’ve entered everything correctly you can run :
sudo mount -a
If you get any errors from this command then you will need to check your fstab changes.
Otherwise, you can go ahead and re-boot by running the following ( NOTE – I’m doing this via an ssh session on another computer) :
When the Pi comes back up, you should still be able to see the files on the disk in the /mnt/usbstorage directory.
Installing the Plex Server
First of all, we need to enable secure installations via https :
sudo apt-get install apt-transport-https -y
Now we need to get the key for the Plex download site…
wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key | sudo apt-key add -
…and add the repository to the sources list on the Pi…
echo "deb https://dev2day.de/pms/ jessie main" | sudo tee /etc/apt/sources.list.d/pms.list
…which should output…
deb https://dev2day.de/pms/ jessie main
Now make sure that the plex server is included in sources…
sudo apt-get update
NOTE – this should produce some output similar to …
Get:1 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB] Hit http://archive.raspberrypi.org jessie InRelease Get:2 https://dev2day.de jessie InRelease [1,803 B] ***edited for brevity*** Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en Fetched 9,683 kB in 32s (297 kB/s) Reading package lists... Done
…and install it…
sudo apt-get install -t jessie plexmediaserver -y
…which produces output something like…
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: plexmediaserver-installer The following NEW packages will be installed: plexmediaserver plexmediaserver-installer 0 upgraded, 2 newly installed, 0 to remove and 16 not upgraded. Need to get 8,468 B of archives. After this operation, 0 B of additional disk space will be used. Get:1 https://dev2day.de/pms/ jessie/main plexmediaserver-installer armhf 184.108.40.20685-1046ba85f-1 [7,520 B] Get:2 https://dev2day.de/pms/ jessie/main plexmediaserver all 0.9.16.4.1911-ee6e505-2~jessie [948 B] Fetched 8,468 B in 1s (7,776 B/s) Selecting previously unselected package plexmediaserver-installer. (Reading database ... 132214 files and directories currently installed.) Preparing to unpack .../plexmediaserver-installer_220.127.116.1185-1046ba85f-1_armhf.deb ... Unpacking plexmediaserver-installer (18.104.22.16885-1046ba85f-1) ... Selecting previously unselected package plexmediaserver. Preparing to unpack .../plexmediaserver_0.9.16.4.1911-ee6e505-2~jessie_all.deb ... Unpacking plexmediaserver (0.9.16.4.1911-ee6e505-2~jessie) ... Processing triggers for systemd (215-17+deb8u7) ... Setting up plexmediaserver-installer (22.214.171.12485-1046ba85f-1) ... Downloading readynas package ... ######################################################################## 100.0% Passed checksum test. Extracting readynas.deb ... rm: cannot remove ‘/etc/systemd/system/plexmediaserver.service.d/override.conf’: No such file or directory Synchronizing state for plexmediaserver.service with sysvinit using update-rc.d... Executing /usr/sbin/update-rc.d plexmediaserver defaults Executing /usr/sbin/update-rc.d plexmediaserver disable insserv: warning: current start runlevel(s) (empty) of script `plexmediaserver' overrides LSB defaults (2 3 4 5). insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `plexmediaserver' overrides LSB defaults (0 1 6). Synchronizing state for plexmediaserver.service with sysvinit using update-rc.d... Executing /usr/sbin/update-rc.d plexmediaserver defaults insserv: warning: current start runlevel(s) (empty) of script `plexmediaserver' overrides LSB defaults (2 3 4 5). insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `plexmediaserver' overrides LSB defaults (0 1 6). Executing /usr/sbin/update-rc.d plexmediaserver enable Synchronizing state for plexmediaserver.service with sysvinit using update-rc.d... Executing /usr/sbin/update-rc.d plexmediaserver defaults Executing /usr/sbin/update-rc.d plexmediaserver enable Setting up plexmediaserver (0.9.16.4.1911-ee6e505-2~jessie) ...
Now to re-start the pi…
Configuring the Plex server
All of this can be done via the Plex web interface.
To confirm the web address for our newly installed Plex Server…
In my case I get :
Therefore, I’ll need to use the following URL to access the Plex Web Interface via Epiphany :
Note – alternatively, you can access the web interface via another computer if your pi is accessible from the network.
If the network name is raspberrypi.local, you can use :
When you first land on the page you will be asked to sign in :
At this point you can either use an existing account, or create a new one specifically for Plex.
Note that if you’re using a Google account that you have not previously used from the Pi then Plex may “hang” silently until you verify that this is a legitimate connection ( i.e. Google drop a mail to your backup mail address for you to logon and verify the connection).
The reason you need an account is eloquently explained in the next screen – i.e. to get all of that lovely metadata to make your library look pretty …
Click the Got it button and Plex will then look for your Plex server…
I don’t want to access my media from outside of my home network, so I’ve left the box unchecked and hit Next
Yes, we do want to Add Library…
…for Movies, so click the Movies icon and then Next…
…and Browse for Media Folder…
…where we point it at the disk we mounted earlier and click Add…
…before finally, clicking Done.
Plex will now go through the files at the location you’ve specified and try to match up with the appropriate metadata. It seems to do this rather well, but it doesn’t always get it right.
We’ll come back to that shortly.
One final configuration step is to set the transcoder directory to be on the external disk, where there’s more space available than on the memory card in the Pi :
Now we need to install the Plex client on our connected devices…
Installing the Plex Client
Of necessity, this section is somewhat generic. I have two devices that I want to stream to. The first is a Samsung Smart TV running Tizen.
The second is an Amazon Fire TV stick plugged into an elderly – and definitely not very smart – Toshiba.
In each case, you need to go to the relevant App Store and download the Plex client onto the device.
When you first open Plex on your TV/Stick, you’ll be instructed to use a separate device to visit :
…and enter the displayed 4-digit code.
…and you will then be able to see the name of your Plex server on your device.
When Plex gets perplexed
If Plex has managed to mismatch meta data with a given film, you can persuade it to change it’s mind.
For example, the actual version of A Christmas Carol that’s on the disk is the 2009 animated version. However, Plex has matched to a different version.
To fix this, we can select Fix Match… from the menu
…and wait for Plex to present us with a list of alternatives….
…before we select the correct one…
There are, of course, several ways to do this but this method should work as a first attempt for most mismatches.
Addictive Tips have a rather good guide installing Plex on a Pi, in case you get stuck following this one ( or just prefer theirs).
There’s also a useful article on the Plex site about how to name your media files.
As for me, well it seems simply ages since I’ve sung along to Frozen…