What's new

Tutorial Debian 12 Bookworm + Plex Media Server (Asus RT-AX86S)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

bbeny123

New Around Here
I was recently installing Plex media server on my router and as the existing sources are outdated and/or unavailable I had to fiddle around a bit to get it to work.
Here's a little tutorial on how to do it.

Based on:
Tested on: Asus RT-AX86S with Asuswrt-Merlin 3004.388.4 beta1

Prerequisites:

  • installed Entware
  • SWAP enabled (2GB or more recommended)
* steps are optional.

1 -
ssh to router

* - increase swappiness if it is 0 (in my case, it significantly improved the performance of the Plex Media Server)

Bash:
# check current value of swappiness
cat /proc/sys/vm/swappiness

# change swappiness on runtime and persists it after reboot
echo 10 > /proc/sys/vm/swappiness
echo 'echo 10 > /proc/sys/vm/swappiness' >> /jffs/scripts/post-mount

2 - install required packages

Bash:
opkg install coreutils-sha256sum debootstrap binutils perlbase-autodie

3 - remount Entware partition

Bash:
mount -i -o remount,exec,dev /opt/..

4 - install chrooted Debian

Bash:
debootstrap --variant=minbase --arch=arm64 bookworm /opt/debian/ http://ftp.debian.org/debian/

5 - prepare Debian's init.d script

Bash:
rm /opt/etc/init.d/S99debian
wget -O /opt/etc/init.d/S99debian https://raw.githubusercontent.com/bbeny123/Plex_Asuswrt-Merlin/main/init-debian.sh
chmod 755 /opt/etc/init.d/S99debian
# instead of downloading the script, it can also be copy-pasted:
# cat >> /opt/etc/init.d/S99debian << 'EOF'
# copy-paste script from the spoiler below
# type 'EOF' and press enter

By default, all subdirs of /tmp/mnt/ (except the Entware partition) will be bind-mounted on chrooted Debian's /mnt/ (making them visible by Plex Media Server).​

Bash:
#!/bin/sh

PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin

CHROOT_DIR=$(readlink -f /opt/debian)
CHROOT_SERVICES_LIST=/opt/etc/chroot-services.list

if [ ! -e "$CHROOT_SERVICES_LIST" ]; then
  echo "Please, define Debian services to start in $CHROOT_SERVICES_LIST first!"
  echo "One service per line. Hint: this is a script names from Debian's /etc/init.d/"
  exit 1
fi

running() {
  if [ $(mount | grep $CHROOT_DIR | wc -l) -gt 0 ]; then
    return 0
  fi

  return 1
}

mount_int() {
  mkdir -p $CHROOT_DIR/opt/tmp

  for dir in dev proc sys opt/tmp; do
    if ! mountpoint -q $CHROOT_DIR/$dir; then
      mount -o bind /$dir $CHROOT_DIR/$dir
    fi
  done
}

