Setup PLEX in an iocage on FreeNAS

FreeNAS will soon be replacing the jails managed by warden with iocage. You will still be able to use existing jails however you will not be able to implement the latest jail template currently at release 11.1

If you are feeling adventurous then you can setup an iocage jail using the FreeNAS CLI and this tutorial will show you how to setup PLEX in an iocage jail.

It’s been possible to use iocage on FreeNAS for a while however the release of FreeNAS 11.1 U4 caused network issues when setting up an iocage jail so the first thing we will need to do is:

  • Fix the network issues
  • Create the Jail
  • Add storage to the jail using fstab
  • Install PLEX

Fix the network issues

o fix the network issues open the FreeNAS shell CLI and then type

cd/tmp

Now clone and update iocage

git clone --recursive https://github.com/iocage/iocage

Finally copy the iocage files from the tmp folder to /usr/local/lib/python3.6/site-packages/iocage/lib

cp -R iocage/iocage/lib/ /usr/local/lib/python3.6/site-packages/iocage/lib

Create the jail

Now that you have updated the iocage files you can now go ahead and create the jail. In this instance we will call the jail and the hostname PLEX. and this is done by using the following command.

iocage create --name "PLEX" -r 11.1-RELEASE ip4_addr="vnet0|{IP Addres}/24" defaultrouter="{Default Gateway}" boot="on" host_hostname="PLEX" vnet="on"

Replace the following:

  • {IP Address} your chosen IP address for the jail
  • {Default Gateway} the IP address of the default gateway of your router e.g. 192.168.0.1

Add storage to the jail

Now that you have created the jail you can now add the storage. This is done with the following command using fstab.

iocage fstab -a {Name Of Jail} /your/source/path /destination/path nullfs rw 0 0

and repeat as necessary. Now that you have created the jail and added the storage, you can now go on to install the plex server. To install the PLEX server you now have to access the PLEX jail and this is done with the folowing command.

iocage console PLEX

Install Plex

make sure the packages are up-to-date using

pkg update && pkg upgrade

Once any of the packages have been updated you can now continue to install the PLEX server using the folowing command

pkg install multimedia/plexmediaserver

Once the installation completed has completed use the following command to ensure that the Plex server will start automatically should you have to restart the server/jail.

sysrc plexmediaserver_enable=YES

Now start the PLEX media server with

service plexmediaserver start

You can now test that the Plex server is working by entering its URL into your web browser.

http://192.168.X.X:32400/web

Now that we have set up the server we should now associate your plex account with your newly installed server. By associating the Plex server with your Plex account we will be able to view media internally and externally from your network by using the following link

https://plex.tv/web

Upgrading plex

Plex is updated regularly and you are able to update plex easily without losing any data. When an update is available you will be notified via the web interface of the server, or you can visit http://www.freshports.org/multimedia/plexmediaserver/

To upgrade Plex you will need to stop the service from running by using the following command.

service plexmediaserver stop

To download and update Plex run the following command.

pkg update && pkg upgrade multimedia/plexmediaserver

After writing this post I noticed that I was not getting the most up-to-date version of PLEX even after following the procedure above. After visiting the FreeNAS forums I was advised to switch to the most recent repo, so, If you want to switch to the most recent repo you should create the following file.

nano /usr/local/etc/pkg/repos/FreeBSD.conf

When I tried this I didn’t have a pkg or repos folder so I just changed directory to /etc and created the extra directories with

mk dir pkg
cd pkg
mk dir repos
nano FreeBSD.con

And add the following to the FreeBSD.conf file

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

Once you have saved the file run the following

pkg upgrade

This will rebuild the package database and pull the latest versionsof the packages into your jail, including PLEX.

Restart Plex with the following command

service plexmediaserver start

You should now have a fully functioning Plex server.