Linux Tips

Tips & Tricks of the Linux trade.

Below, you’ll find a collection of tips, tricks, and how-to’s to help make setting up, administrating, and using Plex Media Server on Linux a little easier.

25 Likes

Using other hard drives (Windows or Linux) with PMS

This How-To is written to help with Internal and External drives. It also is written to demonstrate how to cope with NTFS and EXT4 formatted drives. By logical extension, any format supported by Linux can be handled using the technique shown here. In all cases, the goal is to give user plex permission to read your media files which Linux doesn’t allow by default due to its strict security model.

We will walk through the steps needed to add these external USB hard drives and internal hard drives, either formatted as NTFS or ext4, to your Linux configuration so Plex Media Server can access it.

Three disks will be added.

  • An external ext4-formatted disk.
  • An external NTFS-formatted disk.
  • An internal hard drive which, in this example, happens to be NTFS formatted. It may also be HPFS formatted as Linux supports this natively.

Any disk formats which Linux supports, regardless of whether internal or external, can be added as shown below.

For reference purposes, this document was created using Fedora 24 Linux with the Gnome desktop and the Nautilus graphical file manager. Linux shell (command line) commands are bold face text.

A. Identify the disk(s) you want to add in the graphical disk manager

We get the device names, which we only need temporarily, using the command df

[chuck@lizum ~]$ df
Filesystem  1K-blocks      Used  Available Use% Mounted on
/dev/sda5   128884388  19057076  103257328  16% /
/dev/sda2      487652    146960     310996  33% /boot
/dev/sda7   970737276 159145788  762923072  18% /home
/dev/sda1   831543292 149144996  682398296  18% /run/media/chuck/8E7025AD70259D49
/dev/sdb1  1922728752  11372564 1911339804   1% /run/media/chuck/Media-3
/dev/sdc1  1953480700  91720372 1461760328  26% /run/media/chuck/Chuck 2T

We have identified internal disk partition /dev/sda1 and external USB disks “Chuck 2T” and “Media-3” as the disks we want made available to Plex .
Now we use this information to obtain the rest of the information we need.

The following steps must be performed as the Super-User (root).

[chuck@lizum ~]$ sudo sh
Passwd:
[root@lizum chuck]# 

B. Get the ‘Block Id’ or device name (/dev/sdxx) of the disk partition(s) we are interested in

Get the label UUIDs for the USB drives (format does not matter) because their device names can change. This ensures they always mount at the same location. This step also provides us with the partition’s format.
We will need this.

[root@lizum chuck]# blkid /dev/sda1
/dev/sda1: UUID="8E7025AD70259D49" TYPE="ntfs" PARTUUID="000ac519-01"

[root@lizum chuck]# blkid /dev/sdb1
/dev/sdb1: LABEL="Media-3" UUID="50f1a141-bc8a-48ba-9b29-8a7bee8043e9" TYPE="ext4" PARTUUID="d456a9a6-9727-4143-be3e-f946400ec3ba"

[root@lizum chuck]# blkid /dev/sdc1
/dev/sdc1: LABEL="Chuck 2T" UUID="56EA5848EA582691" TYPE="ntfs" PARTUUID="542c75ae-01"

We now have both the UUID and partition formatting. Both pieces are needed below.

C. Create the locations where we will graft everything into Linux

