(Tutorial) How To Install Plex in a FreeNAS 11.2 Jail

Cosmo_Kramer

Contributor
Joined
Jan 9, 2013
Messages
103
How To Install Plex in a FreeNAS 11.2 Jail:

  1. Follow the instructions on how to create a jail, and set the following:
    1. Jail Name: plex
    2. Release: pick the latest
    3. VNET: checked
    4. IPv4 Interface: vnet0
    5. IPv4 Address: select something that is on your network and outside of your DHCP scope (e.g. 192.168.1.x)
    6. IPv4 Netmask: select the subnet mask of your network
      1. This is often 24 (equivalent to 255.255.255.0)
    7. IPv4 Default Router: set this to your router's IP address (e.g. 192.168.1.1)
    8. Auto-start: checked
  2. Once the jail is created, click on "Start" from the jail options menu (if it's not already started)
  3. Click on "Shell" from the jail options menu
  4. Once at a shell prompt, make sure your packages are up to date by running (this will also test that your network settings are correct):
    pkg update
    pkg upgrade
  5. To install Plex, run the following command:
    pkg install multimedia/plexmediaserver
  6. To setup Plex to start automatically when the jail starts, run the following command:
    sysrc plexmediaserver_enable=YES
  7. To start the Plex server, run the following command:
    service plexmediaserver start
  8. Plex is now ready to use and you can navigate to it with this URL (replace 192.168.x.x with the actual IP address assigned earlier):
    http://192.168.x.x:32400/web
  9. Once you tie a Plex account with your server, you will be able to access Plex internally and externally via:
    https://plex.tv/web

Accessing Mounted Storage In Your Jail With Plex:
  1. Follow the documentation to add additional storage in your jail
    1. Since Plex doesn't need to make modifications to your data, it's best to make the mount read-only as an additional protection
  2. After mounting the storage in your jail, it may be tempting to grant your files 777 access to give Plex access to them. Don’t do it though! There is an easy work around by creating groups in the jail with the same GroupID as the ones on the host system, and then adding the "plex" user to that group.
    1. To find out what the GroupID is of the group that is assigned permissions on the mount, run the following command in the jail (assuming you mounted the storage in /mnt in the jail):
      ls -l /mnt
    2. You’ll then see a list of mount points such as this one:
      Code:
      drwxrwx---+ 7 1002 1001 8 Mar 3 18:35 Media
    3. The column with 1002 is the UserID, and 1001 is the GroupID. If you want Plex to have access to the "Media" mount, you need need to create the "Media" (can be named anything) group in the jail with a GroupID of 1001, and add the plex user to that group. This can be done with the following command (replace 1001 with your actual group):
      pw groupadd Media -g 1001 && pw usermod plex -G plex,Media
    4. After running the previous command, you can look at the permissions of the mount again by using:
      ls -l /mnt
    5. You should now see the following instead:
      Code:
      drwxrwx---+  4 root  Media   4 Feb 21  2014 Media
    6. For Plex to have access to the mounts, you must restart Plex with the following command:
      service plexmediaserver restart
    7. You are now done. Plex will now have access to the "Media" mount. These steps can be repeated for other mounts that have different group permissions, but the "pw usermod" command will change slightly to include the additional group.

Upgrading Plex:

  1. Stop the Plex server with the following command:
    service plexmediaserver stop
  2. To update Plex, run the following command:
    pkg update && pkg upgrade multimedia/plexmediaserver
  3. Start Plex again with the following command:
    service plexmediaserver start
 
Last edited:

panz

Guru
Joined
May 24, 2013
Messages
556
Is Sysctls "allow.raw_sockets=true" necessary during Jail creation?
 

panz

Guru
Joined
May 24, 2013
Messages
556
I'm following your tutorial now and the Plex Media Server is up and running! Many, many thanks ;)

How do I backup Plex metadata?
 

Cosmo_Kramer

Contributor
Joined
Jan 9, 2013
Messages
103
I'm following your tutorial now and the Plex Media Server is up and running! Many, many thanks ;)

How do I backup Plex metadata?

You're welcome.
There are many ways you can do this. I for one just take ZFS snapshots of the dataset with Plex on it.
If that doesn't work for you, you could probably copy the Plex folder to another drive. The Plex data folder can be found here:
/usr/local/plexdata/Plex Media Server
 

panz

Guru
Joined
May 24, 2013
Messages
556
Let's consider the situation of a complete reinstall (from scratch) of FreeNAS. After creating the Plex Jail as you explained above, how do I rollback the backup? Simply copying the data into /usr/local/plexdata/Plex Media Server?
 

Cosmo_Kramer

Contributor
Joined
Jan 9, 2013
Messages
103
Let's consider the situation of a complete reinstall (from scratch) of FreeNAS. After creating the Plex Jail as you explained above, how do I rollback the backup? Simply copying the data into /usr/local/plexdata/Plex Media Server?

I've never done this before, but I'd assume that if you install Plex as mentioned in the guide above, then stop the service, then copy over the install with the backup data folder, then start Plex again, that it'd work.
 

panz

Guru
Joined
May 24, 2013
Messages
556
After leaving my machine unattended for about 3 hours I can't access the installed Plex Server; this is the top output

Code:
Mem: 343M Active, 715M Inact, 25G Wired, 118M Buf, 5395M Free
ARC: 23G Total, 1130M MFU, 22G MRU, 911K Anon, 85M Header, 348M Other
Swap: 12G Total, 12G Free
 
  PID USERNAME    THR PRI NICE  SIZE    RES STATE  C  TIME  WCPU COMMAND
18959 plex          2  20    0  319M  204M select  3  1:10  0.00% Plex Media Scanner
79521 plex        13  35  15  401M  230M select  6  0:41  0.00% python
79520 plex        66  20    0  344M  198M uwait  0  0:23  0.00% Plex Media Server
79527 plex        12  20    0  188M 28696K uwait  4  0:01  0.00% Plex DLNA Server
27301 root          1  20    0 16600K  2392K CPU6    6  0:00  0.00% top
13485 root          1  20    0 14180K  1844K nanslp  0  0:00  0.00% cron
13432 root          1  20    0 12088K  1872K select  7  0:00  0.00% syslogd
26959 root          1  20    0 17568K  3184K pause  0  0:00  0.00% tcsh
 


No 192.168.x.x:32400/web access :(
 

Cosmo_Kramer

Contributor
Joined
Jan 9, 2013
Messages
103
Try restarting Plex:
service plexmediaserver restart

When accessing the Plex Web GUI, make sure you type this:
http://ip.addr.here:32400/web/index.html
Obviously, changing IP.Addr.here to what ever your IP address is i.e. http://192.168.1.45:32400/web/index.html


If that doesn't work, then try sockstat in the jail:
sockstat -4l
^^ lowercase L

This will show listening connections and see if Plex is listening on 32400.
 

panz

Guru
Joined
May 24, 2013
Messages
556
Committing

Code:
service plexmediaserver restart


did work, but after quite a while it "sleeps" again :mad:
 

panz

Guru
Joined
May 24, 2013
Messages
556
I've never done this before, but I'd assume that if you install Plex as mentioned in the guide above, then stop the service, then copy over the install with the backup data folder, then start Plex again, that it'd work.

Today I successfully migrated the database from the .PBI Plex installation to the Jail created following your tutorial.

This procedure could be done to restore the database from a backup too (e.g. from a snapshot).

Here's what I did.

First, open a shell and cd to the upper level directory containing the Plex Media Server dir
(please replace "/mnt/storage/jails/plex/" with your path):

Code:
cd /mnt/storage/jails/plex/usr/local/plexdata/


under "plexdata" directory there's your Plex Media Server database. Let's delete it
(WARNING: double check your command line before pushing enter!)

Code:
rm -Rf Plex\ Media\ Server/


note that there is a space before "Media" and before "Server".

Locate the directory containing your source ("from") database. This puzzled me a lot, because in the .PBI installation the Plex Media Server database is located here (replace the path after /mnt with yours):

Code:
/mnt/storage/jails/plexmediaserver_1/usr/pbi/plexmediaserver-amd64/plexdata/Plex\ Media\ Server/



Copy this database to the other Jail location:

Code:
cp -Ripv /mnt/storage/jails/plexmediaserver_1/usr/pbi/plexmediaserver-amd64/plexdata/Plex\ Media\ Server/ /mnt/storage/jails/plex/usr/local/plexdata/Plex\ Media\ Server/


Now we have to restart the server of the plex jail for the modifications to take effect:

Code:
jls
jexec 2 tcsh
service plexmediaserver restart


jls = lists all running jails
jexec 2 tcsh = open a shell into the #2 jail (in my case it's the jail running the plex server)
service plexmediaserver restart = restarts the Plex Server

Voilà :)
 

adrianwi

Guru
Joined
Oct 15, 2013
Messages
1,231
After a number of positive posts, thought I'd try upgrading through the UI and it worked without any issues. Took about 30-45 minutes, but all good!
 

marcusorwen

Dabbler
Joined
Aug 22, 2013
Messages
14
After a number of positive posts, thought I'd try upgrading through the UI and it worked without any issues. Took about 30-45 minutes, but all good!

Are you reffering to the PBI plugin for FreeNAS then or through this guide? (suspect the first).
I do not dare updating the plugin since i have had the database corrupt/not readable when upgrading twice.
Having a pretty large library of movies and tv-shows the metadata is pretty large.
 

adrianwi

Guru
Joined
Oct 15, 2013
Messages
1,231
Sorry, yes updated the PBI plugin.

Not sure how big my database is, but have 6-7TB of media.
 

diedrichg

Wizard
Joined
Dec 4, 2012
Messages
1,319
Once at a shell prompt within the jail, find out what the GroupID is of the group that is assigned permissions on the mount with this command:
ls -l /mnt

You’ll then see a list of mount points such as this one:
drwxrwx---+ 7 1002 1001 8 Mar 3 18:35 Media

The column with 1002 is the UserID, and 1001 is the GroupID. If you want Plex to have access to the Media mount, you need need to create the Media group in the jail with a GroupID of 1001, and have the plex user in it.
Thank you! This helps me with several other jails too!
 

Cosmo_Kramer

Contributor
Joined
Jan 9, 2013
Messages
103
Are you reffering to the PBI plugin for FreeNAS then or through this guide? (suspect the first).
I do not dare updating the plugin since i have had the database corrupt/not readable when upgrading twice.
Having a pretty large library of movies and tv-shows the metadata is pretty large.

I would suggest using a jail instead. When upgrading the Plex port, it doesn't affect your database at all. The upgrade takes less than a minute with portupgrade.
 

calisto

Cadet
Joined
Apr 4, 2014
Messages
1
Hi,

has anyone installed the Unsupported (as in totally unofficial) Appstore onto there Plex Freenas set up & if yes how please?

Thanks
Calisto
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Hi,

has anyone installed the Unsupported (as in totally unofficial) Appstore onto there Plex Freenas set up & if yes how please?

Thanks
Calisto

This isn't the plex forums. Please direct your question to the Plex forums.

Thanks.
 
Top