Saturday, October 20, 2018

Plex Media Server Installation and Set Up with External (USB) Hard Drives

Plex Media Server Installation and Set Up with External (USB) Hard Drives on Linux

This is on a Fedora 22 and higher Linux OS and also works on Ubuntu 16.04LTS and higher.

Plex is awesome for organizing and categorizing all of your media, then making it available for any devices in the home or on the go.

But if you have a lot of media, then you most likely have it stored on external hard drives.  Under Linux, setting up Plex is easy, until you have got to try and read from an external hard drive that wasn't set up correctly.

I run two Plex Media Servers, from two different locations. At each location, I have identical external hard drives to store my media, and use Syncthing (post coming soon) set up to make sure everything stays synced between servers.  One server is in the US, the other in Australia, so WAN syncing isn't fast, but it isn't slow.  This also adds a layer of redundancy if a disk fails at one end.  And lastly, for reasons of I like to make things difficult, the Linux OS that each Plex Media Server runs on is different.  One runs on Ubuntu and the other on Fedora.

There are two installation methods for Plex.  I prefer the second method, but will cover both.

Install method 1 - Local RPM
First, download Plex Media Server from Plex Linux Downloads, then install it with

$ sudo dnf -y install ./plexmediaserver-1.13.8.5395-10d48da0d.x86_64.rpm

And done, Plex is now installed.  In order to update, you will need to download the Plex Linux Downloads site, download the new .rpm and do install/update from there.

Install method 2 - Install from repo

Create plex.repo in /etc/yum.repos.d/ that looks like the following:

$ sudo vi /etc/yum.repos.d/plex.repo

[PlexRepo]
name=PlexRepo
baseurl=https://downloads.plex.tv/repo/rpm/$basearch/
enabled=1
gpgkey=https://downloads.plex.tv/plex-keys/PlexSign.key
gpgcheck=1

Then $ sudo dnf -y install plexmediaserver

Plex is now installed.  Under this method, running a $sudo dnf update command to update your system, Plex will be updated if a new version is available.

The benefits to installing from the repo over the downloaded .rpm file are that you can update the installation through dnf, rather than having to download the latest version through a browser each time you want to update your Plex media server.



Once the install completes, change/set up the Plex Media Server user and group to the local user

$ vim /usr/lib/systemd/system/plexmediaserver.service

Change the User=plex to User=<username>
Change the Group=plex to Group=<usergroup>

Change the owner and group of the library and user space as well with

$ sudo chown -R <username>:<usergroup> /usr/lib/plexmediaserver
$ sudo chown -R <username>:<usergroup> /var/lib/plexmediaserver

Where <username> is the local username you want to use.

Note:  To let Plex media server run as designed (run the service as the plex user) and to be able to access media on USB drives owned by the local user, and to not have to do too much work on changing the mount points of those remote drive, a quick and dirty method for getting this all working would be to change the permissions on the directory where the USB drive mount to 755.

For example, my USB drives mount to /run/media/<username>/.  The permissions on /run/media/<username> are 750 after the first drive mounts.  This directory is not-persistent across reboot, so every time the Plex media server is restarted, I would have to change permissions on this directory to 755.  If you don't reboot often, this is the fastest way to go, but I prefer a more robust solution, so I change the user and group that Plex runs under to the local user.

Start the plexmediaserver.service service,

$ sudo systemctl start plexmediaserver.service

and enable the service to run at startup

$ sudo systemctl enable plexmediaserver.service

Now, navigate a browser to 127.0.0.1:32400/web/index.html and the Plex Media Server interface should show up.

For my installations, I prefer to have Plex to run as my user <username> instead of under the default plex:plex user.  The reason is because my external hard drives holding all of my media are LUKS encrypted, and formatted with ext4 partitions.  This means that all of the media and directories have permissions attached.  If the media has the user:group as username:username and plex tries to access the drives as plex:plex, you won't see anything come up since the plex user doesn't have access to any of the username:username files and directories.

You can add the plex user to the username group, or you can just change the default user that Plex Media Server runs as to the local user, username.

I choose the latter, as the configuration is easier, since all of my media and drives are already owned by username:username.



Sources for this article came from:
https://support.plex.tv/articles/200273978-linux-user-and-storage-configuration/
https://forums.plex.tv/t/plex-refused-to-run-as-a-different-user-fedora-18/35208/2
https://forums.plex.tv/t/using-ext-or-ntfs-drives-internal-or-external-on-linux/198544
https://support.plex.tv/articles/200288596-linux-permissions-guide/


No comments:

Post a Comment