• Home
  • Blog
  • Migrate plex from a warden jail to an iocage jail

Migrate plex from a warden jail to an iocage jail

Vincent Danen

November 04, 2018

I've been running FreeNAS 11.2 beta for a while (currently on 11.2-RC1). I've got a bunch of media on it from when I started running FreeNAS 9 (home videos, music, etc.) and I've not taken the step to migrate the old warden-based jails to the newer iocage jails. This meant that my Plex jail was not listed in the web UI. I could get into the jail using jexec but couldn't really configure it or use the web UI to control it. This was sufficient to apply Plex upgrades and other things that I needed to do, from within the jail, which was all CLI-based.

Amongst other fiddling today, I decided to create a new jail in the FreeNAS web UI and try to migrate the old jail to a new one. It had to take 10 minutes or less or I wasn't interested (I didn't want to fight with it on a Sunday!). I was pleasantly surprised.. it took maybe 15 minutes including testing. But I had prepared the old jail a long time ago in that I had all of the media and data files in storage volumes outside of the jail.

I have one pool named "storage" and within this pool I have two datasets: "plex" and "plex_media". The first contains all the media files for Plex, the second has all the data files (basically /usr/local/plexdata). This meant that all configuration data for Plex existed outside of the jail. If you have these local to the jail, you'll want to create a dataset, stop the Plex server, mount the dataset in the jail, and copy the data files over. Plex respects symlinks so it works out pretty good (you'll see what I mean in a moment). I had plex mounted in the jail at /media and plex_media mounted in the jail at /plex_media.

Creating the new jail involved very little "special sauce". When I created the jail, I added similar mount points as those described above to the jail. I also made sure before I started the new jail to stop the Plex server running in the old jail since having two Plex servers accessing the same metadata at the same time would probably cause issues.

I did this using (in the old jail):

# service plexmediaserver stop
# sysrc plexmediaserver_enable=NO

Note, you can see where those datasets are mounted in the jail using mount on the FreeNAS host:

/mnt/storage/plex on /mnt/iocage/jails/plex/root/media (nullfs, local)
/mnt/storage/plex_media on /mnt/iocage/jails/plex/root/plex_media (nullfs, local)

In the new jail, which was pristine, I did the following:

root@plex:~ # pkg upgrade
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[plex] Installing pkg-1.10.5_5...
[plex] Extracting pkg-1.10.5_5: 100%
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file or directory
[plex] Fetching meta.txz: 100%    944 B   0.9kB/s    00:01
[plex] Fetching packagesite.txz: 100%    6 MiB   2.2MB/s    00:03
Processing entries: 100%
FreeBSD repository update completed. 32468 packages processed.
All repositories are up to date.
Updating database digests format: 100%
Checking for upgrades (1 candidates): 100%
Processing candidates (1 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
root@plex:~ # pkg upgrade
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (1 candidates): 100%
Processing candidates (1 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
root@plex:~ # pkg install multimedia/plexmediaserver
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    compat9x-amd64: 9.3.903000.20170608
    compat10x-amd64: 10.3.1003000.20170608

Number of packages to be installed: 3

The process will require 200 MiB more space.
71 MiB to be downloaded.

Proceed with this action? [y/N]: y
[plex] [1/3] Fetching plexmediaserver- 100%   66 MiB   7.7MB/s    00:09
[plex] [2/3] Fetching compat9x-amd64-9.3.903000.20170608.txz: 100%    3 MiB   1.5MB/s    00:02
[plex] [3/3] Fetching compat10x-amd64-10.3.1003000.20170608.txz: 100%    2 MiB   1.2MB/s    00:02
Checking integrity... done (0 conflicting)
[plex] [1/3] Installing compat10x-amd64-10.3.1003000.20170608...
[plex] [1/3] Extracting compat10x-amd64-10.3.1003000.20170608: 100%
[plex] [2/3] Installing compat9x-amd64-9.3.903000.20170608...
[plex] [2/3] Extracting compat9x-amd64-9.3.903000.20170608: 100%
[plex] [3/3] Installing plexmediaserver-
===> Creating groups.
Creating group 'plex' with gid '972'.
===> Creating users
Creating user 'plex' with uid '972'.
[plex] [3/3] Extracting plexmediaserver- 100%
Message from plexmediaserver-

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

multimedia/plexmediaserver includes an RC script:

sysrc plexmediaserver_enable=YES

service plexmediaserver start

Once started, visit the following to configure:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

root@plex:~ # sysrc plexmediaserver_enable=YES
plexmediaserver_enable:  -> YES

root@plex:~ # cd /usr/local
root@plex:/usr/local # mv plexdata plexdata.org
root@plex:/usr/local # ln -s /plex_media plexdata
root@plex:/usr/local # service plexmediaserver start

I kept the old plexdata directory just as a precaution; you could easily delete it.

After this I grabbed the MAC address of the jail so that I could update my static DHCP mapping to give it the IP address of the old jail:

root@plex:/usr/local # ifconfig|grep ether
    ether 02:ff:60:14:fa:0a

After updating the DHCP server and flushing the ARP cache, I restarted the jail using the web UI. After that, Plex was running properly with all of the old media, at the old web address, available to Google Chromecast and my mobile devices, etc.

I know you can run Plex as a plugin but I like running it in a jail as you get a bit more control over it and don't typically have to wait too long for Plex server upgrades.

The last step is to remove the old warden jail. I'll likely wait a few days before I do that to ensure the new jail is working properly. In the meantime, with the new DHCP map and the Plex server disabled in the old jail, it shouldn't be running and interfering with anything.

This was actually a lot easier than I had expected! This is the second migration of Plex I've done and the first was so painful I didn't want to try again, but this one was really easy (granted the first was from a macOS server to FreeNAS so there was a bit more effort, but it completely hosed all of my metadata so it was like starting from scratch). At any rate, I know a lot of people in the FreeNAS community that use Plex were having difficulty with migrating jails so I thought I would quickly write this up for anyone who might still need it (keeping in mind that 11.2 is still technically a beta product although it's worked pretty well for me thus far, your mileage may vary). For the record, it took me longer to write this than to do the actual upgrade!

Next step is to setup another jail to play with OpenProject and possibly move my GitHub setup from a separate machine here at home onto the FreeNAS server (those are likely Christmas shutdown projects though).


December 28, 2018 @ 6:54 AM

Hey just wanted to say thanks for writing this post. Your post (along with this one here:https://forums.freenas.org/index.php?threads/how-to-migrate-plex-plexpass-version-from-a-warden-jail-to-an-iocage-jail.60128/) helped a lot with my own migration of Plex! One thing I did have trouble with afterwards was that my server settings (logins, etc) all seemed to migrate over just fine, but no libraries are loaded. I did do a start/stop of the Plex service in the new jail before copying the data over but not sure where else I might have gone wrong. Any ideas?

Vincent Danen
December 28, 2018 @ 12:10 PM

Hi Leng. Your settings are typically stored in a different place from your Media library. You should double-check the path. If you used an external storage pool (such as I do, one for Plex media and one for Plex settings) make sure you've mounted it inside the jail.

You can check on the FreeNAS host to see what's mounted where, for instance (relevant output of mount:

/mnt/storage/plex on /mnt/iocage/jails/plex/root/media (nullfs, local)
/mnt/storage/plex_media on /mnt/iocage/jails/plex/root/plex_media (nullfs, local)

I have my storage volumes mounted in /media and /plex_media respectively. In the jail, I use symlinks to point to the right place (note that the Plex package and the Plex-pass package use different paths by default):

[email protected]:/usr/local # ls -al|grep plex
lrwxr-xr-x   1 root  wheel   11 Nov  4 15:47 plexdata-plexpass -> /plex_media

That's for the configuration stuff (yes my name is not amazing). I have the libraries in Plex itself pointing to /media/Movies, etc. You can find that in Settings -> Manage -> Libraries and update each individually.

Hope that helps!

December 29, 2018 @ 2:37 PM

Hey Vincent,

Thanks for the reply! I had found the old plexdata folder in the expected place in the old warden jail:

```/mnt/PlexJail/Jail/customplugin_1/var/db/plexdata/Plex Media Server

I was then copying it to the corresponding directory in the iocage jail:

```/mnt/PlexJail/iocage/jails/plex/root/var/db/plexdata/Plex Media Server/

What I didn't realise was when I executed the command, it copied the old Plex Media Server directory into a new Plex Media Server directory so I had a nested /Plex Media Server/Plex Media Server/ situation going on. Once I fixed that, I then realised that wasn't even the right place to copy it to! The correct directory was:


Once that was sorted, all of my libraries loaded but I'm still working on getting the mount points working. Running mount in the jail outputs this:

```PlexJail/iocage/jails/plex/root on / (zfs, local, nfsv4acls)

I've used the FreeNAS Web GUI to set the Mount Points with the source as /mnt/MediaVolume/Media and the destination as /mnt/PlexJail/iocage/jails/plex/root/MediaVolume but it doesn't seem to be actually working. I suspect I have a permissions issue that I've been trying to resolve by following this tutorial (https://www.youtube.com/watch?v=XUCIhlh6jCM) though I've got an issue in that the user/group for the MediaVolume directory is root/wheel as in your instance!

Hopefully I'm close though...

Vincent Danen
January 04, 2019 @ 9:04 AM

You shouldn't be mounting from within the jail. You should be assigning that from the web GUI (don't mount anything from within the jail).

In the WebGUI Storage -> Pools you should have a dataset defined (i.e. I have two: plex and plex_media). Then in Jails find your jail, click the triple dots to get the pulldown and select Mount points. This is where you should be mounting things. Sounds like this is what you did with /mnt/MediaVolume/Media pointing to /mnt/PlexJail/iocage/jails/plex/root/MediaVolume. I'm guessing MedaiVolume is your dataset?

You could look on the FreeNAS host (not in the jail) to see if the data you expect is in /mnt/MediaVolume/Media; perhaps because you copied the files directly into the jail, your mount point is not mounted over top of the data, thus hiding it?

If you copy a random file or make a directory in your jail in /MediaVolume/ you should see it on the FreeNAS host itself. If that's true, maybe try unmounting the volume from the WebGUI, move the directory contents you copied in there, then remount and copy it back and see if it shows up?

(Also sorry for the slow response, for some reason I'm not getting mail notifications on new comments and I've not yet built in notifications on replies so you may be annoyed that you have to keep coming back to see if I've replied)

January 08, 2019 @ 10:17 PM

Oops, I must have been unclear - yes, my dataset is MediaVolume and I used the FreeNAS Web GUI to assign the mount points like you described. PlexJail is the iocage jail and customplugin_1 is the old warden jail:

[[email protected] /mnt]# mount MediaVolume on /mnt/MediaVolume (zfs, local, nfsv4acls) MediaVolume/Media on /mnt/MediaVolume/Media (zfs, local, nfsv4acls) PlexJail on /mnt/PlexJail (zfs, local, nfsv4acls) PlexJail/Jail on /mnt/PlexJail/Jail (zfs, local, nfsv4acls) PlexJail/Jail/customplugin_1 on /mnt/PlexJail/Jail/customplugin_1 (zfs, local, nfsv4acls) PlexJail/iocage on /mnt/PlexJail/iocage (zfs, local, nfsv4acls) PlexJail/iocage/jails/plex on /mnt/PlexJail/iocage/jails/plex (zfs, local, nfsv4acls) PlexJail/iocage/jails/plex/root on /mnt/PlexJail/iocage/jails/plex/root (zfs, local, nfsv4acls) /mnt/MediaVolume/Media on /mnt/PlexJail/iocage/jails/plex/root/MediaVolume (nullfs, local)

What's really odd is that when I login to the Plex Web GUI, the mount point isn't visible to select, however I can type in the direct path and it seems to load all the media correctly. I'm totally boggled as to what the issue is and haven't been able to figure it out.

But since everyone can access media just fine now I suppose it doesn't matter...just one of those oddities that I can't help thinking if I understood a bit more I'd know what mistake I made!

Leave a Comment

Comments use MarkDown. Need help? MarkDown Cheatsheet