The directory `/disks’ has been chosen because Gnome “Nautilus” and Ubuntu (in general) claim exclusive access to anything found in /media. This prevents conflicts with those desktop components.

In this example, the username ‘chuck’ should be replaced with your actual Linux username . This allows you to maintain full ownership and control of the media without needing to use the superuser (root) account each time.

# The location 
[root@lizum chuck]# mkdir /disks /disks/c /disks/media3 /disks/chuck2t
[root@lizum chuck]# chown -R chuck:chuck /disks

[root@lizum chuck]# ls -la /disks
drwxr-xr-x   3 chuck chuck 4096 Jul 27 11:14 .
dr-xr-xr-x. 30  root  root 4096 Jul 27 11:14 ..
drwxrwxrwx   4 chuck chuck 4096 Jul 27 11:04 c
drwxrwxrwx   4 chuck chuck 4096 Jul 27 11:04 chuck2t
drwxrwxrwx   4 chuck chuck 4096 Jul 27 11:04 media3
[root@lizum chuck]#

Having created the directories as root, verify empty (unmounted) directory permissions are 0755 before mounting

D. Create the entry in the file system table where to mount the disk each time the system boots

Edit the file system table Linux uses to mount all drives using your favorite text editor. Text editors commonly found are: vi, gedit, nano, and xed.

Gedit is a graphical-based editor (WYSIWYG) and may be easier as it’s more like Microsoft editors.

For the USB drives:

Create lines for your system like the lines below, pasting UUID= value and TYPE (ntfs or ext4) from above, plus the directory locations just created where the external drives will always be found.

Best practice for USB drives is to use the UUID= method. USB drives will change physical device name from use to use. UUID= guarantees they always are mounted in the same location.

Use caution editing /etc/fstab. Mistakes can force you to take manual recovery/editing steps in command line mode ONLY** comment out the erred line(s) during recovery**

[root@lizum chuck]# vi /etc/fstab  (or use whatever text editor is available / favorite  and add the following lines, using your information)

# Addtions for external and internal drives
# Mount Media-3 (ext4)  at /disks/media3 for Plex
UUID=50f1a141-bc8a-48ba-9b29-8a7bee8043e9 /disks/media3  ext4  defaults,auto,rw,nofail 0 1

# Mount Chuck-2T (NTFS) at /disks/chuck2t for Plex
UUID=56EA5848EA582691                     /disks/chuck2t ntfs  defaults,auto,rw,nofail 0 1

# Mount /dev/sda1 directly  READ-ONLY,  and use the device name because it will never change
/dev/sda1                                 /disks/c       ntfs  defaults,auto,ro,nofail 0 1

Save and test. (Both Redhat & Debian shown here)

# See where the disks are currently mounted and unmount
# (This is from Redhat)
df
umount /run/media/chuck/Media-3
umount /run/media/chuck/Chuck2T

# (This is from Ubuntu/Debian)
df
umount /media/chuck/Media-3
umount /media/chuck/Chuck2T


# mount each one individually to verify no errors
[root@lizum chuck]# mount /disks/media3
[root@lizum chuck]# mount /disks/chuck2t
[root@lizum chuck]# mount /disks/c
[root@lizum chuck]# ls  /disks/*         # this will produce a lot of output if correct.  Be prepared

E. Restart the computer and verify all is as expected**

[chuck@lizum ~]$ ls /disks/*    # The output here should be the same as the previous test above


[chuck@lizum ~]$ df 
Filesystem  1K-blocks      Used  Available Use% Mounted on
/dev/sda5   128884388  19057076  103257328  16% /
/dev/sda2      487652    146960     310996  33% /boot
/dev/sda7   970737276 159145788  762923072  18% /home
/dev/sda1   831543292 149144996  682398296  18% /disks/c
/dev/sdb1  1922728752  11372564 1911339804   1% /disks/media3
/dev/sdc1  1953480700 491720372 1461760328  26% /disks/chuck2t

[chuck@lizum ~]$

F. Correct (set) Linux file permissions (ext4 drives only)

Drives are now mounted. Verify PMS can read them.
NTFS drives do not require permissions to be set for Linux because they use a different mechanism.
We will only address the ext4 formatted drive.

[chuck@lizum ~]$ su
Password:

# change the default permissions to owner='rwx', everyone else to 'r-x' 
#  'x' means to traverse the directory to subdirectories & files
[root@lizum chuck]# find /disks/media3 -type d -exec chmod 755 {} \;

# change the default permissions to owner= 'rw-',  everyone else 'r-only'
[root@lizum chuck]# find /disks/media3 -type f -exec chmod 644 {} \;

G. Open Plex and add the external disk to your library

With the drives now mounted and permissions set, open PMS and add the media directories (folders) to the appropriate sections.

H. Update your Library

Manually invoke a Library update if you configuration isn’t configured to do so.

Back to top

10 Likes

Customizing your Plex configuration on systemd based systems

This information is intended for those systems where cat /proc/1/comm returns systemd.

On systems which use Systemd (Ubuntu 16+, Fedora 26+, Centos 7+, Debian 8+,) you create this customization file which SystemD reads prior to launching PMS. This file is independent of the default configuration and service control mechanisms in /lib/systemd/system/plexmediaserver.service. Your customization override is preserved across updates, uninstall, re-install operations.

If your system returns init, please edit the values in /etc/defaults/plexmediaserver

While you may change /lib/systemd/system/plexmediaserver.service, it is under the control of the package manager and subject to replacement without warning at any time during an update. To provide stability, systemd allows creation of an override.conf file to customize and create enduring local adjustments to a distributed default package.

You can change a number of parameters about how PMS runs on your Linux system including where the metadata (Library) resides.

The most common, and safest, parameters you can change are:

  1. Environment variables.
  2. Username PMS uses at runtime
  3. Group name PMS uses at runtime

All Environment variable specifications are of the forms:

Environment="VARIABLE_NAME=literal string here. spaces are allowed"
or
Parameter=value

Examples:

Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plexdir/Application Support"
User=chuck

WARNING: /media is a reserved directory name on Gnome-based systems. Do not put your PMS library there

The Plex-supplied service definition should not be modified as any changes are subject to overwriting at every update. For changes to persist, those changes must be maintained in /etc/systemd/system/plexmediaserver.d/override.conf

The task, with PMS stopped, is:

  1. Create the ‘override’ file in directory /etc/systemd/system/plexmediaserver.service.d
  2. Move any files if needed
  3. Change ownership if needed
  4. Inform systemd of the changes
  5. Start PMS

In the example below, the following will be shown. Tailor to your environment as needed

a) Run as user chuck:chuck
b) Move the metadata (Library) to /home/plexdir for the extra space
c) Relax the default file-creation permissions (for plug-ins, etc)

The following steps must be done as root, elevate first and get a full shell to work in

sudo sh

Begin here:

A. Create directory /etc/systemd/system/plexmediaserver.service.d.

In this directory, create override.conf configuration customization entries similar to the following example

#
# Customize Plex's config
#
# Identify this as a service override
[Service]
#
#  Move the data directory
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plexdir/Library/Application Support"
#
#  These values are only needed if you wish to change user & group
User=chuck
Group=chuck
#
# This is needed to change the default umask     
UMask=002    # this must be octal    - See warning below 

Warning:
Some distros used UMask while others use Umask
Some distros want 4 octal digits for, not the standard 3. (Go figure…).

Please be cautious of this on your system.

B. Inform SystemD of the changes and test the related & reconfigured PMS

systemctl daemon-reload
systemctl start plexmediaserver

C. Test your system. Verify everything is exactly as it was. If not, resolve before proceeding

http://127.0.0.1:32400/web

Administration note:

Once you have created the override file, you can later edit it with systemctl edit plexmediaserver

E. Shortcut version

If you have only a few customizations to make, you may opt to let systemctl make the files for you

  1. sudo systemctl stop plexmediaserver
  2. sudo systemctl edit plexmediaserver
  3. Enter the same override information as shown above
  4. Save and exit the editor
  5. sudo systemctl daemon-reload
  6. Perform any required ownership changes or other permission work required
  7. sudo systemctl start plexmediaserver

Back to top

2 Likes

Mounting CIFS + SMB network shares for Plex use

The basic checklist

  • Prepare the NAS
  • Create the CIFS/SMB credentials file for use in /etc/fstab
  • Create a ‘mount point’ directory structure on your Linux machine which will be where all your media shares are grafted and made available for Plex use.
  • Create an entry in /etc/fstab for each share you wish to mount.
  • Mount and debug as needed

A. Prepare the NAS.

This is unique to each NAS. In general, you only need grant read permission. Should you desire Read/Write for yourself, we will allow for it

On Linux, Plex uses username plex. The username plex is the most desirable username to use for your NAS as well.

  1. Add username plex to the NAS. If it requires a password, assign it one and you can use it later if/when needed.
  2. Edit the share permissions for your NAS to either export
    2a. “Read-only” to your LAN (all hosts) for all usernames -or-
    2b. “Read-write” for your username, and Read-only for plex

B. Create the credentials file to pass to the CIFS / SMB server during mount

Create a file to hold the username and password to use. In this example, /etc/plex.cred is used
Using any text editor, create /etc/plex.cred with the following content

username=plex
password=password
domain=CIFS/SMB domain    (this is only required if the CIFS/SMB server requires it)

C. Create the Mount Point directory structure

It usually makes the most sense to create a structure which mirrors your NAS’s shares

An example structure might be:

/nas
/nas/movies
/nas/movies2
/nas/children
/nas/tv
/nas/cartoons
/nas/photos
/nas/music

To create this, we simply supply the Linux commands to create the structure and supply the basic permissions to those directories:

sudo sh
mkdir /nas  /nas/movies /nas/movies2 /nas/children /nas/tv /nas/cartoons /nas/photos /nas/music
chmod -R 755 /nas
exit

D. Create the entries to mount the NAS shares at their target locations.

Each nas vendor has a different pathname conventions. Please follow the documentation for your NAS.
In this example, Synology’s and QNAP’s conventions will be shown.
The photos library will be mounted Read-only to prevent accidental deletion by anyone.

The example systems are a twin volume Synology DiskStation and a single volume QNAP system

You will notice the two nas units are seamlessly blended together here. In the end, Plex will complete the blending into a single library if so desired.

/etc/fstab has the following entries added to it. These will require testing and possible adjustment for your NAS and configuration. NFS is shown here first.

if you have defined the hosts syno and qnap in /etc/hosts, you may use their names here otherwise use their IP addresses.
You may always use hostname or IP address interchangeably as long as there is a definitive resolution.

//syno/volume1/movies     /nas/movies          cifs    auto,defaults,nofail,credentials=/etc/plex.cred,uid=plex 0 0
//qnap/share/movies2      /nas/movies2         cifs    auto,defaults,nofail,credentials=/etc/plex.cred,uid=plex 0 0
//syno/volume1/children   /nas/children        cifs    auto,defaults,nofail,credentials=/etc/plex.cred,uid=plex 0 0
//syno/volume2/tv         /nas/tv              cifs    auto,defaults,nofail,credentials=/etc/plex.cred,uid=plex 0 0
//qnap/share/cartoons     /nas/cartoons        cifs    auto,defaults,nofail,credentials=/etc/plex.cred,uid=plex 0 0

# Two NFS examples in to the same NAS units
# QNAP is .21  
192.168.0.21:/share/Photos       /nas/photos           nfs    auto,defaults,nofail,ro 0 0

# Syno is .23
192.168.0.23:/volume2/music      /nas/music            nfs    auto,defaults,nofail 0 0

Save the file and now we begin testing.

E. Begin verifying and testing the new mount points

sudo sh
mount -avt cifs      # each will attempt to mount and give dialog as it does.   Look for "successfully mounted"

# follow up by seeing what actually is mounted
df

# check to see if you have visibility into each share

cd /nas
ls *     # This will list all the top level output from each share and will be voluminous so be prepared

If you have made any errors, you may work at the individual mount level

sudo sh
mount /nas/movies

ls /nas/movies

# Um,  that didn't work right... Change mount in /etc/fstab
umount /nas/movies

# After editing, try it again 
mount /nas/movies 

Repeat the above until you’re happy with all

There is one final step which will often help avoid permission issues on Linux systems (should the NAS be very security conscious)
This sets the permissions of the directories after they have been mounted too, effectively tweaking the NAS permissions a bit looser (read-only)

sudo chmod 755 /nas/*

All your network (NAS) media is now available to PMS starting with the /nas folder at the top.

For additional information and available options for CIFS/SMB mounts, type man mount.cifs in a terminal window

Back to top

1 Like

Mounting NFS network shares for Plex use

The basic checklist

  • Prepare the NAS:
  • Create a ‘mount point’ directory structure on your Linux machine which will be where all your media shares are grafted and made available for Plex use.
  • Create an entry in /etc/fstab for each share you wish to mount.
  • Mount and debug as needed

A. Prepare the NAS.

This is unique to each NAS. In general, you only need grant read permission. Should you desire Read/Write for yourself, we will allow for it

On Linux, Plex uses username plex. The username plex is the most desirable username to use for your NAS as well.

  • Add username plex to the NAS. If it requires a password, assign it one and you can use it later if/when needed.
  • Edit the share permissions for your NAS to either export.
    • “Read-only” to your LAN (all hosts) for all usernames -or-
    • “Read-write” for your username, and Read-only for plex

B. Create the Mount Point directory structure

It usually makes the most sense to create a structure which mirrors your NAS’s shares

An example structure might be:

/nas
/nas/movies
/nas/movies2
/nas/children
/nas/tv
/nas/cartoons
/nas/photos
/nas/music

To create this, we simply supply the Linux commands to create the structure and supply the basic permissions to those directories:

sudo sh
mkdir /nas  /nas/movies /nas/movies2 /nas/children /nas/tv /nas/cartoons /nas/photos /nas/music
chmod -R 755 /nas
exit

C. Create the entries to mount the NAS shares at their target locations.

Each nas vendor has a different pathname conventions. Please follow the documentation for your NAS.
In this example, Synology’s and QNAP’s conventions will be shown.
The photos library will be mounted Read-only to prevent accidental deletion by anyone.

The example systems are a twin volume Synology DiskStation and a single volume QNAP system

You will notice the two nas units are seamlessly blended together here. In the end, Plex will complete the blending into a single library if so desired.

/etc/fstab has the following entries added to it. These will require testing and possible adjustment for your NAS and configuration. NFS is shown here first.

if you have defined the hosts syno and qnap in /etc/hosts, you may use their names here otherwise use their IP addresses.
You may always use hostname or IP address interchangeably as long as there is a definitive resolution.

syno:/volume1/movies     /nas/movies           nfs    auto,defaults,nofail 0 0
qnap:/share/movies2      /nas/movies2          nfs    auto,defaults,nofail 0 0
syno:/volume1/children   /nas/children         nfs    auto,defaults,nofail 0 0
syno:/volume2/tv         /nas/tv               nfs    auto,defaults,nofail 0 0
qnap:/share/cartoons     /nas/cartoons         nfs    auto,defaults,nofail 0 0

# QNAP is .21
192.168.0.21:/share/Photos       /nas/photos           nfs    auto,defaults,nofail,ro 0 0

# Syno is .23
192.168.0.23:/volume2/music      /nas/music            nfs    auto,defaults,nofail 0 0

Save the file and now we begin testing.

D. Begin verifying and testing the new mount points

sudo sh
mount -avt nfs      # each will attempt to mount and give dialog as it does.   Look for "successfully mounted"

# follow up by seeing what actually is mounted
df

# check to see if you have visibility into each share

cd /nas
ls *     # This will list all the top level output from each share and will be voluminous so be prepared

If you have made any errors, you may work at the individual mount level

sudo sh
mount /nas/movies

ls /nas/movies

# Um,  That didn't work right   ... Change mount in /etc/fstab
umount /nas/movies

# after editing, try it again 
mount /nas/movies 

Repeat the above until you’re happy with all

There is one final step which will often help avoid permission issues on Linux systems (should the NAS be very security conscious)
This sets the permissions of the directories after they have been mounted too, effectively tweaking the NAS permissions a bit looser (read-only)

sudo chmod 755 /nas/*

All your network (NAS) media is now available to PMS starting with the /nas folder at the top.

Back to top

1 Like

Moving Plex’s metadata (Library) directory on systemd based systems

This information is intended for those systems where cat /proc/1/comm returns systemd. If your system returns init, please see the next post in this thread.

While you may change /lib/systemd/system/plexmediaserver.service, it is under the control of the package manager and subject to replacement without warning at any time during an update. To provide stability, systemd allows creation of an override.conf file to customize and create enduring local adjustments to a distributed default package.

You can change a number of parameters about how PMS runs on your Linux system including where the metadata (Library) resides.

One of the more common needs is to relocate /var/lib/plexmediaserver from it’s default location to a SSD or where there is more space.

On systems which use Systemd (Ubuntu 16+, Fedora, Centos 7, Debian 8,) you create a customization file which SystemD reads prior to launching PMS. This file is independent of the default configuration and service control mechanisms in /lib/systemd/system/plexmediaserver.service. The Plex-supplied service definition should not be modified as any changes are subject to overwriting at every update.

The task, with PMS stopped, is:

  • Create the ‘override’ file
  • Move the files to their new location
  • Change ownership if needed
  • Inform systemd of the changes
  • Start PMS

In the example below, the following will be shown. Tailor to your environment as needed

a) Run as user chuck:spacecadet
b) Move the metadata (Library) to /home/plex for the extra space
c) Relax the default file-creation permissions (for plug-ins, etc)

The following steps must be done as root, elevate first and get a full shell to work in

sudo sh

Begin here:

A. Create /etc/systemd/system/plexmediaserver.service.d. In it, create override.conf containing the following

#
# Customize Plex's config
[Service]
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plexdata/Library/Application Support"
#
#  These values are only needed if you wish to change user & group
User=chuck
Group=chuck
#
# This is needed to change the default umask 
UMask=0002    # this must be 4 digits of octal       

Info: Some systems want ‘Umask’ while others want ‘UMask’. Please be cautious of this.

Warning: Do not use /media as it is a reserved directory with Gnome (Nautilus). Select a target directory not used by any system applications.

B. Now copy the existing library. (Resolve errors before deleting the original copy of your library)

mkdir  /home/plexdata

cd /var/lib/plexmediaserver
tar cf - ./Library | (cd /home/plexdata ; tar xf -)   # this will take some time
cd /home/plexdata

# now change ownership
cd /home/plexdata
chown -R chuck:chuck. 

C. Inform SystemD of the changes and test the related & reconfigured PMS

systemctl daemon-reload
systemctl start plexmediaserver

D. Test your system. Verify everything is exactly as it was. If not, resolve before proceeding

http://127.0.0.1:32400/web

E. Delete the old library in /var

rm -rf  /var/lib/plexmediaserver/Library &         # this can safely go into the background

Once you have created the override file, you can later edit it with systemctl edit plexmediaserver

Back to top

Backup, Restore, or Clone your PMS installation

Backing up your PMS data involves the same steps you’ll need if you were to clone your PMS and take to a new computer, reinstall the operating system, or just want a backup for safe keeping.

Making the Backup (General Steps)

  • Stop PMS
  • Invoke the root shell
  • Create the backup image
  • Copy the image to the new system, perform your OS reinstallation, or whatever task you need

Restoring a backup image (General Steps)

  • (Re)install PMS itself if on a new machine
  • Start and Stop PMS one time (no interaction with it is required)
  • Restore the backup image
  • Start PMS

Make the backup image:

On the source (original) system:

[chuck@lizum ~.74]$ sudo sh
sh-4.4# cd /var/lib/plexmediaserver
sh-4.4# tar cfz /nas/tmp/PlexBackup.tar.gz ./Library
sh-4.4# ls -la /nas/tmp/PlexBackup.tar.gz 
-rw-r--r--. 1 root root 864050144 Oct 29 15:29 /nas/tmp/PlexBackup.tar.gz
sh-4.4# 

Restoring a backup image:

sh-4.4# sudo sh
sh-4.4# systemctl start plexmediaserver
sh-4.4# systemctl stop plexmediaserver
sh-4.4# cd /var/lib/plexmediaserver
sh-4.4# rm -rf Library
sh-4.4# tar xf /nas/tmp/PlexBackup.tar.gz
sh-4.4# chown -R plex:plex ./Library
sh-4.4# systemctl start plexmediaserver

Cloning from one to another:

  • Make a backup image
  • Transport it to the new system
  • Restore the image
  • Remember to decommission (delete) the old Preferences.xml file else you’ll have two servers with the same name and ID.

Back to top

3 Likes

Manual database optimization using the command line

If you can’t get to the UI because it times out (your database is really fragmented). This will allow you to invoke database optimization without the UI by sending the command directly to PMS.

Manual CLI/curl Database Optimization with PMS running

#!/bin/sh

# Get the contents of the Preferences file, keep only what we need,  push to a temp, then use it in the curl command

# you may remove the sudo if not needed to read your Preferences.xml

cat "/PATH/TO/Library/Application Support/Plex Media Server/Preferences.xml" |  \
sed -e 's;^.* PlexOnlineToken=";;' | sed -e 's;".*$;;' | tail -1 > /tmp/plex.tmp

curl --request PUT http://127.0.0.1:32400/library/optimize\?async=1\&X-Plex-Token=`cat /tmp/plex.tmp`

rm -f /tmp/plex.tmp
1 Like

Increase the number of directories Linux can monitor (inotify) for PMS

The default size of the Linux inotify table is 8192 directories (*1). When PMS is configured to update automatically when media is added, with properly organized media, especially music, this table rapidly fills and exceeds the default allocation requiring you to increase it.

The solution to this is straight forward. Increasing the table size is easy. The first step is to determine how many directories to allocate,

A. Determine how many directories are currently in use:

sudo find /dir1 /dir2 /dir3 -type d -print | wc -l (use your actual directory names and not dir1, dir2, or dir3. You may add as many top level directories as you need)

B. Determine how many directories to actually allocate

Round up to the next multiple of 32768 (32K). This is done to maximize memory page alignment and keep the maximum amount of memory available for hardware transcoding (if used). This number is called NEW_MAX_DIRECTORIES in the example below.

C. Calculate and verify memory utlization

Multiply the number of entries from above by 512 (worst case size of an inode entry). This tells you how much kernel memory will be permanently allocated and not available to other applications such as PMS. If this results in more memory allocated than you are comfortable allocating, a decision must be made to a) Add more memory to the system or b) reduce the number of directories PMS can automatically monitor. In most cases, increasing system memory is more desirable and yields better overall performance.

D. Implement the change
With calculations complete, it is time to implement the configuration change.

Procedure:

sudo sh
echo  fs.inotify.max_user_watches=NEW_MAX_DIRECTORIES  >> /etc/sysctl.conf
sysctl -p

Example: Allocate 256K (262144) directory entries for the iNotify table


sudo sh
find /nas/movies /nas/tv /nas/music -type d -print | wc -l
201322
#
#
# Round 201322 up to 256K  (262144)
echo  fs.inotify.max_user_watches=262144  >> /etc/sysctl.conf
sysctl -p

In the above example, the table was configured for 262144 (256K) directories on a system with 8GB of main memory.

sysctl was then invoked to make the change immediate (-p).
The system can also be rebooted to make the change take effect.

Notes:

*1 - The default for older Linux systems is 8192. Effective November 2020 Linux kernel, this value is dynamic based on memory and up to 1048576 at start. Most users, with 32GB or more will see the immediate increase to 65536 without making any kernel tuning changes.

Back to top

1 Like

Automating Linux permissions using inheritance (helps with DVR/LiveTV/Curation too)

Linux has a very powerful and convenient way of automatically setting the permissions of your media files as you add more to your media directories.

Linux allows only one username and one group to own a file which is somewhat of a restriction. This can be easily leveraged to accomplish what is needed for Plex.

An excellent application of this is when you wish to record with Plex DVR, allowing it to write directly into your library, while you retain full permission / control of your media.

To accomplish this, we use what is known as the ‘setgid’ (Set Group ID) bit (flag). While this can be used for either the owner or the group, the group inheritance will be shown here. Applying the ‘setgid bit’ flag should only be done on the filesystem containing the actual data. It cannot be reliably implemented over the network or through a VM layer.

Consider the following example:

[chuck@lizum /tmp.126]$ mkdir inherit
[chuck@lizum /tmp.127]$ mkdir 'inherit/movie (year)'
[chuck@lizum /tmp.128]$ touch 'inherit/movie (year)/movie (year).mkv'
[chuck@lizum /tmp.129]$ ls -la inherit
total 0
drwxr-xr-x.  3 chuck chuck  60 Jul  4 13:51 ./
drwxrwxrwt. 21 root  root  520 Jul  4 13:51 ../
drwxr-xr-x.  2 chuck chuck  60 Jul  4 13:52 movie (year)/
[chuck@lizum /tmp.130]$

Automate granting user plex access to anything written into your media library regardless of the original permissions

A. Grant permission outright at the topmost level for everything below it

[chuck@lizum /tmp.130]$ sudo chgrp -R plex inherit

B. Enable inheritance of the group name for all items created below

[chuck@lizum /tmp.131]$ sudo chmod g+s inherit

C. Propagate the inheritance bit (flag) to all existing sub directories (future directories will inherit automatically)

[chuck@lizum /tmp.132]$ sudo find ./inherit -type d -exec chmod g+s {} \;

D. Add another movie to the library

[chuck@lizum /tmp.133]$ mkdir 'inherit/movie2 (year2)'
[chuck@lizum /tmp.134]$ touch 'inherit/movie2 (year2)/movie2 (year2).mp4'

E. Observe the resultant permissions

[chuck@lizum /tmp.135]$ ls -laR inherit
inherit:
total 0
drwxr-sr-x.  4 chuck plex  80 Jul  4 14:00 ./
drwxrwxrwt. 21 root  root 520 Jul  4 13:57 ../
drwxr-sr-x.  2 chuck plex  60 Jul  4 14:01 movie2 (year2)/
drwxr-sr-x.  2 chuck plex  60 Jul  4 13:52 movie (year)/

inherit/movie2 (year2):
total 0
drwxr-sr-x. 2 chuck plex 60 Jul  4 14:01 ./
drwxr-sr-x. 4 chuck plex 80 Jul  4 14:00 ../
-rw-r--r--. 1 chuck plex  0 Jul  4 14:01 movie2 (year2).mp4

inherit/movie (year):
total 0
drwxr-sr-x. 2 chuck plex 60 Jul  4 13:52 ./
drwxr-sr-x. 4 chuck plex 80 Jul  4 14:00 ../
-rw-r--r--. 1 chuck plex  0 Jul  4 13:52 movie (year).mkv

Extend permissions and inheritance to include multiple usernames

In the above example, group plex was used. Any existing group name may be used. Any system usernames may be added to that group

A new group named ‘media’ can be created with multiple users in it (plex being one of those users).

Continuing with the media example above, instead of group plex, create and use new group media. Add users chuck and plex to this new group.
Once added, change the permissions of the directories and files to reflect their new group assignment.

A. Create group media, adding chuck and plex to it

[chuck@lizum /tmp.136]$ sudo groupadd media
[chuck@lizum /tmp.137]$ sudo usermod -a -G media plex
[chuck@lizum /tmp.138]$ sudo usermod -a -G media chuck

B. Reassign all the files and directories to use this new group

[chuck@lizum /tmp.139]$ sudo chgrp -R media inherit

C. Verify the results

[chuck@lizum /tmp.140]$ ls -laR inherit
inherit:
total 0
drwxr-sr-x.  4 chuck media  80 Jul  4 14:00 ./
drwxrwxrwt. 21 root  root  520 Jul  4 13:57 ../
drwxr-sr-x.  2 chuck media  60 Jul  4 14:01 movie2 (year2)/
drwxr-sr-x.  2 chuck media  60 Jul  4 13:52 movie (year)/

inherit/movie2 (year2):
total 0
drwxr-sr-x. 2 chuck media 60 Jul  4 14:01 ./
drwxr-sr-x. 4 chuck media 80 Jul  4 14:00 ../
-rw-r--r--. 1 chuck media  0 Jul  4 14:01 movie2 (year2).mp4

inherit/movie (year):
total 0
drwxr-sr-x. 2 chuck media 60 Jul  4 13:52 ./
drwxr-sr-x. 4 chuck media 80 Jul  4 14:00 ../
-rw-r--r--. 1 chuck media  0 Jul  4 13:52 movie (year).mkv
[chuck@lizum /tmp.141]$

Supplemental:

In the above example RWX (755) permissions were granted solely to the owner (chuck). Should you also wish to grant RWX permission to the group to allow both your username and Plex to write, you will need two additional changes.

  1. The permissions for all directories set to 775 first
  2. Your Plex configuration needs its default Linux umask changed to be 0002 (default is 0022). To change umask, please see “Customizing your Plex configuration”.

Additional Info:

Certain automated media curation tools (e.g. the *ARR family of tools) will set specific permissions as directories and files are created.

When using these tools,

  1. Setup the base permissions however you want them
  2. Now set the appropriate matching permission(s) in the tools.
  3. From this point forward, those curation tools should be able to maintain proper permissions for the entire library
3 Likes

Header Compression in MKV files

If you encounter any issues with header compression in MKV files, this little script will tell you which files in the current directory are using it.

IFS=$'\n'
for infile in `find . -name "*.mkv"` 
do
 uses_compression=$(mkvinfo "$infile" | grep "header removal")
 if [ -n "$uses_compression" ]; then 
    echo $infile 
 fi
done`

