Rclone mount on android -- almost there, but permissions bug?

hey,

almost complete in my dream of having rclone mount running on the shield TV… below’s my current executing command.

The problem I’m running into is with permissions. While rclone copy sets the permissions executable correctly and I’m able to have Plex read the file, rclone mount cannot set it to be executable. I need the permissions to be rwxr-xr-x yet every time I run rclone mount the files in the cache are set at rw-r--r--

I’m thinking this is a problem with Android’s unique permissions structure and the implementation of fusermount I am using, but with --debug-fuse and -v I don’t get anything useful in the log. Any ideas?

rclone mount gdmovies: /storage/4D4F131D28B39596/Movies \
        --config=/storage/4D4F131D28B39596/tools/rclone/rclone.conf \
	--cache-chunk-path=/storage/4D4F131D28B39596/Downloads/rclone-cache \
	--cache-db-path=/storage/4D4F131D28B39596/Downloads/rclone-cachedb \
	--gid 9997 \
	--umask 022 \
	--allow-other \
	--dir-cache-time 72h \
   	--tpslimit 8 \
	--fast-list \
	--debug-fuse \
	--verbose \
        --daemon 

Oh and before anyone asks, yes, when I change the umask to be 002 the permissions only change to rw-rw-r-- with no execution permission

What you want is

  --dir-perms int                      Directory permissions (default 0777)
  --file-perms int                     File permissions (default 0666)

Which you’ll find in the latest beta.

Why do you need the files to be executable?

ok, I’ll try the latest android beta sometime today and report back.

Needing the files to be executable is an assumption on my part. Plex is not reading the directory correctly when I scan for media it reads it for less than 10 seconds and then stops and doesn’t come up with anything. When the folder and media inside are not cached and have permissions 0755 it works. I’m hoping its a permissions issue and not something more complicated

Also, what’s the difference between --umask and --dir-perms --file-perms?

You may have those flags in the version you are using already…

the --dir-perms are the starting permissions for a directory. They are modified by the --umask to get the final permissions. Likewise the --file-perms and files.

How did you mount on Android Shield? I assume you are rooted? I also assume you are using this?

Yes, I’m using that compiled fusermount and yes unfortunately I had to root for this

Hmm running into some weird problems here. So I downloaded the beta, got the permissions running and everything but I still can’t get Plex or other apps for that matter to see the mount.

Weird problem 1) the rclone mount files refuse to chmod 777. They stay “stuck” at 755. But ok.

Weird problem 2) FX File Explorer, even when run in root mode, cannot see any of the cached files. I can see the files in Termux either with tsu or with the normal non-root default Termux user, but any other app can’t see them which is probably why Plex can’t see them either

Weird problem 3) When transferring files, I can see the file by all apps after its transferred, but I get this error on transfer: 2019/01/29 05:02:38 DEBUG : folder.jpg: Failed to pre-allocate: operation not supported

This has got to be something in android, but I don’t know where to start. I CAN see the rclone-db file that’s created with the same permissions and any other filed copied with rclone copy but any “incomplete” file cached by rclone mount seem to be fundamentally different

I’m thinking this problem exists in the fusermount implementation or the way rclone is trying to pre-allocate… how else can I debug this? I have allow-other all set and I’m not receiving any errors pushed to the debug

Try rclone mount with vfs chunk, not rclone cache. It should be faster on shield TV cpu. Then set the chunk size, chunk limit and buffer size to be small enough for shield ram.

I think android shield is more restrictive in terms of file folder permission than standard Linux. I suggest you to use termux and see the uid, guid, and permission for your normal mounted NAS and then make it so it will be similar in result for your rclone mount flag.

So after that you mount the rclone mount, test if the same user can see content. And then test of different user can see content ( by using other app). If the same user can’t see content then you have bad fusermount incompatible with 7.2.2.
Or tryto mount other file system. You can try to compile the fusermount and rclone…

Did your rclone mount persistent, not being killed or zombied?
You can see via termux that lots of background app/services are using the cpu and many of the process gets killed / zombied over time.

