Skip to content

TrueNAS Media Server Virtual Machine

imjustleaving edited this page Dec 22, 2023 · 65 revisions

LAST UPDATED 9/19/23

Many people prefer not to run apps on the bare metal TrueNAS server, and thats fine. I totally get it. Using your TrueNAS as just a NAS and using NFS shares to mount into a VM is just as good (if not better) a solution to hosting a media suite. In order to do that, I have automated the process as much as I could for the end user. This involves the use of scripts to automatically setup an Ubuntu Server VM and configure an *arr stack through Portainer.

A Note On Privacy

This guide was created on a virtual machine which was then destroyed. All settings, IPs, API keys, and the like no longer exist, and are therefore, unredacted for your convenience.

A Note on Piracy

I don't live in the United States. This is not a guide on how to steal things off the internet; this is a software install guide. Don't break the law of the country you live in. You've been warned - the rest is on you.

Starting Points

Its possible to use the script as a standalone. Thats not the intention, so I'll talk about what to modify and where if that is your use-case. If you are running this to interact with TrueNAS Scale, the first thing you should do is configure your TrueNAS like this before you move forward. Do not skip these steps otherwise things won't work!

Dataset Structure

We have to create some directories from within the shell to setup media folders for the container. Navigate to System Settings > Shell then to the top directory of the pool you want to use for your data. For example, if I have a pool named "tank" and I want to create my media folder there, I would navigate to the shell and type cd /mnt/tank. Now copy and paste this entire command into the shell to create the directories with the correct permissions:

mkdir -p ./media/{downloads,movies,tv} && \ chown -R apps:apps ./media ./media/{downloads,movies,tv} && \ chmod -R 777 ./media/{downloads,movies,tv} ./media

NFS Shares

Once you're datasets are setup, navigate to Shares > Unix (NFS) Shares. If it is not on, turn on the service, then add the dataset you just made as a share:

image

Sysctls

We need to add some system controls in for logging and networking. Go to System Settings > Advanced > Sysctl box > and click Add. Ignore the warning when it pops up.

Add the following into the panel on the right (format is variable = value):

  • fs.inotify.max_user_watches = 524288
  • fs.inotify.max_user_instances = 512
  • net.ipv4.ip_forward = 1
  • net.ipv4.conf.all.src_valid_mark = 1

Building a Bridge

Before we setup the VM, we have to build a network bridge. This is necessary because without it, our VM won't be able to see anything on our TrueNAS host. Follow the docs here, or even better, follow this YouTube video.

Getting the ISO

I used Ubuntu, but you can use anything you want which is Debian based. Find the downloadable ISO here and save it to a location in your TrueNAS pool. Note: I did this on Ubuntu Server 22.04. I could not get 23.04 to work.

Setting Up the VM

For this VM, I will be using Ubuntu Server. My recommendation is to use the latest version. On TrueNAS Scale (screenshots are from v. 22.12.3.3), go to the Virtualization tab and click the blue button on the top right to Add. Make your settings look like mine.

image

image

image

Pick a zvol location which is preferably on an SSD. Putting this on spin drives will make it feel really slow.

image

image

Click through the rest of the options without saving and you're done!

image

