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 mountcommands (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 ext4card where even the main partition isext4. My ROM is a Stock ROM that will unlikelineagenot supportext4 mountout of box . I canmountmypartitionswith an approach similar toinit.dand they are visible torooted TCapps but they are not RW. I would likepartitionwideRWfor certain apps. Not just private dirs. I triedvold-posixit does not like my OS and arch. not executable: 64-bit ELF fileI 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 partitionwidemountfor specificrootedand 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 wideapproach 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:23bindfsbinary, 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:24mountcommand creates the three mounts in/mnt/runtimealong with two duplicate mounts in/storage/emulated/0.umountcalled 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/sdb1will 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:55bindfsand 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'sandmountingoptions..... I am still not able to get right access to the target folder which is actually theWhatsAppfolder. 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:30bindfsI can as much as re-name withnon rootprivs. But creating folders is a NO. Any combination .Here is my context for the targetu:object_r:media_rw_data_file:s0so 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 yourbindfse.g. as well. Any ts-shooting help wd be appreciated ✌️ – Jason Reeves Jun 29 '22 at 03:29