Not sure why you have problem with rclone copy. Rclone copy has always work in Android from as long as I can remember. Rclone copy doesn’t use fusermount and so the result of file and folder permission of rclone copy doesn’t impact rclone mount at all.

I wanted to try to root my shield and do rclone mount but I’m waiting for next firmware. Currently 7.2.2 has regression bug which affect mounted file system, so for example mounted NAS showing as mounted but sometimes suddenly can’t seethe content until shield is reboot or remounted.

Try rclone mount with vfs chunk, not rclone cache. It should be faster on shield TV cpu. Then set the chunk size, chunk limit and buffer size to be small enough for shield ram.

Gotcha, I’m just trying to get it to work right now then will focus on optimizing

I think android shield is more restrictive in terms of file folder permission than standard Linux. I suggest you to use termux and see the uid, guid, and permission for your normal mounted NAS and then make it so it will be similar in result for your rclone mount flag.

I’m not trying to do this through a NAS. I’m trying on a drive directly connected to the SHIELD via USB

So after that you mount the rclone mount, test if the same user can see content. And then test of different user can see content ( by using other app). If the same user can’t see content then you have bad fusermount incompatible with 7.2.2.

Yes, as I tried to explain earlier, the same user can see the content, but as soon as I switch apps the content disappears (despite being in the “everyone” uid and gid shared with the whole NVIDIA_SHIELD file structure)

Did your rclone mount persistent, not being killed or zombied?
You can see via termux that lots of background app/services are using the cpu and many of the process gets killed / zombied over time.

Yes, that wasn’t the problem, the daemon persisted it. it’s just a matter of permissions

Not sure why you have problem with rclone copy. Rclone copy has always work in Android from as long as I can remember. Rclone copy doesn’t use fusermount and so the result of file and folder permission of rclone copy doesn’t impact rclone mount at all.

No problem with rclone copy it works great

I wanted to try to root my shield and do rclone mount but I’m waiting for next firmware. Currently 7.2.2 has regression bug which affect mounted file system, so for example mounted NAS showing as mounted but sometimes suddenly can’t seethe content until shield is reboot or remounted.

Not sure why you are trying to do it with a NAS (I tried running rclone mount off my NAS but the connection to Plex was too slow) but you should root the shield and see if you can get further than me

Sorry not to make myself clear. I wasn’t trying to do it with nas.
What I meant was that since you have permission problems especially other user can’t even see the content I suggested you see the folder location where your nas is mounted on shield and use similar folder location for your rclone mount point. And also see your mounted NAS file, folder permission and uid, guid do that you can set similar ones in rclone mount with the logic that when you mount it in similar folder with similar uid, guid and permission as the Shield would normally mount your nas, then it’s more likely and higher chance other app can see it.
Its just from my experience mounting with fusermount long time ago when android was still around 4.0.

For example in my shield everything is mounted under /storage/ so that alloy apps can see and pick them from file picker

I suggested using vfs chunk because I did not think rclone cache would work on android.

So if you switch app then other user can’t see the mount then it seems like it’s not persisted. Where do you put the daemon? And you check that the user, I assume root user can see the content by issuing normal command such as ls or find into rclone mount directory right?

Yes, I am using NVIDIA_SHIELD folder which all users can see and have access to:

drwxrwxrwx 1 root everybod 0 Jan 28 22:01 NVIDIA_SHIELD

I suggested using vfs chunk because I did not think rclone cache would work on android.

Oh, they are different? I thought vfs-chunk are different options for rclone mount

So if you switch app then other user can’t see the mount then it seems like it’s not persisted. Where do you put the daemon? And you check that the user, I assume root user can see the content by issuing normal command such as ls or find into rclone mount directory right?

the process persisted, and I ran the daemon as root (since I have to run the rclone mount command as root since fusermount requires root). You are correct, root user can see it, and termux non-root user can see it, but any other “user” like FX File Exporer, or Plex, cannot.

Looks like this person had my same problem:

Ok this is unrelated to this thread but current shield firmware update yield great speed for plex. For example I have my low-power (8 watt cpu) Linux nas do rclone mount and serve this to my home network as samba v3. Plex server on shield TV can finish scanning that (around 70TB) under few hours with around 75k of tv episode and movies. It usually finish scans in just 10 minutes if there’s not many new movies. Ever since the samba v3 upgrade and rclone version 1.4 the speed is great with small latency.

I only want to do rclone mount on shield side to simplify my setup.

Yes I had a similar setup to you but running it off my router was inefficient, slow, and I also want to simplify my setup :slight_smile:

I’m not sure rclone can fix this issue with Android, it might require changing fusermount or even worse, compiling a custom ROM :frowning:

I wouldn’t mount rclone mount on an external USB file system on android. Is simply too flaky. You can see toast notification sometimes that USB gets unmounted and remounted on shield.
And I bet you this is why you have problem with permission. I believe your USB in shield is mounted as exfat which doesn’t support some chown or chmod commands. Try to point the mount point under /storage /

This is expected in Android sandbox. other app can’t read other user data and root process. That’s why I suggested you check out some details when your shield mounted your nas.
I’m too lazy to install termux and check, but you can see which process own and uid,guid,and permission for mounting your samba on shield and I suggest you make it as similar to that

I think you may need to do rclone mount with “su -l loginname” similar to the ones owner of samba mount

And I bet you this is why you have problem with permission. I believe your USB in shield is mounted as exfat which doesn’t support some chown or chmod commands. Try to point the mount point under /storage /

Ok I’ll try this when I find some time, but the drive is formatted HFS and if I point the mount to /storage/ I only get the 16GB which is not enough space for even one movie

I’m too lazy to install termux and check, but you can see which process own and uid,guid,and permission for mounting your samba on shield and I suggest you make it as similar to that

The Plex process has its own ID, yes, but again, AFAIK there is no way to run the rclone mount with another user other than root since rclone mount requires fusermount which requires root, plus I don’t think there is a way in termux to su -l loginname

Anytime I try to run rclone mount without root I get a permission denied from fusermount

That’s not how rclone mount work. You get unlimited storage from your unlimited gdrive. Just set the chunk size small enough so it will fit in Ram.
You probably confused this with rclone cache. Either way mount point is just mount point. You can set the location of your rclone cache directory to be different than your mount point if you choose to use rclone cache instead of vfs chunk.

Hmm I think you are close. That above means that you just need to play with uid,guid, and mask in rclone mount flags.
Try to make it similar with the ones from your mounted NAS.

I have around 300GB of plex and gaming data and apps on my shield ssd which I will lose when I root my shield so I’m reluctant to root it. And I have few tv apps that won’t work in rooted device…

Try mounting on /system also. Or mount it in Plex or termux’s /data/data/…/directory itself as a test.

I doubt this will work because it’s a new mount though and those need special flags and permissions in Android that rclone or the fuse lib isn’t setting.

I’m guessing this doesn’t work because the OP is trying to mount rclone cache to an external USB in android, which is not stable.

Op, you should try to mount it in the /storage or /mnt or /system with the simplest rclone mount flags such as: rclone mount GDrive: /storage/GDrive --vfs-cache-mode writes --allow-other --allow-non-empty --uid= --gid= --umask

My god we are so close I can feel it.

I mounted it to/storage/GDrive as suggested. It still didn’t work. Then I did some reading. Basically, Android’s file system sucks for making sure other processes can see a mount from another process because of SELinux and the sandboxing built into the file system.

Since I rooted with Magisk, I found out about the Mount Namespace Mode in the Magisk Manager settings, which enables other superuser processes to inherit the permissions of the parent superuser process. Voila! I can see the files from my rclone mount in FX File Manager, open the files, and even play them in Plex. While it is buggy and slow (I presume because it is running through FX File Manager and I didn’t optimize rclone mount yet), it works.

However, this only applies to processes that are run via superuser. I don’t think there is a way to do this in Plex given that Plex does not function as an elevated user unless Plex enables a superuser option similar to FX File Manager and other apps that have that capability.

It seems like there are three options:

1) Run an rclone mount inside /etc/init at startup
I’m unsure how to:
a) write a file to /etc/init since it is read only and probably gets overwritten from boot.img every reboot
b) ensure that rclone and fusermount are in the environmental paths and are called correctly

