[ASUS ZenFone 8] bnsmb:
I've mentioned this elsewhere in some of my howtos, but I think this feature is important and useful enough to get its own howto.

Nowadays in the current Android OS version a lot filesystems are mounted read-only and remounting the filesystem read-write does not work anymore. Therefor the files in these filesystems can not be changed anymore.

That's pretty good from a safety standpoint, but sometimes a real showstopper.

But fortunately Android is a Linux based system and therefor there is a solution for this problem called bind mounts. bind mounts are some kind of symbolic links that only exist in memory and are therefor also supported for read-only mounted filesystems. Of course, this is a very simple description for this Linux feature but it should be enough here -- for more in depth details I recommend the Linux documentation.

bind mounts are used by Magisk but they can also be used manually without an installed Magisk - the only requirement for using it manually is root access to the phone.

Here is an example to replace the file /system/etc/hosts with a writable file using a bind mount:

Spoiler content hidden.

bind mounts are only possible for existing files - bind mounts for non-existent files will fail, e.g:

Spoiler content hidden.

bind mounts are also allowed for directories therefor to "create" a new file just copy the directory, create the new file in that new directory, and then do a bind mount for the existing directory.

Example:

Spoiler content hidden.

Hints

bind mounts are supported by the filesystems ext4, vfat, f2fs. and most probably a lot of other filesystems used on machines running Android.

Be careful when replacing executables, especially when replacing an important file like /system/bin/sh. And you should never replace a file that is just a symbolic link for toybox or busybox.

bind mounts created while the OS is running are only useful for files that are dynamically read by the OS. It does not make sense to replace for example one of the *.rc files using a bind mount because these files are only read once while booting the OS.

The filesystems used for source and target for a bind mount should support the same set of attributes and permissions or the result may not be like expected. E.g. you can not bind mount an executable with a file in the directory /sdcard/<something> because that filesystem for /sdcard does not support the executable permission:

Spoiler content hidden.

The source for the bind mount must be in a directory that is readable for all user that use the bind mounted file, e.g.

Spoiler content hidden.

Use the mount command to check if a file is bind mounted. e.g.

Spoiler content hidden.

To remove a bind mount just do a umount, e.g:

Spoiler content hidden.

Another method to remove all bind mounts is a reboot of the phone

It's recommended to use a sub directory in the directory /data/local/tmp for executables used in bind mounts, example:

Spoiler content hidden.

bind mounts are also useful for writable files to be able to revert the changes to a file. Example:

Spoiler content hidden.

Of course, this can also be done by creating a backup copy of the file and restoring the backup copy if necessary. But if the changes to the file make the phone unusable or cause it to crash, it is more difficult to restore the file. If you use a bind mount, the file will be restored "automatically" at the next reboot.

Notes

see the forum entry How to upgrade the OS with another Android "distribution" for an example usage for this method

See the forum entry How To change any file or directory using Magisk for how to use this method in Magisk module for persisent changes

See the forum entry How to make files in /system writable for another exampe how to use this feature in Magisk

Up to version 25.x of Magisk (at least in Magisk v24.x and v25.x) Magisk mounted the /system/bin directory read-write, so that temporary changes for the files in /system/bin were possible. But because of the more or less not existent free space in the filesystem used for /system the use of this feature was very limited. And this feature does not exist in Magisk v26.x or newer anymore.

(see also this forum message: https://xdaforums.com/t/magisk-general-support-discussion.3432382/page-2815#post-88617909 )