[HowTo] Configuring rclone mount on NVIDIA Shield to replace Plex Cloud

NOTE: This guide has mostly been replaced by this Magisk module. I suggest you install it instead of messing around with the guide below!

Ever since Plex Cloud was retired last year, I’ve been searching for a good way to replace its functionality on my Shield PMS. While others have suggested either switching servers or using a VPS, none of those solutions fit the equipment I have or my small use-case to read and play 2TB+ of movies uploaded to the cloud by 2 to 4 people at once.

This solution works great. Real-world tests have movies loading in 5 seconds and media scans taking 3 to 8 seconds per file on a 400/25 Mbps connection. Seeking takes less than 5 seconds (you might be able to improve this via the --vfs options in rclone). Transcoding and remote playback also work here, but I don’t think the shield can handle more than 2 concurrent streams with rclone mount. Prove me wrong!

Ultimately, until integrating a direct connection with Google Drive gets implemented in the Plex back-end, the solution here is a working, but far from ideal measure to play media from the cloud on the Shield. The (1) overhead from Android’s implementation of FUSE, (2) Android’s SELinux permissions, and (3) the sheer time required prevents this from being optimal.

Below is the guide: I welcome feedback! I recommend you have some familiarity with linux and the console.



1 Root the shield using Magisk


2 Install Termux via Google Play

  1. pkg install tsu nano rclone ssh
  2. setup ssh (allows ssh -p 8022 your.shield.ip)
    2a) nano $PREFIX/etc/ssh/sshd_config and add PermitRootLogin yes (if you put sshd into your startup script below)… I highly recommend you enter these commands through ssh as it makes it way easier than typing stuff into the android keyboard.
    2b) if you do not use ssh and instead use termux to enter the commands, be sure to put tsu before all your commands

3 Install fbind via Magisk Manager > Modules


4 Install fusermount for Android

  1. adb push fusermount
  2. mv fusermount /data/data/com.termux/files/usr/bin
  3. chmod 700 fusermount
  4. cd /data/data/com.termux/files/usr/bin && ls -al (will show your Termux UID)
  5. chown {your termux UID} fusermount

5 Setup rclone and other directories

  1. nano $HOME/.config/rclone/rclone.conf:
    (you should probably setup rclone through rclone config and you can do this through ssh or Termux)
[yourmount]
type = drive
scope = drive
client_id = 
client_secret = 
token =
  1. mkdir /storage/emulated/0/Drive
    all apps will be able to see this directory as the front for your rclone mount
  2. mkdir /storage/emulated/0/.mount
    this is your fbind mount point, which is automatically replicated in /data/media/0/.mount and is your ghost mount point that will be bound to the Drive directory… it provides a funnel from the root permissions in /data/media/0/Drive to the readable directory at /storage/emulated/0/Drive
  3. mkdir /storage/emulated/0/temp (optional)

6 Execute the commands to start the mount and fbind:

  1. tsu
rclone mount gdrive: /data/media/0/Drive \
 --buffer-size 32M \
 --vfs-cache-mode minimal \
 --vfs-cache-max-size 4G \
 --vfs-read-chunk-size 64M \
 --dir-cache-time 72h \
 --allow-other \
 --allow-non-empty \
 --fast-list \
 --use-mmap \
 --log-level INFO \
 --log-file=/storage/emulated/0/temp/rclone-mount.log \
 --daemon
  1. su
    fbind -b /data/media/0/.mount /data/media/0/Drive

7 Your mount should be readable by Plex at Internal Storage > Drive > root drive directory


8 To stop:

  1. tsu
    fusermount -uz /data/media/0/Drive
  2. su
    fbind -u /data/media/0/.mount

9 Setup a Magisk boot script to automate rclone mount on Shield startup

  1. nano /sbin/.magisk/img/.core/service.d/startup.sh
  2. copy the below script to the file (same rclone mount command as above):