2) Dive into SELinux and chcon the rclone mount directory
I’m not sure this will persist through reboots

3) Plex builds superuser capability into their Android app

Any suggestions here?

Other references:
https://stackoverflow.com/questions/42348061/fuse-on-android

https://stackoverflow.com/questions/29589969/how-to-mount-an-external-drives-ext4-partition-on-android-and-make-it-rw-availa

https://android.stackexchange.com/questions/38413/adb-shell-mount-command-documentation

https://books.google.com/books?id=y11NBQAAQBAJ&pg=PA105&lpg=PA105&dq=allow+fuse+android+to+see+processes&source=bl&ots=nVWDFWwRXD&sig=ACfU3U3rkcAg99ZTxtE57U5Vlt3dC5dbgA&hl=en&sa=X&ved=2ahUKEwiN99WD2ZPgAhUCLa0KHTN0Bn8Q6AEwB3oECAMQAQ#v=onepage&q=allow%20fuse%20android%20to%20see%20processes&f=false

Hmm, can’t you transfer all of that to your unlimited storage drive?

And what TV apps won’t work rooted? All mine work fine. I need some help troubleshooting here and would love a second person checking my work.

You can try to disable selinux especially since you wanted to set weird executable permission for your files.
I doubt that will help.

Where did you put the path for rclone and fusermount then? If you put it inside the path of termux that would probably the reason other apps can’t see it too and it probably is not persistent

I suggest you take different approach. When you use mounting with namespace enabled your apps needs superuser elevated privilege to read that mount point. I think samba mounts on shield doesn’t use that. So try to disable namespace.
Did you try to set the same uid, guid in your rclone mount the same as the one in your samba mount?
I think your best bet is to make your rclone mount have similar properties like your samba mount.

Instead of fx,use a proper file manager like solid Explorer which available for TV ui.
My old Sony z3 phone has a feature to mount remote file system so it’s not dead end.
But if you only get it work for superuser I think you have wrong uid,guid and umask setting, or selinux got in your way.

I suggest you to troubleshoot it like this logic. First you want to make sure you mount with the simplest option.what matter here is that it’s persistent with correct uid,guid and correct permission due to restrictive nature of selinux.
Since you seem to have working fusermount you can try to mount simple stuff that’s already proven to work on shield TV.
For example you should try to mount your samba or sdcardfs or sshfs. Once you get that then you play with the correct uid guid. Then you can use similar setting for your rclone mount.
Anyway there are old posts for old android of people rooting tablets and mounting samba, sshfs etc in their phone and tablet.
I believe the concept is still the same, so try to use the same setting for rclone mount that would result in same way of mounting.

I don’t want to root now for several reasons:

Current 7.2.2 has mount related bug, so even if rclone and fusermount works there’s possibility is still not working because of this. In this firmware samba connection sometimes reports successful etc and things seem to be mounted but you can’t actually access the data.it seems to be regression bug.

I have A LOT of movies and TV shows in nvidia plex server, probably around 70,000-80,000 of movies+episodes metadata that I will lose if I root my shield. Stupid plex let you back up the data but doesn’t give any reliable means to restore the data. And around 30,000 of those metadata is irreplaceable because it’s not on tvdb ( because they are European, Chinese, Korean and Japanese TV) so it’s manual work literally hundreds of man hour spent editing metadata.

Some app like BBC iplayer TV, itv hub, and some Korean and Japanese local TV app won’t work with rooted device. Gyao and abema etc.

Lastly the benefit of rooting is small at this point. I would save only around 10watt per hour by eliminating my nas. And each time I click on “play“ until I receive first image frame is going to be only 3-5 seconds faster. Using nas with rclone, with nvidia plex server it takes around 6-10 seconds to play a movie . Using plex server+rclone mount in the same device it will be 3-5 seconds faster in my case.
I tested this. I have 2 identical plex servers one on the nas and another one on the shield.

And also all my game settings and data on shield.

I probably wait until another major firmware update before I try to root my shield.