Move Plex Media Server to Linux VM

Submitted by nigel on Sunday 18th February 2018

I've been playing with Plex Media Server for the last few weeks on my Linux laptop, and much to my surprise it seems to play back any video format I throw at it including DivX and XviD which is the format of a great many of my collection of movies. So buoyed by this I have decided to move the entire Plex configuration to a dedicated Ubuntu virtual machine which will reside on my Intel NUC I reviewed earlier

My Intel NUC is headless, and whilst it is possible to create a VM image on the command line, it is much more convenient to create it on a GUI elsewhere and move it over to the NUC. To that end, I created the VM on my Mac knowing the network configuration would ultimately have to change when the VM is in situ on the NUC.

VM Installation
Name of Operating System
Memory Requirements
Virtual Disk
Fixed Size
10 GB

The steps are quite straightforward so there isn't much need for narrative. I had previously downloaded the Ubuntu 16.04 LTS server iso image (more of that in a minute).

I decided to go for 4GB RAM and 10GB fixed disk size which should be more than adequate. 

Initial Network Connection
Bridged network connection

The initial network connection is set as above. We need a bridged network so I can use my pre-existing 192.168 network in my property. Obviously when the VM is moved to the Intel NIC the AirPort won't be a valid setting at that point - so we'll have to change it then. 

Ubuntu 16.04 Installation
Select Ubuntu Image
Installation screen
openssh server

As mentioned previously, I had already downloaded the Ubuntu 16.04 LTS iso image which is selected for the installation above. Most of the installation screens haven't been captured for brevity because they are straightforward, but note I have selected openSSH server in the software packages to install - this is important since we will need to ssh into our headless Plex server. 

We now need to edit the /etc/network/interfaces file to change the default DHCP IP assignment to static. Your configuration will obviously be different from mine here. I've elected to go for the address of for my server. 

nigel@plex-media-server:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
# iface enp0s3 inet dhcp
iface enp0s3 inet static
Export the VM

I have already covered how to export a VM image in a previous blog here, so I don't need to go into too much detail in this blog. My VM has been exported and now needs to be copied to the NUC host machine using scp. 

Nigels-MacBook-Pro:Documents nigel$ scp Plex\ Media\ Server.ova nigel@
nigel@'s password: 
Plex Media Server.ova                                                                        100%  604MB   4.1MB/s   02:27    
Nigels-MacBook-Pro:Documents nigel$
Now log into the host machine and cd into the correct directory and import the VM.
nigel@devbox:~/VM$ VBoxManage import Plex\ Media\ Server.ova 
Interpreting /home/nigel/VM/Plex Media Server.ova...
  vmdisk1       10737418240     -1       Plex Media Server-disk001.vmdk  -1      -1
Virtual system 0:
 0: Suggested OS type: "Ubuntu_64"
    (change with "--vsys 0 --ostype <type>"; use "list ostypes" to list all possible values)
 1: Suggested VM name "Plex Media Server"
    (change with "--vsys 0 --vmname <name>")
 2: Number of CPUs: 1
    (change with "--vsys 0 --cpus <n>")
 3: Guest memory: 4096 MB
    (change with "--vsys 0 --memory <MB>")
 4: Sound card (appliance expects "", can change on import)
    (disable with "--vsys 0 --unit 4 --ignore")
 5: USB controller
    (disable with "--vsys 0 --unit 5 --ignore")
 6: Network adapter: orig Bridged, config 3, extra slot=0;type=Bridged
 7: CD-ROM
    (disable with "--vsys 0 --unit 7 --ignore")
 8: IDE controller, type PIIX4
    (disable with "--vsys 0 --unit 8 --ignore")
 9: IDE controller, type PIIX4
    (disable with "--vsys 0 --unit 9 --ignore")
10: SATA controller, type AHCI
    (disable with "--vsys 0 --unit 10 --ignore")
11: Hard disk image: source image=Plex Media Server-disk001.vmdk, target path=/home/nigel/VirtualBox VMs/Plex Media Server/Plex Media Server-disk001.vmdk, controller=10;channel=0
    (change target path with "--vsys 0 --unit 11 --disk path";
    disable with "--vsys 0 --unit 11 --ignore")
Successfully imported the appliance.
Now we need to modify the ethernet card settings and the audio as per my previous blog
$ VBoxManage modifyvm "Plex Media Server" --nic1 bridged --bridgeadapter1 enp3s0
$ VBoxManage modifyvm "Plex Media Server" --audio none
Ok now we need to be sure we are in the correct directory and start up our machine. Once this has been done, it will be possible to ssh into it.
$ pwd
/home/nigel/VirtualBox VMs
$ VBoxHeadless --startvm "Plex Media Server" &
Let's try to log into
nigel@nigel-Aspire-VN7-793G:/etc$ ssh nigel@
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is SHA256:BLRRmyijEFgtS+KnkXQUudkdsMskpLrzR19zBugQ2ww.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (ECDSA) to the list of known hosts.
nigel@'s password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)
 * Documentation:
 * Management:
 * Support:
