Ensure our operating system is entirely up to date:
sudo apt-get update
sudo apt-get upgradeInstall the package apt-transport-https that allows the apt package manager to retrieve packages over https protocol that the Plex repository uses:
sudo apt-get install apt-transport-httpsAdd the Plex repositories to the apt package managers key list:
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -Add the official plex repository to the sources list:
echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.listRefresh the package list:
sudo apt-get updateInstall the Plex Media Server:
sudo apt-get install plexmediaserverNOTE: In my case Plex worked perfectly configured with its default user.
By default, the Plex Media Server package will utilize a user named plex. To reduce the chances of dealing with permission issues, we could change the server’s default file:
sudo nano /etc/default/plexmediaserverchange the PLEX_MEDIA_SERVER_USER line from plex to pi:
export PLEX_MEDIA_SERVER_USER=piRestart the plexmediaserver service:
sudo systemctl restart plexmediaserverWe should make sure the Pi has a static IP, so it’s easy to remember the IP address. To get your current IP address, enter the following command:
hostname -IOpen up thecmdline.txt file:
sudo nano /boot/cmdline.txtAt the bottom of this file, add the following line (Replacing “YOUR IP” with the IP you got from using hostname -I):
ip=YOUR IPRestart the Raspberry Pi:
sudo rebootIf you only have one external hard drive connected to the Pi, then it should be attached to /dev/sda1 – additional drives will use /dev/sdb1 and /dev/sdc1 etc.
Make a directory in which to mount the USB drive:
sudo mkdir /mnt/mediastorageMake pi the owner of the mounted drive and make its permissions read, write and execute for it:
sudo chown -R pi:pi /mnt/mediastorage
sudo chmod -R 775 /mnt/mediastorageSet all future permissions for the mount point to pi user and group:
sudo setfacl -Rdm g:pi:rwx /mnt/mediastorage
sudo setfacl -Rm g:pi:rwx /mnt/mediastoragesudo blkidYou will see something like this. Again it is the sda1 line we are interested in (In this case we are working with only one external hard drive). We need to take note in the attribute TYPE (NTFS for me) because we will need it to configure the fstab file.
/dev/mmcblk0p1: LABEL="boot" UUID="27D9-A951" TYPE="vfat" PARTUUID="d95dc960-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="db9fbdec-9f10-4008-95da-5062491e0659" TYPE="ext4" PARTUUID="d95dc960-02"
/dev/mmcblk0: PTUUID="d95dc960" PTTYPE="dos"
/dev/sda1: LABEL="Elements" UUID="328C83488C830597" TYPE="ntfs" PARTLABEL="Elements" PARTUUID="0f291c06-b24b-47f3-815d-fe34d120459d"If the hard drive is NTFS we will need to install some utilities first:
sudo apt-get install ntfs-3g -yIf the drive is exfat install these utilities:
sudo apt-get install exfat-utils -yFor all drive types mount the hard drive with this command, -o insures pi is the owner which should avoid permission issues:
sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/mediastorageIf you get an error use this syntax:
sudo mount -t uid=pi,gid=pi /dev/sda1 /mnt/mediastorageIf the mount -t command returns an error then use this syntax:
sudo mount uid=pi,gid=pi /dev/sda1 /mnt/mediastorageIf you are getting this drive is already mounted errors then you are probably using a distro which automounts the drives. Unmount the hard drive with the next command before to mount it again to the right mount point (/mnt/mediastorage) with one of the previous commands:
sudo umount /dev/sda1/mnt/mediastorage will be the folder in which you store your media. We want it to be automounted on boot The best way to do this is through the UUID. Get the UUID by using this commmand:
sudo ls -l /dev/disk/by-uuid/You will see some output like this. The UUID you want is formatted like this XXXX-XXXX for the sda1 drive. If the drive is NTFS it can have a longer format like UUID="328C83488C830597".
total 0
lrwxrwxrwx 1 root root 15 Sep 10 10:17 27D9-A951 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 Sep 10 11:02 328C83488C830597 -> ../../sda1
lrwxrwxrwx 1 root root 15 Sep 10 10:17 db9fbdec-9f10-4008-95da-5062491e0659 -> ../../mmcblk0p2Now we will edit fstab to mount the USB by UUID on boot:
sudo nano /etc/fstabAdd the next line to the bottom, replace XXXX-XXXX with your UUID and TYPE with the correct type (e.g. ntfs, exfat, vfat, ext4). You may or may not need the quotation marks wrapped around the UID, you do not need quotation marks wrapped around the file system type (ext4, vfat, NTFS etc):
UUID=XXXX-XXXX /mnt/mediastorage TYPE nofail,uid=pi,gid=pi 0 0The umask 0002 sets 775 permissions so the pi user and group can read, write and execute files on the external USB drive. To completely eliminate permission issues you can set the umask to 0000 which equals 777 permissions so anybody can read, write and execute. Note that 777 permissions are considered a security risk.
If you have issues here then try replacing uid=pi,gid=pi with just the word defaults (typical for ext4). You can also try replacing the UUID with the /dev/sda1 line.
In my case, for NTFS:
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1
UUID=328C83488C830597 /mnt/mediastorage ntfs nofail,uid=pi,gid=pi 0 0If you get any errors you can replace uid=pi,gid=pi with defaults or remove it entirely:
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1
UUID=328C83488C830597 /mnt/mediastorage ntfs nofail,defaults 0 0For using /dev/sda1 and defaults if you have troubles with UUID
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1
/dev/sda1 /mnt/mediastorage ntfs nofail 0 0Now test the fstab file works:
sudo mount -aIf you didn’t get errors then reboot, otherwise try the suggestions above to get it working then mount -a again until it succeeds
sudo rebootYou should be able to access the mounted USB drive and list its contents
cd /mnt/mediastorage
lsEvery time you reboot, the drives will be mounted as long as the UUID remains the same. If you delete the partitions or format the USB hard drive or stick the UUID changes so bear this in mind. You can always repeat the process for additional hard drives in the future.
If you have multiple hard drives you will have to make separate mount points (e.g. /mnt/mediastorage2) for each drive’s partition.
To connect to the browser, enter the IP followed by the port 32400 and /web/. For example, in my case:
192.168.1.95:32400/web/You will be prompted to log in, simply sign up or sign in to an existing plex account. Next, you will need to set up your music, movie, and TV show libraries:
- First select add library in the left-hand side column.
- Next, select the type of media that is in the folder. If you have more than one type, then you will need to add a new library for each type of media.
- Next, you will need to select the folder that has all your media in it. For example, mine is on /mnt/mediastorage/Media.
- Once added the library, Plex will now organize the files on its interface.
- Go to %LOCALAPPDATA%\Plex Media Server on Windows.
- Backup the folders: Media, Metadata, Plug-in Support, Plugins. These folders contain the data and the media images for the library.
- Configure Plex on Linux via the web interface. At this point you’ll have an empty library.
- Shutdown Plex on Linux:
sudo systemctl stop plexmediaserver- Copy the backed up media files to Linux:
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/- Fix permissions in the copied folders (Repeat this step with the folders: Metadata, Plug-in Support and Plugins):
sudo chown -R plex:plex /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Media
sudo chmod -R 755 /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Media- Start Plex:
sudo systemctl start plexmediaserver- Open Plex web interface and change the Library paths to new paths. This will trigger a rescan of the files.
- After complete, re fresh the plex website.
sudo apt-get purge plexmediaserverWhat it does:
- Uninstall the package
- Removes the user plex
- Deletes its home directory /var/lib/plexmediaserver
If you’re uncertain and/or want to be certain about user plex and its data (home directory):
sudo userdel plex
sudo rm -rf /var/lib/plexmediaserver