Go to Settings Magisk and configure
Mount Namespace Mode at
Global once and for all. In the SuperSU application, turn off
Mount Namespace Separation.
For a one-time solution, use this command instead:
~$ su -mm -c 'mount '
but after a while, the partition is dismounted automatically and I have to remount it.
This behavior is due to Mount Namespace implemented by Android since Android-6 in order to sandbox / isolate applications. In order to control the access of applications to system resources and file systems, in particular SD cards, each application (Dalvik or ART VM that processes the Java bytcode in .dex executable binary) is started by zygote (init process Android) in a new mount namespace where it can independently dismount any filesystem (except rootfs) or remount, without affecting other namespaces. Each process started by the application lives in the same or more isolated namespace.
mnt (mount) and
net Namespaces (network) are enabled on the default Android kernel. Other namespaces
uts can be activated by rebuilding the kernel.
NAME OF THE WORLD
The first process launched by the kernel on startup: init with all kernel processes (kworkers, etc.) and other init daemon processes (such as ueventd, logd, servicemanager, vndbinder, mediaserver, netd, etc.) Global namespace / root. When we install mods (such as Magisk, Xposed, etc.), they also start as processes in a root namespace, usually at the initial stage of the boot process.
Android file systems (real or pseudo; / system, / data, / proc, etc.) are also initially mounted in a global namespace. The namespace of an application has all mounts (including rootfs) set to
slave, so that any new editing inside them in the root namespace, spreads to the namespace of the application but not the only one. reverse. See the mounting propagation.
lsns can be used to see all namespaces. Mount namespace can be created by
unshare -m. To enter a namespace,
nsenter is an easily available SETNS wrapper. In most cases, these commands do not work without root privileges.
SUPER USER AND MOUNT NS
When we run
su command in a terminal emulator application, a new process (shell) is launched with high capabilities. This process lives in the same mount namespace as that of the Terminal application. Therefore the
mount This command is also run in the same namespace, and the file system is visible only in this namespace. Once we
exit this shell, mount point will not show the contents of the file system. If there is no process running in a namespace, it is automatically cleaned up.
Please note that an application is completely destroyed when its Dalvik process is killed by Force Stop or by the management of the Android memory.
If the Terminal application has not been completely killed,
su can enter the same namespace, only when
Inherited Namespace This option is enabled in Magisk.
Isolated Namespace will always create a new mount namespace.
I now come to your question:
Even when it is mounted, the content is not visible in file explorer applications such as MiXplorer and ES Explorer, and is visible only in the terminal.
Indeed, the explorers (applications) run in their own namespaces montage. Run this command as root to get an overview:
~# ps f -p2 --ppid 2 --deselect -o mntns,pid,cmd --sort=mntns
You can use Termux for a full version of
When I configure this command to run at boot time by putting the init.d directory in / etc, it works normally and the ext4 partition does not unmount automatically.
Indeed, the init.d script is executed by
init in a global namespace.
So, what is the best way to mount an ext4 partition in Android persistently and what is the reason for such behavior?
To escape the puzzle, always mount file systems that you frequently access in Global Mount Namespace (although he is vulnerable to security vulnerabilities) unless necessary. A simple check if we are in a global namespace:
~# ( "$(readlink /proc/self/ns/mnt)" = "$(readlink /proc/1/ns/mnt)" ) && echo 'In Global NS.' || echo 'Not in Global NS.'
NOTE: This test only works in the initial NS PID.
Another possibility is to create a namespace with
unshare -m --propagation shared. From now on, all new edits in this namespace will propagate to all namespaces. But this does not apply to the namespaces of already created applications.
mount --make-rshared / does not work (at least for me) if the namespace was originally created with
See this thread for more details.