127 packages can be updated.
64 updates are security updates.
Last login: Sun Feb 18 19:58:43 2018 from
fstab entry to connect to CIFS partition
My FreeNAS server has a CIFS mount point which contains my media collection. It would therefore be useful for the drive to be automatically loaded on boot. A prerequisite for this is the cifs-utils package which will need to be installed.
$ sudo apt-get install cifs.utils
Next we need to create the mount point directory which will be /mnt/freenas
$ sudo mkdir /mnt/freenas
It would useful to check we can connect first on the command line. So lets type out the required mount command, but first we need to create a credentials file for FreeNAS. This will be owned by the root user and should be placed in the root user's directory and made read only for root.
# cat .cifs 
# ls -las .cifs
4 -r-------- 1 root root 39 Feb 18 21:37 .cifs
Now the actual mount command and a follow up directory listing to make sure it has been mounted correctly.
$ sudo mount.cifs //  /mnt/freenas    -o vers=3.0,credentials=/root/.cifs,uid=1000
$ ls -las /mnt/freenas | grep Documents
     0 drwxr-xr-x 2 nigel root         0 Aug 14  2017 Documents
Now we need to unmount this and add the entry to the /etc/fstab file.
$ sudo umount /mnt/freenas
$ cat /etc/fstab
# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=600eb961-4caa-4a24-b8cf-c35efdd71ca4 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=523ed080-41af-4dab-839f-070f40c26ada none            swap    sw              0       0
# CIFS FreeNas mount
//        /mnt/freenas    cifs    credentials=/root/.cifs,uid=1000,vers=3.0       0      0
$ sudo mount -a
$ ls -las /mnt/freenas | grep Documents
     0 drwxr-xr-x 2 nigel root         0 Aug 14  2017 Documents
That's another job done! Finally we can think about moving the Plex configuration over to our new VM.
Commence the Plex Move from Source to Destination
Empty Trash

Firstly navigate to Settings->Server->library and disable the setting Empty trash automatically after every scan as shown above. Save this setting change.  

Stop the Plex Media Server running on the source machine. This is achieved on the command line with
$ sudo service plexmediaserver stop
[sudo] password for nigel: 
$ ps -ef | grep plex
nigel     6274  1647  0 09:51 pts/1    00:00:00 grep --color=auto plex
Note I double checked that there were no Plex services running just in case.
install Plex on Destination Machine
In my case my destination machine is a VM on my Intel NUC so let's see if the VM is currently running.
nigel@devbox:~$ VBoxManage list vms
"badzilla-d8" {86af2c61-3b68-47c5-a71e-8f45ac196cbe}
"Plex Media Server" {5efa7e7b-ae92-45a9-8244-bae451b53c0a}
nigel@devbox:~$ VBoxManage list runningvms
So the good news is it is there. The bad news is it isn't currently running. Let's spark it up.
nigel@devbox:~$ VBoxHeadless --startvm "Plex Media Server" &
Ok let's ssh into the VM so we can install the new copy of Plex
nigel@devbox:~$ ssh nigel@
The authenticity of host ' (' can't be established.                                  
ECDSA key fingerprint is SHA256:BLRRmyijEFgtS+KnkXQUudkdsMskpLrzR19zBugQ2ww.                                    
Are you sure you want to continue connecting (yes/no)? yes                                                      
Warning: Permanently added '' (ECDSA) to the list of known hosts.                                  
nigel@'s password:                                                                                 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)                                               
 * Documentation:                                                                      
 * Management:                                                              
 * Support:                                                                 