mount_ext() {
  for dir in /mnt/*; do
    dir=$(readlink -f $dir)/
    if ! echo "$CHROOT_DIR" | grep -q ^$dir; then
      target_dir=$CHROOT_DIR/mnt/$(echo "$dir" | sed 's!^.*mnt/!!')
      mkdir -p $target_dir
      if ! mountpoint -q $target_dir; then
        mount -o bind $dir $target_dir
      fi
    fi
  done
}

start() {  
  if running; then
    echo "Chroot'ed services seems to be already started, exiting..."
    exit 1
  fi
  
  mount_int
  mount_ext

  echo "Starting chroot'ed Debian services..."

  for item in $(cat $CHROOT_SERVICES_LIST); do
    chroot $CHROOT_DIR /etc/init.d/$item start
  done
}

stop() {
  if ! running; then
    echo "Chroot'ed services seems to be already stopped, exiting..."
    exit 1
  fi

  echo "Stopping chroot'ed Debian services..."

  for item in $(cat $CHROOT_SERVICES_LIST); do
    chroot $CHROOT_DIR /etc/init.d/$item stop
    sleep 2
  done

  if mountpoint -q $CHROOT_DIR/dev/pts; then
    umount $CHROOT_DIR/dev/pts
  fi

  mount | grep $CHROOT_DIR | awk '{print $3}' | xargs umount -l
}

restart() {
  stop
  start
}

enter() {
  if ! running; then
    start
  fi

  if ! mountpoint -q $CHROOT_DIR/dev/pts; then
    mount -o bind /dev/pts $CHROOT_DIR/dev/pts
  fi

  chroot $CHROOT_DIR /bin/bash

  if mountpoint -q $CHROOT_DIR/dev/pts; then
    umount $CHROOT_DIR/dev/pts
  fi
}

status() {
  if running; then
    echo "Chroot'ed services running..."
  else
    echo "Chroot'ed services not running!"
  fi
}

case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
restart)
  restart
  ;;
enter)
  enter
  ;;
status)
  status
  ;;
*)
  echo "Usage: (start|stop|restart|enter|status)"
  exit 1
  ;;
esac

echo Done.
exit 0

* - prepare Debian's remount hotplugged USB script

Skipping this step, newly attached USB drives will be accessible from Debian (and thus Plex Media Server) only after rebooting the router or manually executing debian restart / debian enter via SSH.​

Prerequisite: JFFS custom scripts and configs enabled (router WebUI -> Administration -> System)​

Bash:
wget -O /jffs/scripts/mount-debian.sh https://raw.githubusercontent.com/bbeny123/Plex_Asuswrt-Merlin/main/mount-debian.sh
chmod 755 /jffs/scripts/mount-debian.sh
echo './jffs/scripts/mount-debian.sh' >> /jffs/scripts/post-mount
# instead of downloading the script, it can also be copy-pasted:
# cat >> /jffs/scripts/mount-debian.sh << 'EOF'
# copy-paste script from the spoiler below
# type 'EOF' and press enter

Bash:
#!/bin/sh

CHROOT_DIR=$(readlink -f /opt/debian)

if [ $(mount | grep $CHROOT_DIR | wc -l) -gt 0 ]; then
  for dir in /mnt/*; do
    dir=$(readlink -f $dir)/
    if ! echo "$CHROOT_DIR" | grep -q ^$dir; then
      target_dir=$CHROOT_DIR/mnt/$(echo "$dir" | sed 's!^.*mnt/!!')
      mkdir -p $target_dir
      if ! mountpoint -q $target_dir; then
        mount -o bind $dir $target_dir
      fi
    fi
  done
fi

6 - prepare chrooted services list and create symlink to Debian

Bash:
touch /opt/etc/chroot-services.list
chmod 755 /opt/etc/chroot-services.list
ln -s /opt/etc/init.d/S99debian /opt/bin/debian

* - copy hosts file to Debian

Bash:
cp /etc/hosts /opt/debian/etc/

7 - enter debian

Bash:
debian enter

8 - upgrade packages and install those required by Plex Media Server

Bash:
apt update && apt upgrade -y
apt install -y apt-transport-https curl gnupg procps

9 - configure timezone

Bash:
dpkg-reconfigure tzdata

10 - instal Plex Media Server

Bash:
curl -sS https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/plexmediaserver.gpg
echo 'deb https://downloads.plex.tv/repo/deb public main' | tee /etc/apt/sources.list.d/plexmediaserver.list
apt update
apt install plexmediaserver

After installation, the server will start automatically.​
During initialization (which will take about 5-15min) CPU/RAM usage will be close to 100%.​
The server will be almost unusable during this time so I recommend just waiting it out.​

11 - exit Debian

Bash:
exit

12 - add Plex Media Server to chrooted services list

Bash:
echo 'plexmediaserver' >> /opt/etc/chroot-services.list

13 - restart Debian

Bash:
debian restart


After about 30 seconds, the server should be reachable at: <router-ip-address>:32400/web like 192.168.1.1:32400/web or router.asus.com:32400/web

When configuring libraries, CPU/RAM consumption will also be close to 100%. Web-panel and Debian will be unresponsive during this time.
After configuring the libraries and downloading the metadata, the Plex Media Server should start working well.
I have done some tests and the playback of videos with a bitrate of almost 80Mb/s was seamless and smooth.
 
Last edited:
Thank you very much! This is an excellent guide which currently works to the letter! I've just installed Plex on my RT-AX86U router.

And a bit of info for Olndo Pindaro - when I stream 1080p file into Firefox browser, router CPU usage is around 40% across all cores, but when I stream it to Apple TV (3rd gen), CPU is around 10%, so this is not taxing at all!
 
A few years ago I had a PLEX on AC86U, there were no problems. The content must be viewed through applications (Plex application for Windows, Plex applications for Android, etc.). When you open it through the browser, the load falls on the router and it may not cope.
 
Hi ,

I got to step 8 but I'm getting the below error , can someone help please ?

Code:
root@RT-AC86U-5660:/# apt update && apt upgrade -y
Hit:1 http://ftp.debian.org/debian bookworm InRelease
Get:2 https://downloads.plex.tv/repo/deb public InRelease [6685 B]
Err:2 https://downloads.plex.tv/repo/deb public InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
Reading package lists... Done
W: GPG error: https://downloads.plex.tv/repo/deb public InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
E: The repository 'https://downloads.plex.tv/repo/deb public InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
 
Last edited:
Hi ,

I got to step 8 but I'm getting the below error , can someone help please ?

Code:
root@RT-AC86U-5660:/# apt update && apt upgrade -y
Hit:1 http://ftp.debian.org/debian bookworm InRelease
Get:2 https://downloads.plex.tv/repo/deb public InRelease [6685 B]
Err:2 https://downloads.plex.tv/repo/deb public InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
Reading package lists... Done
W: GPG error: https://downloads.plex.tv/repo/deb public InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
E: The repository 'https://downloads.plex.tv/repo/deb public InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Repeat step 8, especially for gnupg.
 
Repeat step 8, especially for gnupg.
I've run the below again but it still fails on the apt update && apt upgrade -y part

apt install -y apt-transport-https curl gnupg procps


Code:
Hit:1 http://ftp.debian.org/debian bookworm InRelease
Get:2 https://downloads.plex.tv/repo/deb public InRelease [6685 B]
Err:2 https://downloads.plex.tv/repo/deb public InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
Reading package lists... Done
W: GPG error: https://downloads.plex.tv/repo/deb public InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
E: The repository 'https://downloads.plex.tv/repo/deb public InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
 
I've run the below again but it still fails on the apt update && apt upgrade -y part

apt install -y apt-transport-https curl gnupg procps


Code:
Hit:1 http://ftp.debian.org/debian bookworm InRelease
Get:2 https://downloads.plex.tv/repo/deb public InRelease [6685 B]
Err:2 https://downloads.plex.tv/repo/deb public InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
Reading package lists... Done
W: GPG error: https://downloads.plex.tv/repo/deb public InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 97203C7B3ADCA79D
E: The repository 'https://downloads.plex.tv/repo/deb public InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

Code:
rm /etc/apt/sources.list.d/plexmediaserver.list
Then start again at step 8.
 
Hi , one more question : what should be the correct Library folder path to add to Plex ?
I've tried the below 2x options but nothing comes up after the scan is done.
Code:
192.168.1.1/Torrent/Completed
root/mnt/media/Torrent/Completed
 
I highly doubt that first trial would succeed since there would be no such directory in the filesystem. (MS, being different as is their wont, calls directories "folders" for some reason - inconsistently so, for if in a terminal you want to change directories, you'd issue the "cd" command [_c_hange _d_irectory - wait, was it "chdir"?] and most definitely not "cf", which would stand for "change folder" ...), and the second example is wrong if for no other reason than it's a relative instead of absolute pathway declaration - could mean anything or nothing whatsoever.

If the second were /root/mnt/media/Torrent/Completed (leading /) it might succeed if there exists a /root directory; oh hell, too much to explain - it's got to be plumb wrong as well, no ifs ands or buts. Where did you encounter such declarations as possibilities?
 
I highly doubt that first trial would succeed since there would be no such directory in the filesystem. (MS, being different as is their wont, calls directories "folders" for some reason - inconsistently so, for if in a terminal you want to change directories, you'd issue the "cd" command [_c_hange _d_irectory - wait, was it "chdir"?] and most definitely not "cf", which would stand for "change folder" ...), and the second example is wrong if for no other reason than it's a relative instead of absolute pathway declaration - could mean anything or nothing whatsoever.

If the second were /root/mnt/media/Torrent/Completed (leading /) it might succeed if there exists a /root directory; oh hell, too much to explain - it's got to be plumb wrong as well, no ifs ands or buts. Where did you encounter such declarations as possibilities?
I have managed to get it working properly , thank you for your time. I was trying to mount the media drive to be able to use it in Plex.
 
I have managed to get it working properly , thank you for your time. I was trying to mount the media drive to be able to use it in Plex.
What did you end up doing to get it working?
 
Last edited:
What did you end up doing to get it working?
Had another look at the steps and noticed that they actually cover the exact steps to mount the drive, which I was trying to accomplish.
And the drive was available to select when adding the Plex Library.
Screenshot 2023-10-29 at 19.39.25.png


Code:
sed -i 's!##EXT_DIR##!EXT_DIR=/tmp/mnt/media-hdd/movies/!' /opt/etc/init.d/S99debian # replace '/tmp/mnt/media-hdd/movies/' with the path to dir that should be mounted to Debian's /mnt
 
Step 10, when I write 'apt install plexmediaserver ', it seems to occur configuration error.

After installation, 'service plexmediaserver start' also doesn't work.

Are there someone who can help me?

I emphasize command lines and error messages.

Code:
root@RT-AX88U-7E70: /# apt install plexmediaserver
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: plexmediaserver o upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 70.4 MB of archives. After this operation, 160 MB of additional disk space will be used. Get:1 https://downloads.plex.tv/repo/deb public/main armhf plexmediaserver armhf 1.32.6.7557-1cf77d501 [70.4 MB] Fetched 70.4 MB in 7s (10.2 MB/s) Selecting previously unselected package plexmediaserver. (Reading database ... 18037 files and directories currently installed.) Preparing to unpack .../plexmediaserver_1.32.6.7557-1cf77d501_armhf.deb ... PlexMediaServer install: Pre-installation Validation. PlexMediaServer install: Pre-installation Validation complete. Unpacking plexmediaserver (1.32.6.7557-1cf77d501) ... Setting up plexmediaserver (1.32.6.7557-1cf77d501)
grep: /proc/1/cgroup: No such file or directory
PlexMediaServer install: PlexMediaServer-1.32.6.7557-1cf77d501 - Installation starting. PlexMediaServer install: PlexMediaServer install: Now installing based on: PlexMediaServer install: Installation Type: New PlexMediaServer install: Process Control: Plex User: PlexMediaServer install: PlexMediaServer install: Plex Group: PlexMediaServer install: Video Group: PlexMediaServer install: Metadata Dir: PlexMediaServer install: Temp Directory: PlexMediaServer install: Lang Encoding: PlexMediaServer install: Processor: PlexMediaServer install: Intel 1915 Hardware: Not found PlexMediaServer install: Nvidia GPU card: Not Found PlexMediaServer install: PlexMediaServer install: Completing final configuration.
configuration error - unknown item 'NONEXISTENT' (notify administrator)
configuration error - unknown item 'PREVENT_NO_AUTH' (notify administrator)
configuration error - unknown item 'NONEXISTENT' (notify administrator)
configuration error - unknown item 'PREVENT_NO_AUTH' (notify administrator)
Running in chroot, ignoring request. #########..
Running in chroot, ignoring request.
Running in chroot, ignoring command 'daemon-reload'

Running in chroot, ignoring command 'start'
PlexMediaServer install: PlexMediaServer-1.32.6.7557-1cf77d501 - Installation successful. Errors: 0, Warnings: 0 Processing triggers for mailcap (3.70+nmu1)
root@RT-AX88U-7E70: /# service plexmediaserver start
plexmediaserver: unrecognized service
root@RT-AX88U-7E70:/#
 
Last edited:
Thx a lot :)

It works well.

However when i use 'debian restart', I get umount error.

How can I solve it?


RT-AX88U-7E70:/tmp/mnt/sdb1/entware/etc# debian restart Stopping chroot'ed Debian services... Shutting down Plex Media Server: Stopping bittorrent daemon: transmission-daemon.
umount: /tmp/mnt/sdb1/entware/debian/dev/pts: not mounted.
Restarting chroot'ed Debian services... Starting Plex Media Server. Starting bittorrent daemon: transmission-daemon. Done.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top