I want to use rclone-mount on Android to mount remote directories from my own server as well as from pCloud. I want the mount points to be established automatically at boot time and to remain mounted full time.
I have not been able to install Magisk on this device yet. See How to install Magisk without an unlocked bootloader?
I tried the following rclone-mount method with Termux:
How to mount rclone on Android?
Unfortunately, that results in permissions errors that I have not been able to solve. I posted a question about it here:
scripts - How to use rclone-mount with Termux:Boot?
That remains unresolved. I have worked on this for many hours, so I could add more info to my other question if needed. However, with the assistance of @alecxs I tried another approach and resolved the permission errors. Now rclone
can now successfully mount both pcloud and my own server when I run the commands at the CLI.
My current question is, how to automate this without Termux:Boot or Magisk? II can't install Magisk and Termux gave me tons of trouble for a couple weeks and I only got this working by ditching Termux. Again, see the above question if you think you know the reason for the Termux problems.)
For background, and to possibly help others, I am listing all my steps so far since the commands are working and this might prove to be a useful supplement for Irfan Latif's great answer that helped me get started with rclone-mount on Android.
- removed Termux (& verified all files are gone)
- removed Magisk app (the module was never installed)
- kept original SuperSU v2.82 (& verified it doesn't have trackers)
- gave network access permissions to apps running under root in AFWall+
- used "Simple SSHD" app (from F-Droid) to access device via SSH (from my PC)
- I have a working rclone.conf file already
- my env var
LD_LIBRARY_PATH
is empty and I did not have to modify it with this method - my device is Arm64
echo $PATH
=/sbin:/system/sbin:/system/bin:/system/xbin
and I put the binaries into/system/bin
EDIT: @alecxs pointed out that these custom binaries should have been installed to/system/xbin
.
First, I put the binaries into the correct directories on my Android device:
cd /path/to/files/gocryptfs_fusermount-ARMHF_2021-01-13/
NOTE: the fusermount binary comes from XDA / mirfatif: https://forum.xda-developers.com/m/mirfatif.7805402/ Fusermount on android (rclone mount) XDA Forums
$ scp -P 2222 fusermount 192.168.1.123:~/
On Android, become superuser:
su
install fusermount binary:
mount -o rw,remount /system
mv /system/bin/fusermount /system/bin/fusermount.termux
cp ./fusermount /system/bin/fusermount
chmod 775 /system/bin/rclone
chown system:shell /system/bin/fusermount
check SELinux context and DAC permissions:
# ls -laZ /system/bin/fusermount
-rwxrwxr-x 1 system shell u:object_r:system_file:s0 114056 2021-10-25 01:29 /system/bin/fusermount
Install the official rclone binary: NOTE: The rclone binary I'm using is from: https://beta.rclone.org/test/testbuilds-latest/rclone-android-21-armv8a.gz
I have it on my phone at: /storage/emulated/0/Documents/rclone-android-21-armv8a
mount -o rw,remount /system
ls -la /system/bin/rclone
lrwxrwxrwx 1 system shell 42 2021-10-21 19:55 /system/bin/rclone -> /data/data/com.termux/files/usr/bin/rclone
rm /system/bin/rclone
cp /storage/emulated/0/Documents/rclone-android-21-armv8a /system/bin/rclone
chmod 775 /system/bin/rclone
chown system:shell /system/bin/rclone
ls -laZ /system/bin/rclone
-rwxrwxr-x 1 system shell u:object_r:system_file:s0 62257128 2021-10-26 19:45 /system/bin/rclone
Optional (if needed, restore SELinux context -- I did not need to do this):
restorecon -F /system/bin/rclone
restorecon -F /system/bin/fusermount
Finished, so mount readonly again:
mount -o ro,remount /system
Check the mount namespace:
# readlink /proc/1/ns/mnt
mnt:[4026531840]
# readlink /proc/self/ns/mnt
mnt:[4026531840]
If they don't match, run the command below. (Mine match)
nsenter -t 1 -m -- "$0"
Verify the remote is not already mounted:
# ls -la /mnt/runtime/write/emulated/0/mypcloud/
Set env var for rclone config:
export RCLONE_CONFIG=/data/data/org.galexander.sshd/files/rclone.conf
Now manually mount remote using rclone:
rclone -vvv mount mypcloud: /mnt/runtime/write/emulated/0/mypcloud --gid 9997 --dir-perms 0771 --file-perms 0660 --umask=0 --allow-other --cache-dir /storage/emulated/0/.cache --vfs-cache-mode full --vfs-cache-max-age 2h0m0s --vfs-cache-poll-interval 5m0s
Success!
to umount:
fusermount -u /mnt/runtime/write/emulated/0/mypcloud
There is really nothing new in the steps above that Irfan Latif didn't already discuss. However, there are differences. For example, I did not need to set LD_LIBRARY_PATH
. Also, rclone emits this warning:
WARNING: linker: /system/bin/rclone: unsupported flags DT_FLAGS_1=0x8000001
However, that doesn't appear to be a problem. I also show more info about SELinux contexts and a few other things. There are enough differences from the existing answer that my steps might help someone else with their own troubleshooting.
Now, my main question how can I automate this at boot time without Termux:Boot or Magisk? I guess I could put a script into init somewhere, but I would appreciate an expert answer. I have reviewed a lot of answers about init.rc and executing scripts at boot. They have mostly sent me to solutions that were obsolete by Android 4.x and they also do not deal with the question of how to handle the case of booting up when a network connection is not available.
EDIT: @alecxs contributed the following idea for booting up when a network connection is not available:
until dumpsys connectivity | grep -iq state..connected
do
sleep 1
done && rclone <...> &
My device is running Android 7.0 (US Samsung Galaxy S8). It is rooted, I have true root, it has SuperSu 2.82, SELinux is permissive, and I can remount /system rw (as shown above). I do have the /system/su.d/
directory.
Also, related question, where is a good / safe location (path) on my Android device to keep my pcloud token and my private ssh key (for the remote SFTP server)?
init.rc
– alecxs Oct 27 '21 at 10:44/init.rc
? You can put a newanything.rc
file in/system/etc/init/
when you have write access to/system
. – Irfan Latif Oct 27 '21 at 18:31etc/
in boot.img is the only location – alecxs Oct 27 '21 at 18:33/etc
symlink has always been pointing to/system/etc
. – Irfan Latif Oct 27 '21 at 18:36