Now you should see this. Click the slider to start the VM, then expand the box by clicking on the down arrow on the right (if you haven't already) and click Display to enter into the console. Allow the pop-up in your browser.

Install Ubuntu however you like - I wont be covering how to do that here. If you have never done it before, basically just follow the steps without changing any of the default options. Remember the username and password you choose as we will need that later.

image

Once you get to this screen, go back to the TrueNAS page, Power-Off the VM, click Devices, then find the 3 dots at the end of the line which says CDROM and delete that device. Then go back to the Virtualization tab and Restart the VM.

Click Display again. You may need to hit enter to see the Login prompt. Enter the username and password you chose, and you should see the Ubuntu Server Prompt.

image

Enter the command ip a and note the IP address your machine has been assigned.

image

Automatic Install

Now its time for the automation. Script 1 is going to completely setup your new VM by doing some things:

  • updating the VM
  • installing a webgui front end for server management called Webmin
  • installing Docker
  • installing Portainer
  • creating a user and group called "apps" so the TrueNAS permissions work
  • installing the package to mount an NFS share
  • mount your TrueNAS server to /mnt as well as adding an entry to fstab so it will survive restarts
  • creates a local directory structure in case you want to use this as a standalone
  • creates a Docker network for all the apps

It then will deploy the following conatiners:

  • emby
  • flaresolverr
  • jellyseerr
  • prowlarr
  • qbittorrent (with VPN and vuetorrent UI)
  • radarr
  • recyclarr
  • sonarr
  • watchtower
  • unpackerr

After, it will configure the containers to talk to each other. The script does most of that for you, but it can't do everything. For example, you will have to setup Emby and Jellyseerr on your own. YouTube will help with that. What this script will do is:

  • qBittorrent - uses your wireguard.conf file for the automatic configuration of the VPN, changes settings to enable vuetorrent webui, removes all speed limits and max simultaneous downloads, binds qbit to the wg0 network interface
  • Prowlarr - add radarr/sonarr to the apps list, adds your discord webhook, adds qbittorrent as the download client
  • Radarr - sets the root folder, adds your discord webhook, adds qbittorrent as the download client, sets up profiles for recyclarr
  • Sonarr - sets the root folder, adds your discord webhook, adds qbittorrent as the download client, sets up profiles for recyclarr
  • Recyclarr - copies all the current download profiles into a config file and syncs Sonarr and Radarr to them

Open a terminal and ssh into the new Ubuntu Server VM (ssh {username}@{IP address}). Type yes when prompted to connect for the first time, then enter your password. Next, switch the root user by typing sudo su then entering your password again.

Now we want to create a file by typing touch script1.sh

Next we need to make the script executable by running the following command chmod +x script1.sh

Next we want to open a text editor by typing nano script1.sh and pasting all of the contents from here into the window (to paste, use Ctrl+Ins).

Variables

image

Now we need to change some things in the script. You will need to type values into these lines to tell the script some specific details about your setup. Each variables is described below.

  • TRUENAS_IP - This is the IP of TrueNAS (or any machine) you want to mount as an NFS share. Enter the IP in the format 192.168.1.10. If you don't want to mount this machine to TrueNAS, leave this section blank.
  • POOL_NAME - This is the name of the directory to mount into the server. The format is /directory. For example, if you named your TrueNAS pool "tank", the entry would be /tank. If you don't want to mount this machine to TrueNAS, leave this section blank.
  • DISCORD_WEBHOOK - To allow all of the apps to talk to you (assuming you have discord setup [which is outside the scope of this guide]) enter your discord webhook here and it will be added to unpackerr, radarr, sonarr, and prowlarr. If you don't have this, just leave it blank. You will see errors when the script runs if its blank, but its no big deal. Everything will still be setup correctly sans webhooks.
  • wireguard_conf - You need a VPN to deploy qBit. This setup is for one which uses wireguard. Download the conf file from your VPN provider and copy the lines for PrivateKey, Address, PublicKey, and Endpoint into the file. Leave everything else alone. Do not copy any IPv6 info into the file or any other lines from your conf file.

To save your changes and exit, type Ctrl+X, then y, then Enter.

Running the Script

To run the script, enter ./script1.sh

If you get a window like this, put a star in all the brackets by hitting the spacebar then click OK to move on:

image

Done!

You still have to setup Emby and Jellyseerr, but those aren't hard since all the paths and API keys are setup.

In Emby, when it asks for the paths for your movie and tv folders, they are simply /media/movies and /media/tv. In Jellyseerr, the server address for radarr is "radarr" and "sonarr" for sonarr. Do not change the ports. The API keys are listed at end of the script output for your convenience.

Bugs

This script isn't perfect. As of now, these are the current bugs:

  • in Prowlarr, the discord webhook isn't being added properly.
  • in Sonarr/Radarr set the Media Management > File Management > Propers and Repacks to Do Not Prefer (make sure you are showing the advanced options).
  • I consider the fact that I am not smart enough to automate the Emby and Jellyseerr install a bug

If you find anything I haven't listed, please open up an Issue.