Complete walkthrough for sharing a Plex media server between Windows and Raspberry Pi

It took many days of research to put this all together, so I thought I would consolidate it all in one post. Everything you need to share your Plex database between Windows and Raspberry Pi is right here. I am not a Raspberry Pi expert, nor do you need to be.

Why? I take mine camping. Yea, roughing it, I know. .

I back my Windows Server up to an 8 TB External USB Drive.
I keep all TV shows on D:\ root (it’s ok if your drive is different) but backup the whole folder to USB
I keep all Movies on F:\ root (it’s ok if your drive is different) but backup the whole folder to USB
If you don’t keep your media in the root, then you will need to adjust the paths as necessary when you edit the database.
Copy folder ‘%LOCALAPPDATA%\Plex Media Server’ to the USB root folder ‘Plex Media Server’. This will contain all of your Metadata, databases, and organization of your media. Make sure it’s still in folder ‘Plex Media Server’ on the USB drive.

Now you must edit the database on USB drive to change the Windows paths to Linux (Raspberry) paths.
Use any editor for SQLite, I personally use ‘DB Browser for SQLite’, but there are others. Open database on USB drive \Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db

Perform the following edits:
My %LOCALAPPDATA% is C:/Users/Administrator/AppData/Local/, if yours is different, adjust as necessary. My media sources were D:\ and F:\, yours are likely different, so adjust as needed. Again, if you don’t have media at the root folder, you will need to tweak this.

** Linux uses / windows uses \
UPDATE media_parts SET file = REPLACE(file, ‘\’, ‘/’);

Now, going forward, everything in media_parts table, will have ‘/’, where it was ‘\’ on Windows

** Repoint the meta data to where it will be on Raspberry
UPDATE media_parts SET file = REPLACE(file, ‘C:/Users/Administrator/AppData/Local/’, ’/media/PlexMedia/’) WHERE file LIKE (‘C:/Users/Administrator/AppData/Local/’, ’/media/PlexMedia/%’);;

** Update source locations, you might have drives other than D or F, just do this for each one
UPDATE media_parts SET file = REPLACE(file, ‘D:/’, ’/media/PlexMedia/’) WHERE file LIKE (‘D:/%’);
UPDATE media_parts SET file = REPLACE(file, ‘F:/’, ’/media/PlexMedia/’) WHERE file LIKE (‘F:/%’);

** Update your Plex directory structure, again, you might have other than D or F, just adjust to what you use.
UPDATE section_locations SET root_path = REPLACE(root_path, ‘F:’, ’/media/PlexMedia/’) WHERE root_path LIKE (‘F:%’);
UPDATE section_locations SET root_path = REPLACE(root_path, ‘D:’, ’/media/PlexMedia/’) WHERE root_path LIKE (‘D:%’);

Now, let’s build our Pi. I used this: ‘V-Kits Raspberry Pi 3 Model B+ (Plus) Complete Starter Kit with Official Black Case’ from Amazon.

  1. On PC: Download Raspbian https://downloads.raspberrypi.org/NOOBS_latest unzip and copy all files to SD card.
  2. Put card in Raspberry and boot, select language/keyboard, then install Raspbian (the first option). This will take about 20 minutes, connect it to Wifi, and put in a root password.
  3. Click the black icon in the application bar, to go to terminal mode.
  4. Get Plex: sudo wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key | sudo apt-key add -
  5. Add Plex to pkg list: echo ‘deb https://dev2day.de/pms/ jessie main’ | sudo tee /etc/apt/sources.list.d/pms.list
  6. Apply updates: sudo apt-get update
  7. Install Plex: sudo apt-get install -t jessie plexmediaserver
  8. Edit Plex config: sudo nano /etc/default/plexmediaserver.prev
  9. Replace Plex user: find PLEX_MEDIA_SERVER_USER=plex change user to pi (CTRL-X to save, then ‘y’ to confirm)
  10. Install NTFS reader (your USB drive is file format NTFS): sudo apt-get install ntfs-3g
  11. Reboot Raspbian: sudo reboot
  12. Browse to Plex: 127.0.0.1:32400/web and log in. Bookmark ‘127.0.0.1:32400/web’
  13. Set Raspberry Pi Plex server as default, it is likely defaulting to your windows server (left hand menu)
  14. Enable Plex offline mode (then you can run without internet): Go to Settings/Server click Show Advanced click Networks, go to ‘List of IP addresses and networks that are allowed without auth’. Put in 127.0.0.1
  15. Plug in USB drive, wait for Raspbian to recognize it, may take 15 to 20 seconds
  16. Go back to terminal mode, find your USB device: sudo df (mine was /dev/sda2)
  17. Edit daemon config to auto mount this device: sudo nano /etc/fstab
  18. Put new mounted device at bottom of file: /dev/sda2 /media/PlexMedia ntfs defaults 0 0 Make sure you put in your device from #16, not mine.
  19. Create Plex Media subfolder: sudo mkdir /media/PlexMedia
  20. Set permissions: sudo chmod 555 /media/PlexMedia (turn off writes)
  21. Reboot Raspbian: sudo reboot
  22. Go back to terminal mode, stop plex: sudo service plexmediaserver stop
  23. CD to plex database: cd ‘/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases’
  24. Delete the default database files: sudo rm com.plexapp.plugins.library.db*
  25. Copy database you edited from USB backup: sudo cp ‘/media/PlexMedia/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db’ com.plexapp.plugins.library.db
  26. Set database as read/write: sudo chmod 777 com.plexapp.plugins.library.db
  27. Go to Plex media folder: cd ‘/var/lib/plexmediaserver/Library/Application Support/Plex Media Server’
  28. Delete default Cache we are linking in ours from USB: sudo rm -r Cache
  29. Delete default Media we are linking in ours: from USB sudo rm -r Media (might not exists)
  30. Delete default Metadata we are linking in ours from USB: sudo rm -r Metadata (might not exists)
  31. Link in Cache from usb drive: sudo ln -s '/media/PlexMedia/Plex Media Server/Cache’ '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache’
  32. Link in Media from usb drive: sudo ln -s '/media/PlexMedia/Plex Media Server/Media’ '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Media’
  33. Link in Metadata from usb drive: sudo ln -s '/media/PlexMedia/Plex Media Server/Metadata’ '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata’
  34. Start Plex: sudo service plexmediaserver start
  35. Browse to plex: 127.0.0.1:32400/web it should work perfect
  36. Now, simulate no WiFi. Power wifi off: sudo iwconfig wlan0 txpower off
  37. Reboot Raspbian: sudo reboot (doing this just to simulate power up with no internet)
  38. Browse to plex: 127.0.0.1:32400/web it should work perfect with no internet !!!
  39. Turn wifi back on: sudo iwconfig wlan0 txpower auto (due to Raspbian bug, this might need to be done twice)
  40. Power down. Wait till you are sure it is off. Eject the SD card. NEVER eject SD card while powered on.
  41. Backup SD card from your PC. I use Win32DiskImager, but use whatever you want. Just make sure you do not modify the SD card from your PC, or you may well corrupt it.

My source references:
https://thepi.io/how-to-set-up-a-raspberry-pi-plex-server/

New Install of Linux Mint 17 and PMS

Is it possible to move server metadata to another location?

Sync Plex Database between Windows Windows and Raspberry Pi

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.