After locating those files which use header compression, your next step is use mkvmerge or other tool to return MkV headers to normal.

Back to top

Installing Plex Media Server on Intel NUC

Since Ubuntu 18 and NUC 7 systems, installation of Plex Media Server on NUC computers has become very simple and straight forward.

Today’s NUC8 and above machines are easily capable of hardware transcoding with HEVC HDR → SDR tone mapping.

The recommended distribution is Ubunutu 20.04 LTS. Plex’s Linux package for Ubuntu has been overhauled to make installation very easy and informative. If any required software is needed it now tells you what you need to install and where you can find the recommended supplemental packages.

The process is:

  1. Install Ubuntu 20.04 LTS (or newer) on the NUC using Ubuntu defaults.
  • Recommendation is to ensure the / partition has enough space to hold your metadata (256GB is recommended minimum, 512GB preferred)
  1. Mount your media sources (NFS or SMB or external USB) as appropriate. Ensure all users (which will include plex) can minimally READ the media files. (755/644 permissions)
  2. Download PlexMediaServer directly from https://Plex.tv/downloads (AMD64)
  3. In a command line terminal window
cd ~/Downloads 
sudo dpkg -i  Plex_package_name_you_just_downloaded.deb
  1. The installer will run (pre installation validation and post installation configuration)

  2. Should there be issues with installation, /tmp/plexinstaller.log will contain the information needed to bring to the forum for assistance.

  3. Open a new browser window (Open an Incognito one if you have an existing Plex installation on another machine)

  4. Open URL http://127.0.0.1:32400/web

  5. The setup wizard will now guide you through setup of your Plex server.

