bbeny123
New Around Here
Here's an up-to-date guide for installing Plex Media Server, since most existing tutorials are now obsolete.
GitHub Mirror: https://github.com/bbeny123/Plex_Asuswrt-Merlin
Tested on: Asus RT-AX86S with Asuswrt-Merlin 3004.388.9_2
Prerequisites:
* - increase swappiness (if set to 0)
2 - install required packages
3 - remount Entware partition
4 - install chrooted Debian
5 - set up Debian init.d script
* - set up hot-plugging of USB drives in Debian
* - set up Debian graceful shutdown on Entware partition unmount
6 - prepare chrooted services list and set up
* - copy hosts file to Debian
7 - enter Debian
8 - upgrade packages and install Plex prerequisites
9 - configure timezone
10 - ensure
11 - instal Plex Media Server
12 - exit Debian
13 - add Plex Media Server to chrooted services list
14 - restart Debian
1 - ssh to router
* - update amtm and Entware packages using
2 - enter Debian
3 - hold Plex and upgrade other Debian packages
4 - ensure
5 - unhold and upgrade Plex
* - restart Debian
GitHub Mirror: https://github.com/bbeny123/Plex_Asuswrt-Merlin
Tested on: Asus RT-AX86S with Asuswrt-Merlin 3004.388.9_2
Steps marked with an asterisk (*) are optional
Prerequisites:
- Entware installed
- SWAP enabled (2GB or more recommended)
* - increase swappiness (if set to 0)
Increasing swappiness can significantly improve Plex performance
Bash:
# check current swappiness value
cat /proc/sys/vm/swappiness
# change swappiness at runtime and make it persistent across reboots
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 - set up Debian 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 can be entered directly:
# cat >> /opt/etc/init.d/S99debian << 'EOF'
# paste script content from the spoiler below
# type EOF and press Enter
By default, all subdirs of/tmp/mnt/
(excluding the Entware partition) are bind-mounted to the Debian/mnt/
, making them visible to Plex
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() {
mount | grep -q "$CHROOT_DIR"
}
mount_ext() {
for dir in /mnt/*; do
{ [ -d "$dir" ] && mountpoint -q "$dir"; } || continue
dir=$(readlink -f "$dir")
[ "${CHROOT_DIR#"$dir/"}" != "$CHROOT_DIR" ] && continue
target_dir="$CHROOT_DIR/mnt/$(basename "$dir")"
mountpoint -q "$target_dir" && continue
mkdir -p "$target_dir" && mount -o bind "$dir" "$target_dir"
done
}
start() {
if running; then
echo "Chroot'ed services seems to be already started, exiting..."
return 0
fi
logger "Starting Debian..."
rm -rf "$CHROOT_DIR/opt/tmp/" "$CHROOT_DIR/tmp/" 2>/dev/null
mkdir -p "$CHROOT_DIR/opt/tmp" "$CHROOT_DIR/tmp"
for dir in dev proc sys; do
target_dir="$CHROOT_DIR/$dir"
mountpoint -q "$target_dir" && continue
mkdir -p "$target_dir" && mount -o bind "/$dir" "$target_dir"
done
mount_ext
echo "Starting chroot'ed Debian services..."
grep -Ev '^\s*($|#)' "$CHROOT_SERVICES_LIST" | while IFS= read -r service; do
chroot "$CHROOT_DIR" "/etc/init.d/$service" start
done
echo "Debian started" && logger "Debian started"
}
stop() {
if ! running; then
echo "Chroot'ed services already stopped"
return 0
fi
logger "Stopping Debian..."
echo "Stopping chroot'ed Debian services..."
grep -Ev '^\s*($|#)' "$CHROOT_SERVICES_LIST" | while IFS= read -r service; do
chroot "$CHROOT_DIR" "/etc/init.d/$service" stop
sleep 1
done
awk -v dir="$CHROOT_DIR" '$2 ~ dir { print $2 }' /proc/mounts | sort -r | xargs -d '\n' -r umount -l
echo "Debian stopped" && logger "Debian stopped"
}
restart() {
stop
start
}
enter() {
running || start
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
}
postmount() {
if [ -n "$1" ] && [ "${CHROOT_DIR#"$1/"}" != "$CHROOT_DIR" ]; then
start
else
mount_ext
logger "Debian - missing external drives mounted"
fi
}
unmount() {
if [ -n "$1" ] && [ "${CHROOT_DIR#"$1/"}" != "$CHROOT_DIR" ]; then
stop
fi
}
status() {
running && echo "Chroot'ed services: RUNNING" || echo "Chroot'ed services: STOPPED"
}
case "$1" in
start | stop | restart | enter | status)
"$1"
;;
postmount | unmount)
"$1" "$2"
;;
*)
echo "Usage: (start|stop|restart|enter|status)"
exit 1
;;
esac
exit 0
* - set up hot-plugging of USB drives in Debian
Skipping this step, hot-plugged USB drives will only become available to Debian (and thus accessible by Plex) after a router reboot or a manualdebian restart
/debian enter
Prerequisite:JFFS custom scripts and configs
enabled (router WebUI -> Administration -> System
)
Bash:
echo 'debian postmount "$1"' >> /jffs/scripts/post-mount
* - set up Debian graceful shutdown on Entware partition unmount
This step ensures a graceful shutdown of Debian (and thus Plex when the Entware partition is unmounted.
This also prevents mostDevice or resource busy
errors, making the unmount process significantly faster.
Prerequisite:JFFS custom scripts and configs
enabled (router WebUI -> Administration -> System
)
Bash:
echo 'debian unmount "$1"' >> /jffs/scripts/unmount
6 - prepare chrooted services list and set up
debian
symlink
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 Plex prerequisites
Bash:
apt update && apt upgrade -y
apt install -y apt-transport-https curl gnupg procps
9 - configure timezone
Bash:
dpkg-reconfigure tzdata
10 - ensure
/usr/sbin/init
is not a systemd
symlink
Bash:
[ -f /usr/sbin/init ] && ls -l /usr/sbin/init | grep -q systemd && mv -f /usr/sbin/init /usr/sbin/init.bak
11 - 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
Plex Media Server will start automatically after installation.
During initial setup, which can take 5–15 minutes, CPU and RAM usage may spike to nearly 100%.
The router may become unresponsive during this time — just let it finish.
12 - exit Debian
Bash:
exit
13 - add Plex Media Server to chrooted services list
Bash:
echo 'plexmediaserver' >> /opt/etc/chroot-services.list
14 - restart Debian
Bash:
debian restart
After about 30 seconds, the Plex should be reachable at<router-ip>:32400/web
. For example: 192.168.1.1:32400/web or router.asus.com:32400/web
Note: Plex library configuration may cause very high CPU and RAM usage.
During this process, the router's web interfaces and SSH may become unresponsive.
Once library configuration is complete, overall performance should return to normal.
Update procedure
1 - ssh to router
* - update amtm and Entware packages using
amtm
Warning: This step may overwrite/opt/etc/init.d/S99debian
.
If this happens, repeatstep 5
of the installation procedure to restore it.
2 - enter Debian
Bash:
debian enter
3 - hold Plex and upgrade other Debian packages
Plex should be upgraded separately to prevent other packages from creating a problematicsystemd
symlink.
Alternatively – upgrade everything at once, then fix the symlink and reinstall Plex.
Bash:
apt-mark hold plexmediaserver
apt update && apt upgrade -y
4 - ensure
/usr/sbin/init
is not a systemd
symlink
Bash:
[ -f /usr/sbin/init ] && ls -l /usr/sbin/init | grep -q systemd && mv -f /usr/sbin/init /usr/sbin/init.bak
5 - unhold and upgrade Plex
Bash:
apt-mark unhold plexmediaserver
apt update && apt upgrade -y
* - restart Debian
Bash:
exit
debian restart
Last edited: