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?