For those using older Debian-based OS versions, please consider the following

Plex Media Server with Intel NUC and Ubuntu 16.04 LTS

Contributed by: @grogster

HARDWARE

  • Intel NUC (BOXNUC7I5BNK, i5-7260U 2,20 GHz, Link)
  • 2 x 8GB DDR4 RAM (CT2K8G4SFD8213, Link)
  • 250GB M.2 PCIe NVMe SSD (Samsung 960 EVO MZ-V6E250BW, Link)

This hardware setup is meant to be an allrounder. Fast enough to transcode multiple movies at the same time, almost completely silent in order to run it in the living room and power efficient in order to run it 24/7. It is able to hardware transcode three H.264 1080p movies at the same time with ~30-35% CPU load. Transcoding a single H.265 4K HDR movie has ~35-40% CPU load.
If you are looking for a single user setup this NUC might be overkill, the NUC i3 with 2 x 4GB RAM should be fine then.

Step 1: Install Ubuntu

  • Update BIOS with latest from Intel’s website

  • Install Ubuntu 16.04 LTS 64bit server version

  • Use the following partition scheme (ESP size was suggested by Ubuntu, swap size is much bigger than usual because of RAM transcoding):

    #1: 536MB, ESP, bootable
    #2: 64GB, swap
    #3: 185,5GB, ext4

  • Setup user named plex