19 packages can be updated.
10 updates are security updates.
Last login: Sun Feb 18 22:11:59 2018 from
On a separate machine, download the latest Ubuntu 64 bit Plex Server, and scp it into the destination machine file system.
nigel@nigel-Aspire-VN7-793G:~/Downloads$ scp plexmediaserver_1.11.3.4803-c40bba82e_amd64.deb nigel@
nigel@'s password: 
plexmediaserver_1.11.3.4803-c40bba82e_amd64.deb                               100%  104MB 817.5KB/s   02:10    
Now switch back to the term window of the destination machine and install Plex.
nigel@plex-media-server:~$ sudo dpkg -i /tmp/plexmediaserver*.deb
[sudo] password for nigel: 
Selecting previously unselected package plexmediaserver.
(Reading database ... 93857 files and directories currently installed.)
Preparing to unpack .../plexmediaserver_1.11.3.4803-c40bba82e_amd64.deb ...
Unpacking plexmediaserver ( ...
Setting up plexmediaserver ( ...
Created symlink from /etc/systemd/system/ to /lib/systemd/system/plexmediaserver.service.
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
The installation process will invoke Plex so stop the service
nigel@plex-media-server:~$ sudo service plexmediaserver stop
Copy to Destination Machine
We now need to copy Plex from the source to the destination machine. The best method is to scp the entire Plex file structure from one machine to the other. The file structure is at /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/ and is owned by the user plex as you can see here:
nigel@nigel-Aspire-VN7-793G:/$ ls -las /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/
total 44                                                                                                        
4 drwxr-xr-x 10 plex plex 4096 Feb 24 09:51 .                                                                   
4 drwxr-xr-x  3 plex plex 4096 Jan 28 20:11 ..                                                                  
4 drwxr-xr-x  5 plex plex 4096 Feb 24 09:45 Cache                                                               
4 drwxr-xr-x  3 plex plex 4096 Jan 28 20:11 Codecs                                                              
4 drwxr-xr-x  3 plex plex 4096 Jan 28 20:11 Crash Reports                                                       
4 drwxr-xr-x  3 plex plex 4096 Feb 24 09:14 Logs                                                                
4 drwxr-xr-x  3 plex plex 4096 Jan 28 20:18 Media                                                               
4 drwxr-xr-x  6 plex plex 4096 Jan 30 21:44 Metadata                                                            
4 drwxr-xr-x  3 plex plex 4096 Feb 22 20:25 Plug-ins                                                            
4 drwxr-xr-x  7 plex plex 4096 Jan 28 20:11 Plug-in Support                                                     
4 -rw-------  1 plex plex 1002 Feb 24 09:45 Preferences.xml
So to get all the permissions and ownerships correct during the copy we should assign a password to the user plex so when we scp we can provide the prompted for password.
root@plex-media-server:/home/nigel# passwd plex 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Ok - so if we switch back to the source machine we need to execute the scp command like this:
nigel@nigel-Aspire-VN7-793G:/$ sudo -H -u plex scp -rp  /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/* plex@"/var/lib/plexmediaserver/Library/Application\\ Support/Plex\\ Media\\ Server/."
Note that I am running the scp as the plex user on my source machine through the superuser, and also note the double back-whacks and quotes on the destination directory structure.

Next we should start the Plex service on the destination machine and check it came up ok.
nigel@plex-media-server:~$ sudo service plexmediaserver start
nigel@plex-media-server:~$ ps -ef | grep plex
plex     17501     1  0 13:19 ?        00:00:00 /bin/sh -c LD_LIBRARY_PATH=/usr/lib/plexmediaserver "/usr/lib/plexmediaserver/Plex Media Server"
plex     17502 17501 22 13:19 ?        00:00:02 /usr/lib/plexmediaserver/Plex Media Server
plex     17517 17502 89 13:19 ?        00:00:07 Plex Plug-in [com.plexapp.system] /usr/lib/plexmediaserver/Resources/Plug-ins-c40bba82e/Framework.bundle/Contents/Resources/Versions/2/Python/ --server-version /usr/lib/plexmediaserver/Resources/Plug-ins-c40bba82e/System.bundle
nigel    17541  1453  0 13:19 pts/0    00:00:00 grep --color=auto plex
Web Browser Destination Access

You should now be able to point your browser to Plex's new home. You need to change the URL to include your IP address, which in my case is with a port of 32400. Yours should be similar but probably not identical. Check out the first image above for the entire URL although you won't need to include the index.html. 

You may have to log in again but mine went straight to the 'Recently Added' view as you can see in the second image above. So my media and my libraries have been found ok. This shouldn't be a surprise - don't forget earlier in the tutorial I connected the VM to my FreeNAS where the media is held - and the canonical path is exactly the same to the media on the VM (destination) as it is on my source machine (my laptop). 

Empty trash automatically
Enable empty trash

Now we know everything is working ok, we should re-enable the emptying of trash - see the screenshot above. 

Tidying up
A little housekeeping is required. We now have two systems using the same BadzillaPlex name - so let's remove it from my laptop. To do that issue:
$ sudo dpkg --remove plexmediaserver
[sudo] password for nigel: 
(Reading database ... 334962 files and directories currently installed.)
Removing plexmediaserver ( ...
Removed symlink /etc/systemd/system/
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
blog terms
Hardware Linux