Linux Tips

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