Moving PMS 'Library'



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:

  1. Create the ‘override’ file
  2. Move the files to their new location
  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” in the “strange” group.
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

You can create the path directly in your favorite text editor or with systemctl edit plexmediaserver

Once in the editor, create the customization override containing the following**

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

INFO: It appears some systems want Umask while others want UMask. Please be cautious of this until fully resolved and noted here.

Warning: Do not use /media as it is a reserved directory with Gnome. 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:strange

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

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 and add additional customizations with
sudo systemctl edit plexmediaserver

Cannot play media after metadata library move

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

This procedure is intended for those whose systems are init based (cat /proc/1/comm returns init).

Perform the following sequence in a root shell and with PMS stopped

sudo sh

A. Create the new location to hold the Plex Library

In this example, I show you how to use /home/plexdata. It can be any valid filesystem on your computer. The only restriction is it may not be a network file system (remote mount). This is because the database requires file locking. File locking is not supported by most network share protocols.

mkdir  /home/plexdata

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

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

C. Change ownership to plex

chown plex:plex /home/plexdata

D. Add the following entry to /etc/fstab which will ‘bind’ (overlay) the new location on top of /var/lib/plexmediaserver/Library

/home/plexdata/Library    /var/lib/plexmediaserver/Library         none  bind 0 0

E. Test the mount

mount /var/lib/plexmediaserver/Library
touch /var/lib/plexmediaserver/Library/dummy
umount /home/plexdata

F. Verify the dummy file only exists in the new location (/home/plexdata/Library)

ls /home/plexdata/Library
ls /var/lib/plexmediaserver/Library

G. Verify normal PMS operation with the mount active

mount /var/lib/plexmediaserver/Library

Start PMS

H. With Verification complete

  1. Stop PMS
  2. umount /home/plexdata
  3. rm -rf /var/lib/plexmediaserver/Library/* (Library must remain but remove all below it)
  4. mount /home/plexdata
  5. Start PMS

I. All metadata will now be stored in /home/plexdata