I am using a Sony Xperia M4 Aqua. As is well known, the internal memory is rather small. Especially the Media
directory of WhatsApp
uses a lot of precious space, therefore I am trying to move it to the SD card.
I am using Android 6 and I have formatted the SD card to have an adopted storage partition.
Adopted storage would be normally used to migrate all /data
to it, as discussed here.
I am however interested in moving just the single directory WhatsApp/Media
somewhere else (possibly in the adopted storage partition), and then bind-mount it to its original location.
For this purpose, I moved the WhatsApp/Media
directory to the adopted storage. Then, following this discussion, I have modified the script /system/etc/init.qcom.post_boot.sh
adding the following mount
commands (the phone has no support for init.d
scripts)
mount -o bind /mnt/expand/4fdb2500-9aa7-44bc-a2c4-80aeae28e764/WhatsAppMedia /storage/emulated/0/WhatsApp/Media
mount -o bind /mnt/expand/4fdb2500-9aa7-44bc-a2c4-80aeae28e764/WhatsAppMedia /mnt/runtime/write/emulated/0/WhatsApp/Media
mount -o bind /mnt/expand/4fdb2500-9aa7-44bc-a2c4-80aeae28e764/WhatsAppMedia /mnt/runtime/read/emulated/0/WhatsApp/Media
mount -o bind /mnt/expand/4fdb2500-9aa7-44bc-a2c4-80aeae28e764/WhatsAppMedia /mnt/runtime/default/emulated/0/WhatsApp/Media
mount -o bind /mnt/expand/4fdb2500-9aa7-44bc-a2c4-80aeae28e764/WhatsAppMedia /data/media/0/WhatsApp/Media
Notice: /mnt/expand/4fdb25....
points to the adopted storage partition.
This only apparently works: if I open a shell with adb
I can correctly see that the WhatsApp/Media
directory contains the mounted directory. Also, I see no additional views that contains the WhatsApp directory, as can be checked by doing, in an adb shell
find / -type d -name WhatsApp
Nevertheless, WhatsApp is not able to access the Media gallery. For instance, in the chat I just see blurred pictures (like a preview), and clicking on it I do not see the full picture. Moreover, if somebody sends me a picture, all I can see is a blurred preview with the download icon. Clicking on the download icon does not produce anything.
Wrong permissions are presumably the source of problems. For example, some permissions/group ownership appear to be incorrect on some views:
root@E2303:/ # ls -n /storage/emulated/0/WhatsApp
drwxrwx--x 0 1015 2019-09-04 14:37 Backups
drwxrwx--x 0 1015 2019-10-19 02:00 Databases
drwxrwx--x 0 1015 2019-09-04 20:24 Media
root@E2303:/ # ls -n /mnt/runtime/write/emulated/0/WhatsApp
drwxrwx--- 0 9997 2019-09-04 14:37 Backups
drwxrwx--- 0 9997 2019-10-19 02:00 Databases
drwxrwx--x 0 1015 2019-09-04 20:24 Media
root@E2303:/ # ls -n /mnt/runtime/read/emulated/0/WhatsApp
drwxr-x--- 0 9997 2019-09-04 14:37 Backups
drwxr-x--- 0 9997 2019-10-19 02:00 Databases
drwxrwx--x 0 1015 2019-09-04 20:24 Media
root@E2303:/ # ls -n /mnt/runtime/default/emulated/0/WhatsApp
drwxrwx--x 0 1015 2019-09-04 14:37 Backups
drwxrwx--x 0 1015 2019-10-19 02:00 Databases
drwxrwx--x 0 1015 2019-09-04 20:24 Media
root@E2303:/ # ls -n /data/media/0/WhatsApp/
drwxrwxr-x 1023 1023 2019-09-04 14:37 Backups
drwxrwxr-x 1023 1023 2019-10-19 02:00 Databases
drwxrwx--x 0 1015 2019-09-04 20:24 Media
Permissions and group ownership of the Media
directory should be the same of the other (non bind-mounted) directories Backups
and Databases
.
Oddly enough, an attempt to remount the directories with the correct gid
root@E2303:/ # mount -o remount, gid=9997 /mnt/runtime/write/emulated/0/WhatsApp/Media
root@E2303:/ # mount -o remount, gid=9997 /mnt/runtime/read/emulated/0/WhatsApp/Media
root@E2303:/ # mount -o remount, gid=1023 /data/media/0/WhatsApp/Media
does not produce any changes in the group ownership: ls -n
as above gives identical results.
Even more strange, but maybe unrelated, omitting the space between remount
and gid=...
results in
mount: Invalid argument
How to bind mount WhatsApp/Media
folder from external SD card with correct permissions?
partitioned ext4
card where even the main partition isext4
. My ROM is a Stock ROM that will unlikelineage
not supportext4 mount
out of box . I canmount
mypartitions
with an approach similar toinit.d
and they are visible torooted TC
apps but they are not RW. I would likepartition
wideRW
for certain apps. Not just private dirs. I triedvold-posix
it does not like my OS and arch. not executable: 64-bit ELF file
I get this error forbindfs
. Any other ? – user1874594 Mar 17 '20 at 02:10getprop ro.product.cpu.abilist gives armeabi-v7a,armeabi
. Any other approach so I can get aRW partition
widemount
for specificrooted
and non rooted apps ( non rooted app is stock ROM's file manager that is invoked by default by all apps to traverse directories ) . As I understand ,Android 'deprecates this but I'd appreciate it' , if you can throw in your 2 cents ! – user1874594 Mar 17 '20 at 02:16partition wide
approach is not feasible then at the time of mounting want to give specific app IDs RW. as part of mount. How can I do this ? – user1874594 Mar 17 '20 at 02:23bindfs
binary, you have to build from source. If you can't, let me know and I'll build one for you when I get time. As far as your other queries are concerned, they cannot be explained (again) in comments. You may ask a precise and unique question with all necessary information and I can try to briefly explain steps specific to your situation. – Irfan Latif Mar 17 '20 at 03:24mount
command creates the three mounts in/mnt/runtime
along with two duplicate mounts in/storage/emulated/0
.umount
called on these directories returns no errors, but trying to re-mount to the same directory later doesn't propagate to non-root namespaces. SELinux is set to permissive. Only thing that fixes it is a reboot of the tablet. Using LineageOS 16.0 (Android 9) with Magisk. – Shamtam Oct 17 '20 at 16:53/dev/block/sdb1
will disappear on loss of power, and then when power is applied, it will appear again as/dev/block/sdc1
). – Shamtam Oct 17 '20 at 16:55bindfs
and it does seem to atleast execute with whatever options you have shown. I am on Android 10. Unfortunately after trying each and every option with varioususer id and group ID's
andmounting
options..... I am still not able to get right access to the target folder which is actually theWhatsApp
folder. in light of this can you please modify your answer for Android 10 or else maybe del it ✌️ – Jason Reeves Jun 28 '22 at 16:30bindfs
I can as much as re-name withnon root
privs. But creating folders is a NO. Any combination .Here is my context for the targetu:object_r:media_rw_data_file:s0
so why is that no Folders cant be created . I see something like an untrusted process app is accessing media_rw . But that 's happening with yourbindfs
e.g. as well. Any ts-shooting help wd be appreciated ✌️ – Jason Reeves Jun 29 '22 at 03:29