Step 2: Install Plex Media Server

  • Add plex repository as source
    • echo deb https://downloads.plex.tv/repo/deb/ public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
    • curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
  • Install Plex Media Server + dependencies
    • sudo apt-get update && sudo apt-get install avahi-daemon avahi-utils plexmediaserver
    • During installation you will be asked if you want to override the plex repository source with the one from the package. Select yes.
  • Re-enable plex repository source
    • By default the plex repository source from the package is disabled (commented out), enable it in /etc/apt/sources.list.d/plexmediaserver.list

Step 3: Setup NFS and Autofs

  • Install dependencies
    • sudo apt-get install autofs nfs-common
  • Create mount directory and configure Autofs
    • sudo mkdir /data
    • sudo nano /etc/auto.master
    • Append the following line at the end of the file:
      /data /etc/auto.data
  • Create Autofs configuration file for data directory
    • sudo cp /etc/auto.misc /etc/auto.data
    • Append all your mount points at the end of the file, for example:
movies    -fstype=nfs4    <ip-of-your-nas>:/volume1/Movies
music     -fstype=nfs4    &lt;ip-of-your-nas&gt;:/volume1/Music</pre>
  • Restart Autofs
    • sudo systemctl restart autofs
  • All your mount points are now available at /data/...
  • Autofs will automatically unmount all mount points if there is no access within 5 minutes and remount if you try to access the mount point. You can keep ghost references to the mount points by adding --ghost in auto.master at the end of the appended line

