Maybe you’re also using Plex and have already thought about how to move Plex away from the system drive to an external disk. This is especially useful if you’re running Plex on a Raspberry Pi using an SD card and want to reduce write operations on it.
I will not use the often-mentioned approach with symlinks, but instead show how to implement this in a system-conform way on systems using systemd, such as Debian.
The idea
To move the Plex library away from the system drive to another disk, the following general approach works well:
- Move the Plex library to a share
- Ideally the same share that already contains your media libraries
- Advantage: shared backups
This can be implemented most easily using systemd units, more specifically with a so-called override file for the existing Plex systemd unit on Debian. This ensures that your changes remain intact even after Plex or its systemd unit is updated.
Preparation
a) Stop Plex
sudo systemctl stop plexmediaserver
b) Create a directory for the Plex library
I will refer to it as “PlexData”, located on the share that contains the media libraries. Make sure to remember the full path. In the following examples, I use: /share/Holo Deck/PlexData/
c) Assign “PlexData” to user “plex” and group “users”
sudo chown plex:users PlexData
sudo chmod 775 PlexData
d) Add user “plex” to the group “users”
sudo usermod -a -G users plex
Copy the existing library
Now copy the existing Plex library into this directory. The original location is: /var/lib/plexmediaserver/Library/Application Support/
(If a path contains spaces, as it does here, the quotation marks are very important!)
cd "/var/lib/plexmediaserver/Library/Application Support"
sudo cp -a "Plex Media Server" "/share/Holo Deck/PlexData/"
Before Plex will start, we now make sure that the directory actually exists. To do this, an override file is created for the already existing Plex service. This can be done very easily with:
sudo systemctl edit plexmediaserver
An editor will open. In the upper marked section between the comments (make sure to leave those comments in place!), insert the following. I’ve included the complete initial lines here:
### Editing /etc/systemd/system/plexmediaserver.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file
[Unit]
ConditionPathExists=/share/Holo Deck/PlexData/Plex Media Server/Preferences.xml
[Service]
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/share/Holo Deck/PlexData"
### Edits below this comment will be discarded
Of course, you’ll need to adjust the share path to match the one you chose.
Enable everything again
Now we start the Plex service again:
sudo systemctl start plexmediaserve
If you did everything correctly, your Plex server should now be running again and using the library from the newly created directory. On a reboot of the NAS, Plex will only be started if the external drive containing the new library is available.
If you want to check whether Plex is running, you can do so with:
systemctl status plexmediaserver
This not only shows whether Plex is running, but also provides useful information if Plex fails to start. If, for some reason, Plex is not running—e.g. after a reboot—you can restart it with:
sudo systemctl restart plexmediaserver
Once you’ve confirmed that everything is working correctly, you can delete the old library and thus reduce write operations on your SD card.
Happy Plex-ing.