script
#!/system/bin/sh
export PREFIX=/data/data/com.termux/files/usr
export HOME=/data/data/com.termux/files/home
export PATH=${PREFIX}/bin:${PREFIX}/bin/applets:$PATH
export LD_LIBRARY_PATH=${PREFIX}/lib:$LD_LIBRARY_PATH

sleep 15 # wait for final checks while Magisk boots

sshd -p 22

rclone mount gdrive: /data/media/0/Drive \
 --buffer-size 32M \
 --vfs-cache-mode minimal \
 --vfs-cache-max-size 4G \
 --vfs-read-chunk-size 64M \
 --dir-cache-time 72h \
 --allow-other \
 --allow-non-empty \
 --fast-list \
 --use-mmap \
 --log-level INFO \
 --log-file=/storage/emulated/0/temp/rclone-mount.log \
 --daemon

## Additional items for startup
# sleep 60 # wait for external drive to mount before transmission starts, and then set it as a low priority

# nice -n 15 transmission-daemon --log-error -e '/storage/emulated/0/temp/transmission-daemon.log'
  1. chmod +x /sbin/.magisk/img/.core/service.d/startup.sh

10 A few notes:

  1. I used to have an external drive, but that’s no longer needed since this can be run direct off the shield’s internal memory and storage with --vfs-cache. While an external drive is easier to manage under NVIDIA_SHIELD since it’s writable and can be connected to the Shield’s Samba server, your rclone drive mount will not work there because of Android’s weird permissions. It also is not optimal when using with --vfs-cache-mode. vfs makes sense because you can manage the size of the cache which is stored in memory and not use any of the 16GB internal shield storage. If you need write access (--vfs-cache-mode minimal means rclone will download the file to disc if you are doing RW operations) you can control the size of the file with --vfs-cache-max-size. You will not be able to manage the rclone mount storage via the traditional methods. However, --vfs-cache-mode minimal enables deleting files with Plex. Checkout the rclone forums for more rclone related settings.

  2. Play around with the rclone mount settings, especially the --vfs-cache-mode. I tried to optimize as much as possible given the Shield is memory constrained and the vfs-cache is memory intensive. Let me know if you find better settings specific for the Shield.

  3. Setup your own client_id in rclone to avoid some of the rate limiter bans that may prevent you from streaming smoothly.

  4. This solution is only recommended for video media, although I use it with music too and don’t experience many problems.

2 Likes

Why not just setup a cheap vps for 2 to 5€ per month and setup plex/rclone on linux server.

p.s. Seek is working with rclone mounts.

Nice work @thekiefs . I have been following this on rclone forums. Have you tried using the vfs options for rclone instead of cache. You likely would not need an external drive for the cache files and it completely avoids google 24 hour bans.

Here is my command I use on my mac to mount and serve plex.

/usr/local/bin/rclone mount Google: ~/Google \
  --log-level INFO \
  --log-file /Applications/Rclone/Logs/rclonemount$(date "+%Y%m%d").log \
  --volname Google
  --allow-other \
  --buffer-size 256M \
  --dir-cache-time=72h \
  --drive-chunk-size 32M \
  --vfs-read-chunk-size=128M \
  --vfs-read-chunk-size-limit=off

Any way you can test the mount with vfs. I am hesitant to root my shield and have to redo everything on it but if this works then I will for sure do it.

1 Like

I tried it and it works really well. Movies startup the same but playback is smoother––router shows consistent download throughout (rclone cache spikes the bandwidth) and seeking is noticeably faster.

I updated my config above and removed the related cache configurations since we’re using --vfs-cache and since the kernel doesn’t have the read/write overhead associated with an external drive. Thanks! My internal storage has about 7G free so I’ll test out my settings further over the long run and see what happens.

btw, your config doesn’t have --vfs-cache-mode specified, which is needed to turn vfs caching on, so I don’t think you’ve been using it to date :sweat_smile:

You do not needed it if you are not writing files and vfs-read-chunk-size will still be in effect.

Oh yes, you’re right… I’m reading here:

Chunked reading will only work with --vfs-cache-mode < full, as the file will always be copied to the vfs cache before opening with --vfs-cache-mode full.

–vfs-cache-mode string Cache mode off|minimal|writes|full (default “off”)

I guess in default mode as “off” it’s still “on”, but off should probably be ok for our use-case here

On which version is your Shield? I read that fuse/fusermount doesn’t work with Oreo anymore?

And instead of root the NVIDIA Shield with Magisk, just install the developer image, that gives you root access as well.

Where are you reading that? I’m on Shield release 7.2.2, Android 8.0. It works great. It’s possible Nvidia kept fuse in their implementation of Android. I don’t think they use SDCardFS.

Magisk comes with su. You need that for this. The developer image doesn’t come with su.

uhmm mount rclone in windows and then point shield to that drive letter is prob the most simple way

But then you need another server/pc who is online 24/7, the Shield runs anyway^^

2 Likes

thanks for the guide @ thekiefs

I have few questions :slight_smile: :slight_smile:

  1. Did you try before running Librelec with rclone in the Shield? In case you tried does this solution perform better?
  2. I’m assuming that before doing this you also tried with an VPS. Does this solution perform better?
  3. What’s the resolution that you are playing? 1080p?
  1. I didn’t try LibreELEC or any other non-shield based solution. I don’t want to invest in having a separate custom-built box to host a Plex server because I think a 256 core Tegra X1 should handle anything I throw at it. Locally everything plays file. Remotely most of my constraints are bandwidth limited––downloading the file via rclone then uploading it to the remote stream taxes my home internet :thinking: (400Mbps down / 25 Mbps up).

  2. I didn’t try a VPS, so I can’t give you any real world comparisons. There are a few advantages over a VPS that I can think of: (a) local streaming should be better since you don’t have to download it from the VPS rclone then upload it to the local player (b) no setup costs or fees (3) you are in complete control and don’t have to live within the constraints of the VPS provider… although you do have to bend Android to your will!

  3. I play up to 4k. My highest bit rate is a 55 Mbps 4k HDR file and it only takes about 5 seconds to start playing locally. Most of the problems I have, if any, are related to Plex bugs in the Shield which are slowly but surely being squashed.

Thanks for the reply. So does it work so good that iit let’s you play 4K files coming from recline?

That’s impressive! What is the size of those files?

Yes! About 65 Gb.

Hi. I have managed to do everything but bind my Rclone mount to external storage using fbind on the latest Shield Experience rooted with the developer version and Magisk. When I execute fbind it just seems to sit there and nothing happens. Should I be entering something in the fbind configurable.txt? Thanks

IIRC you don’t get confirmation of a successful fbind, but if everything is followed correctly the mount should be readable by Plex. The fbind is automatically saved and loaded on Magisk’s startup scripts.

I remember fbind not handling internal storage binds to external storage folders very well, and with vfs-cache you shouldn’t need to use an external storage anyway. Did you change that from the guide?

Okay, I’ll give it a shot, there’s just nothing obvious that its done anything and I don’t see the files when I load in Plex. By external storage I mean “internal user accessible” for my metadata on Plex server really so I’m kind of conflating too things. I currently use a VPS but since my friend has a Shield and a 2gbps synchronous connection that will be better and cheaper in the long run if I can get it to work :slight_smile:

If I take your example I see the files under my data/media/0/Drive but not under data/media/0/Mount and not mag(isk)ally when I try to add a Library in Plex Server but I’ll perservere.

Thanks


Virus-free. www.avast.com


Virus-free. www.avast.com

Can other apps, like FX File Explorer, see the files? What’s the output of ls -l from /sdcard/ and /data/media/0/?

Yeah FX and ls -l sees them under /data/media/0/Drive but not /data/media/0/Mount. Video spawned from FX under Drive plays fine. /sdcard (/storage/emulated/0) shows same as plex visualisation. Is the owner critical for the fbind because you specify media_rw in your doc but I could only get the rclone to mount to Drive when its owner was set to root despite having --allow-other flag?