Step 4: Configure Plex Media Server

  • Open http://<ip-of-your-server>:32400/web in your browser and configure your server

Step 5: Setup RAM transcoding

  • Create transcoding directory
    • sudo mkdir /tmp/transcoding
  • Setup the system to mount the RAM disk on every boot
    • sudo nano /etc/fstab
    • Append the following line:
      tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,size=64G,mode=1777 0 0
  • Grant writing permissions for the transcoding directory
    • sudo chown -R plex:plex /tmp/transcoding
  • Use /tmp/transcoding in Plex Media Server > Settings > Server > Transcoder > Temporary directory

Additional notes / tips

  • In order to update plex media server it is enough to run the system update: sudo apt-get update && sudo apt-get upgrade
  • If you setup a DDNS service for your server consider to configure the Ubuntu firewall. In that case please check out the Plex reference for which ports you need to allow

Again, special thanks to @grogster for all the time and effort put forth to make this guide possible.

Back to top

4 Likes

Plex’s metadata on a network share. (Advanced users only)

  1. This is NOT supported. USE AT YOUR OWN RISK
  2. Linux and NFS do work reliably but the degree of reliability is at your own risk subject to every involved software and hardware element involved.
  3. Proper operation is dependent on all layers between PMS and the actual data.
  4. PMS performance will decrease. The latency of the LAN is noticeable.
  5. ONLY use this if you cannot relocate the Library (metadata) to another location on your local machine (see “Moving PMS’s Library” tip) as a LAST RESORT

The above having been stated and understood:

  1. With PMS stopped, use tar to perfectly copy all the files and permissions (retaining UID/GID, and all other inode flags) to the NAS
  2. Add vers=3,local_lock=posix to the mount options if your server does not support NFSv4. This forces TCP and POSIX file locking. PMS uses POSIX locking. Most NFS servers include POSIX locking in NFSv4. Remember to adjust according to your server’s capabilities.
  3. Rename Library locally to save that copy
  4. Create a new Library directory, owned by plex:plex to mount on.
  5. Test the mount
  6. Verify locking are active mount | grep Library by visual inspection of the mount options. Some NFSv4 implementations do not include POSIX file locking by default. Caution is advised.
  7. Verify you have enabled posix file locking in any and all layers / abstractions between PMS and the actual data.
As examples, the completed entry would look something like:
  • syno:/volume1/plexdb /var/lib/plexmediaserver/Library nfs sec=sys,intr,local_lock=posix,rw,vers=3,auto,nofail 0 0

  • syno:/volume1/plexdb /var/lib/plexmediaserver/Library nfs sec=sys,intr,vers=4,rw,auto,nofail 0 0

This is an advanced tip and not for novice users. Corruption and complete loss of your PMS library metadata will result if done incorrectly.

Back to top

1 Like

Installation guide for PMS under Proxmox 5.1 within an LXC Container

Contributed by: @Johnnyh1975

1. Create an LXC Container (standard approach, well documented in Proxmox)

Use the standard approach within Proxmox and create a privileged Container (incl. definition of hostname, root password)
Select the your target operating system template, e.g. ubuntu 16.04, ubuntu 17.04 or ubuntu 17.10. (you have to download it from the Proxmox server)
Define memory and cpu allocation for your Plex container: e.g. 8 cores, 20GB RAM,… as well as network parameters

2. Install on Intel Graphics acceleration drivers Proxmox Host

First install on the Proxmox host the intel graphics acceleration drivers. (e.g. via Shell JS in the Proxmox manager)
Proxmox host is running Debian stretch.

apt-get install i965-va-driver

  • Test if the driver is working. Install vainfo

    apt-get install vainfo

  • Running vainfo should give you an output comparable to

  error: can't connect to X server!
  libva info: VA-API version 0.39.4
  libva info: va_getDriverName() returns 0
  libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
  libva info: Found init function __vaDriverInit_0_39
  libva info: va_openDriver() returns 0
  vainfo: VA-API version: 0.39 (libva 1.7.3)
  vainfo: Driver version: Intel i965 driver for Intel(R) Kabylake - 1.7.3
  vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointEncSlice
      VAProfileVP9Profile2            : VAEntrypointVLD

Well done your host is supporting the appropriate acceleration.

3. GPU passthrough configuration to Plex Container

  • Find out the right parameter of your graphics card

    ls -l /dev/dri

This should give you a comparable output to the following

crw-rw---- 1 root video 226,   0 Dec 29 14:06 card0
crw-rw---- 1 root video 226, 128 Dec 29 14:06 renderD128
  • Note the numbers behind video:

    • card0 has the id 226, 0**
    • renderD128 has the id 226,128**
  • Define the gpu passthrough by adding the following lines at the end of your 100.conf file (use the appropriate number 100, 101,… that you assigned before to the Plex container). Please adjust the following lines with the id numbers for your graphics system you have noted down just before. In the last line replace the 100 with the Plex container id of your system.

    nano /etc/pve/lxc/100.conf

