• 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:
    plexmediaserver: 1.13.8.5395
    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-1.13.8.5395.txz: 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-1.13.8.5395...
===> Creating groups.
Creating group 'plex' with gid '972'.
===> Creating users
Creating user 'plex' with uid '972'.
[plex] [3/3] Extracting plexmediaserver-1.13.8.5395: 100%
Message from plexmediaserver-1.13.8.5395:

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

multimedia/plexmediaserver includes an RC script:
/usr/local/etc/rc.d/plexmediaserver

TO START PLEXMEDIASERVER ON BOOT:
sysrc plexmediaserver_enable=YES

START MANUALLY:
service plexmediaserver start

Once started, visit the following to configure:
http://localhost:32400/web

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

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).

Enjoy!

Leave a Comment

Comments use MarkDown. Need help? MarkDown Cheatsheet