Migrating Plex TrueNAS plugin to a custom jail

TrueNAS includes a set of plugins that will configure a certain application in a jail, for instance Plex. It’s a really nice feature, it works and it’s easy to use. But for long term use the plugins tend to not work as well. I’ve seen issues keeping the jail up to date, both with the latest release of Plex but also with the latest release of FreeBSD. For long term use a custom jail is a better choice since you have much more control over it. Here I will show how you can migrate Plex already running as a plugin to a custom jail on TrueNAS.

Start by logging in to your TrueNAS admin panel and create a new custom jail.

  1. Because of my network configuration I will be using the advanced jail creation option.
  2. Give the jail a name, for instance plex02.
  3. Make sure you set jail type to Clone Jail. You can read more about the differences in the TrueNAS forum.
  4. Choose the latest available release.
  5. Plex need internet access so the jail needs networking.
    1. Activate VNET.
    2. Activate Berkely Packet Filter.
    3. Set vnet_default_interface to none.
    4. Set IPv4 interface to vnet0.
    5. Pick an IP-address and netmask.
  6. I’m putting this jail on a VLAN so I have already created a bridge I want to use with it. Therefore I go to Network Properties and then change interfaces to vnet0:mybridge. Here is some more information about using jails with VLANs.
  7. Create the jail.

Now I like to switch over to using SSH instead. So SSH to your TrueNAS server, start the jail and open a console to it.

iocage start plex02
iocage console plex02

Install some dependencies.

pkg install nano ca_root_nss

Plex is available from the FreeBSD repository right out of the box so you could just run pkg install plexmediaserver or pkg install plexmediaserver-plexpass if you have a Plex pass.

But then you will get a pretty old release of Plex. If you want to get the latest version and get updates quickly you need to first do the following.

mkdir -p /usr/local/etc/pkg/repos
nano /usr/local/etc/pkg/repos/FreeBSD.conf

Add the following to the FreeBSD.conf file.

FreeBSD: {
    url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"

If you now run pkg install plexmediaserver (or plexmediaserver-plexpass) you should get the latest available version.

When Plex has been installed you need to run the following for Plex to start when the jail starts.

sysrc plexmediaserver_plexpass_enable=YES

Check which UID the Plex user is using, it will probably be 972. Save the UID and then logout from the console and stop the jail.

id plex
iocage stop plex02

You now need to setup the same mount points for this jail as you have for the plugin jail. You can do this in the TrueNAS GUI by going to: Jails -> expand the plex02 jail -> Mount Points -> Actions -> Add.

Check which version of Plex the plugin jail is running. If it’s an older version compared to the new jail you should try to update the plugin jail. You can do that by clicking Update on the Jail page in the TrueNAS GUI. If the plugin jail still is running an older version after updating the jail the next step might still work, as long as the difference in version isn’t too big it probably will. You don’t have anything to lose by trying so try and if it doesn’t work there are methods to manually upgrade Plex in a plugin jail, but that is outside the scope of this guide.

Now it’s time to copy all of the Plex data from the plugin jail to the new custom jail. I will do this over SSH as the root user. First navigate to the folder where the jails are stored.

cd /mnt/NAMEOFPOOL/iocage/jails

If you run ls -la here you will see a folder for each jail, in my case I have plex01 (old jail) and plex02 (new jail). Now you can copy the data from the old jail to the new one, don’t forget to stop the old jail first.

iocage stop plex01
cp -a plex01/root/Plex\ Media\ Server/. plex02/root/usr/local/plexdata-plexpass/Plex\ Media\ Server/

As you can see the Plex plugin stores its data in a different location compared to when you install it from the repository. Keep in mind that it can take a long time to copy all of the files.

If the UID for the Plex user that you saved earlier was 972 then you don’t have to do anything more since the Plex plugin also uses 972. If it wasn’t 972 then you will need to change the owner of the files and folders you just copied. You can do that by running the following command.

chown -R 972: plex02/root/usr/local/plexdata-plexpass

You can now startup the new jail and Plex should be available on the IP-address you picked when you created the jail, along with all of your Plex data.

iocage start plex02

I recommend running the new jail for a few days before removing the old jail, just to make sure it works fine. When you have removed the old jail you could rename the new jail to what the old jail was called.

One Reply to “Migrating Plex TrueNAS plugin to a custom jail”

  1. Thank you so much for this.
    It meets my needs for moving a nextcloud instance from a plugin to a jail.
    You’ve written down what I thought I would end up doing, mitigating the pain of working it all out…
    At the moment it’s a hybrid and a pain to upgrade 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.