lxc.cgroup.devices.allow = c 226:0 rwm
lxc.cgroup.devices.allow = c 226:128 rwm
lxc.cgroup.devices.allow = c 29:0 rwm
lxc.autodev: 1
lxc.hook.autodev:/var/lib/lxc/100/mount_hook.sh

  • When the container starts, the last line calls a shell script that you need to create to mount the devices appropriately…
    Let’s create it:

    nano /var/lib/lxc/100/mount_hook.sh

  • Add the following lines and adjust the id’s to your graphics system:

    mkdir -p ${LXC_ROOTFS_MOUNT}/dev/dri
    mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/dri/card0 c 226 0
    mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/dri/renderD128 c 226 128
    mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/fb0 c 29 0
  • Save the file and make it executable.
    chmod 755 /var/lib/lxc/100/mount_hook.sh

  • Your Plex LXC container is ready to boot up incl. GPU passthrough. Well done!

4. Boot-up your container and install Plex media server

Via Console JS of your container execute the following steps

  • Login with root and the assigned password in step 1

  • Make sure your system is up-to-date

    apt-get update && sudo apt-get upgrade

  • Head to the Plex Downloads page and download the current version of Plex Media Server

  • Use dpkg to install the Plex server:
    dpkg -i plexmediaserver*.deb

  • Enable Plex Media Server to start on reboot, and then start the server:

    systemctl enable plexmediaserver.service
    systemctl start plexmediaserver.service

  • The rest is than standard Plex configuration and media file management which is well documented. So I will not repeat it.

  • Last step to make sure your Plex server is using hardware acceleration. Within the Plex web interface, go on “settings>server>transcoder”. Make sure that advanced options are shown. And checkmark “use hardware acceleration when available”

Back to top

Moving your media and keeping the metadata - The TL;DR

This Tip / How-To, while tagged for Linux, is applicable to all PMS platforms.

Preparation

  1. Turn off “Empty Trash after Library Scan”
  2. Turn off “Automatically Update my Library”

Move your media

Make any configuration changes or physical media file moving you need to.
When you are done, proceed with the actual PMS configuration change

Updating your PMS configruation

  1. Edit each library section - Folders - ADD the new location. DO NOT EDIT OR REMOVE THE EXISTING LOCATION at this time. - SAVE the changes.
  2. PMS will see the new location and begin scanning.
  3. You will likely see a RED TRASH CAN. This is expected.
  4. All Trash Cans will be removed when the media has been located. This is expected and desired proof everything is going as expected. You can confirm this by examining the “Get Info” for any items. It will show both file locations.
  5. When completed, Edit the library section again. REMOVE the old media location.
  6. Scan one final time. The old location will be removed from the “Get Info” file location list.
  7. Empty the Trash
  8. Clean the bundles
  9. Optimize the database
  10. Wash - Rinse - Repeat for each library section until done

Cleanup

  1. Restore Empty Trash and any automatic settings previously disabled.

  2. Return to Settings - Server - Library, turn Automatic and Empty Trash back on.

That’s it. Your media has now been moved to its new location(s) and PMS is updated to reflect this.

Back to top

3 Likes

How to best report Linux server problems

This Tip/How-To, while tagged for Linux, is applicable to all PMS platforms.

By providing this information with your initial post, you save yourself and us a great deal of time otherwise wasted in asking for the pieces.

We can see the post, examine all the information provided, and give a better reply (possibly complete solution) in the first reply.

Preparation

  1. Verify DEBUG logging is enabled (Settings - Server - General - Advanced)

  2. Verify VEROSE logging is disabled

  3. Save changes if any boxes changed

  4. Depending on the type of failure; restarting PMS and waiting 2 minutes is beneficial

  5. Recreate the problem. (e.g Start playback, Let play 30 seconds, Stop playback)

  6. Wait 30 seconds for logs to flush out to disk

  7. Settings - Server - Troubleshooting (left panel) - Download Logs

  8. Download and save the ZIP

  9. Hover over the item just played to recreate the problem.

  10. Click the ellipsis -> Get Info -> View XML

  11. Capture the top portion only (down to the </Media> marker) from the browser

  12. Now prepare your posting:
    a. State the problem
    b. Paste the XML segment
    ``` (back-tick / grave character)
    Paste xml text here
    ```
    c. Attach the ZIP file (allow to upload)

  13. Click Reply.

When you have pasted the XML, it will appear like this in your post.

Pasted xml here

Back to top

4 Likes

When server and device credentials are out of sync.

Use this procedure when:

  1. You receive the nasty “No Soup For You” message
  2. You’ve changed your Plex password and now have trouble accessing something.
  3. You’ve cloned the server or performed a ‘backup & restore’ using the procedures above but now cannot access the server.

First choice - Preferences.xml missing or deleted.

If something happened to “Preferences.xml” and you need to claim the server again, with everything being normal, Start here first.

Begin here:

  1. Sign out the plex/web browser
  2. Open a new Window
  3. Go to to www.plex.tv (not app.plex.tv)
  4. Sign into your account settings.
  5. Force sign out everything as you change the password.
  6. Open an incognito window
  7. Open http://ip.addr.of.host:32400/web (or 127.0.0.1:32400/web if on the host)
  8. Sign in
  9. Claim it again.

The X-Plex-Token (PlexOnlineToken) and other credentials will now all resync
go to your devices and sign them in again.

Second choice - After a hard password reset on plex.tv

If you’ve changed your password on Plex.tv, and things didn’t go well afterwards …

There is a similar method for other hosts:

On the server computer

  1. Open a Terminal window / SSH into the machine / get into the container ,
    (whichever case applies)
  2. Stop Plex
  3. Edit Preferences.xml
    (Use the Linux text editor on the host itself.)
  4. Carefully remove the following Name="Value" pairs
    – PlexOnlineName
    – PlexOnlineToken
    – PlexOnlineMail
    – PlexOnlineHome (if it exists)
  5. Save the file
  6. Start Plex
  7. Keep the terminal window open. You will need it again momentarily.

On your computer

  1. Open Claim | Plex
  2. COPY the token given into your browser

Switch back to the Terminal session window

  1. On the command line (where the server is), type:
curl -X POST 'http://127.0.0.1:32400/myplex/claim?token=PASTE_TOKEN_HERE'
  1. Hit Enter.
  2. Wait 15-20 seconds for Curl / PMS to talk to Plex.tv and setup new credentials.

As confirmation, the curl statement will look like this:

curl -X POST 'http://127.0.0.1:32400/myplex/claim?token=claim-xxxxxxx'

Confirming success.

You will be able to confirm the server is properly reclaimed and credentials are in sync when, after executing the curl statement, it responds with a stream of XML which ends in </MyPlex>

3 Likes

Resolving permissions problems

This How-To is about finding and resolving permission issues where PMS cannot read the file(s) due to a problem somewhere in the path.

While the process is straight forward (perform ls -la for each directory in the pathname to the file), the process is time consuming and somewhat tedious.

This HowTo provides a basic script which you can use (change from read-test to write-test if needed) and find where user plex loses its permission to get to a specific file.

Consider the case of file: /tmp/a/b/c/d/e.mp4

The process

Step 1 - Temporarily make user plex a viable shell user account

Step 2 - Copy the text below to a file (making it a script)

I’ve named this “can-read”

#!/bin/sh

if [ "$1" = "" ]; then
  echo usage: $0 path-to-check
  exit 1
fi

Dir="$1"
while [ "$Dir" != "" ]
do
  if [ -r "$Dir" ];  then
    echo READ: \"$Dir\"
  else
    echo FAIL: \"$Dir\"
  fi

  NewDir="$(dirname "$Dir")"
  if [ "$NewDir" = "$Dir" ]; then
    Dir=""
  else
    Dir="$NewDir"
  fi
done

Copy the script and change the -r test to -w to test for write access

Step 3

After making it executable, start testing pathnames with :

su -s /bin/sh plex   can-read  /path/to/file.ext

Example

Check read permissions for `/tmp/a/b/c/d/e.mp4

# su -s /bin/sh plex ./can-read /tmp/a/b/c/d/e.mp4
FAIL: "/tmp/a/b/c/d/e.mp4"
FAIL: "/tmp/a/b/c/d"
FAIL: "/tmp/a/b/c"
READ: "/tmp/a/b"
READ: "/tmp/a"
READ: "/tmp"
READ: "/"
# 

Notice the fail point?

Checking permissions using ls -la finds the permissions problem.

# cd /tmp/a/b
# ls -la
total 0
drwxr-xr-x. 3 chuck chuck 60 Mar 28 03:13 ./
drwxr-xr-x. 3 chuck chuck 60 Mar 28 03:13 ../
drwx------. 3 chuck chuck 60 Mar 28 03:13 c/
# 

Step 4 - Fixing the problem

We observe that, at /tmp/a/b , directory c does not permit anyone except the owner to access it.

We correct this by fixing the permissions chmod 755 /tmp/a/b/c

One last verification confirms everything is now correct.

# su -s /bin/sh plex ./can-read /tmp/a/b/c/d/e.mp4
READ: "/tmp/a/b/c/d/e.mp4"
READ: "/tmp/a/b/c/d"
READ: "/tmp/a/b/c"
READ: "/tmp/a/b"
READ: "/tmp/a"
READ: "/tmp"
READ: "/"
# 

User plex will now be able to access everything from c down.

1 Like

Migration from another OS to Linux

Cross OS migration is a multi-level process.

  1. Copy the PMS databases and metadata
  2. Update all the media locations to point to their new locations.

Prerequisites - On the originating host

  1. Settings - Server - Library

  2. Turn off:

  • Scan my library automatically
  • Run a partial scan when changes are detected
  • Include music libraries in automatic scans
  • Scan library periodically
  • Empty trash automatically after every scan
  1. Stop Plex
  2. ZIP up the “Plex Media Server” directory.

On the new Linux host

  1. Install Plex Media Server
  2. Do not interact with it.
  3. Stop Plex
  4. Open a terminal window session to perform the following steps
  • elevate to ‘root’ privileges
$ sudo bash
  • Remove the pre-created “Plex Media Server” directory
# rm -rf "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
  • Copy the ZIP file from the Originating machine
# cp "/path/to/Plex Media Server.zip"  "/var/lib/plexmediaserver/Library/Application Support"
  • Unzip the PMS data files
# cd "/var/lib/plexmediaserver/Library/Application Support"
# unzip "Plex Media Server.zip"
  • Verify proper final directory structure
    a. Directories of importance for Linux are shown below.
    b. If you have extra directories, do not be concerned. They can be removed later.
    c. The full final path is: /var/lib/plexmediaserver/Application Support/Plex Media Server.
    d. All the files you copied over from the other host are in ‘Plex Media Server’
# ls -la "Plex Media Server"
total 64
drwxr-xr-x 11 chuck chuck  4096 Nov  6 10:31  .
drwxr-xr-x  4 chuck chuck  4096 Oct  4 11:35  ..
drwxr-xr-x  5 chuck chuck 12288 Nov  6 12:53  Cache
drwxr-xr-x  6 chuck chuck  4096 Oct 19 11:09  Codecs
drwxr-xr-x 11 chuck chuck  4096 Oct  4 11:49 'Crash Reports'
drwxr-xr-x  2 chuck chuck  4096 Apr 14  2021  Diagnostics
drwxr-xr-x  3 chuck chuck  4096 Nov  6 12:52  Logs
drwxr-xr-x  3 chuck chuck  4096 Apr 10  2021  Media
drwxr-xr-x  6 chuck chuck  4096 Apr 10  2021  Metadata
drwxr-xr-x  2 chuck chuck  4096 Apr 10  2021  Plug-ins
drwxr-xr-x  7 chuck chuck  4096 Apr 10  2021 'Plug-in Support'
-rw-r--r--  1 chuck chuck  2081 Nov  6 10:31  Preferences.xml
#
  • Preferences.xml file
    a. Windows does not yet have a Preferences.xml file.
    b. If no Preferences.xml file exists, PMS will create a new one on first start.
    c. You will have to “Claim” the new server however all your libraries will already exist.

  • Change the ownership of the files to the Plex user on the Linux host.

# chown -R plex:plex "/var/lib/plexmediaserver"
  • Make certain Linux file permissions are set correctly
# find /var/lib/plexmediaserver -type d -exec chmod 755 {} \;
# find /var/lib/plexmediaserver -type f -exec chmod 644 {} \;
# chmod +x /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Codecs/EasyAudioEncoder-8f4ca5ead7783c54a4930420-linux-x86_64/EasyAudioEncoder/EasyAudioEncoder
  1. Start Plex

  2. If you have a Plex/web browser window open – Sign out (upper right corner) – then close the tab

  3. Open an incognito window

  4. In that window, open http://127.0.0.1:32400/web

  5. Be greeted by the “Got It” and “Sign in” then the setup wizard.

  6. As the setup starts, examine whether it wants to CONFIRM your existing library sections (it should) or create new (which you will SKIP). In all cases, you do not want to create new library sections. Your existing sections will be waiting for you at the end of the setup wizard.

  7. Proceeding through the setup wizard, confirm the Friendly name you wish to use and any other settings.

  8. When you’re DONE, you’ll arrive at the Dashboard. This is completes the first phase. Next, we’ll tell Plex where your media is (as it’s seen from this host).

  9. For each Library section you have,

  • Edit the section (Hover over it - expose the ellipsis - Manage - Edit)
  • Advanced Tab - ADD the new top directory path (Do not remove the old yet) - SAVE the changes.
  • PMS will see the new location and begin scanning.
  • As each item is matched, a 2 will appear (duplicate) on each item already in your library . This is expected and desired proof everything is going as expected.
  • When completed, Edit the library section again. REMOVE the old media location. SAVE
  • Scan one final time. Observe the 2 being removed.
  • Empty the Trash
  • Clean the bundles
  • Optimize the database
  1. Repeat the above sequence for each library section until all are done.
  2. Return to Settings - Server - Library, turn Automatic and Empty Trash back on.

Back to top

6 Likes