How to bind mount libunionfs? Samsung has introduced a feature in its stock ROM that moves content of social media aps (like WhatsApp) to SD card, and then links the two folders.

I ran the following command in Termux:

$su
#mount | grep -i "whatsapp"


The following output was returned:

libunionfs /mnt/runtime/default/emulated/0/WhatsApp fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
libunionfs /storage/emulated/0/WhatsApp fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
libunionfs /mnt/runtime/read/emulated/0/WhatsApp fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
libunionfs /mnt/runtime/write/emulated/0/WhatsApp fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0


I learnt from the net that libunionfs is a virtual file system. How did Samsung create bind mounts to this system? Normal #mount -o bind didn't work.
UnionFS does not bind-mounts, it's an independent in-kernel filesystem itself (though there is also unionfs-fuse). Bind-mount and UnionFS have different uses but can be considered alternative to each other in certain situations. So is OverlayFS and other similar implementations. These are stackable unification filesystems which unify the contents of two different directories. Files in lower directory are overlapped by files of same names in upper directory. All other files in lower directory are visible as normal files. A bind mount on the other hand completely overlays the contents of lower directory. Also see How does UnionFS work?

From your comment:


  The problem is, Termux says "no such device" if i use the option none in the mount command. How do i mention my phone as the device where mount should be done?


Yours seems to be FUSE based UnionFS (just the name, not related to actual in-kernel UnionFS). Android's storage framework works by dynamically changing file permissions depending on the privileges of apps accessing the files, which requires a phenomenon like FUSE or sdcardfs to set pseudo permission modes. FUSE mounts don't work by simply using mount command. You need a specific program which communicates to kernel through /dev/fuse and mounts the Filesystem in UserSpacE (FUSE). Mount is tied to that program.

I don't know exactly what's the executable name Samsung is using for FUSE mounts, you can see your running processes to find the executable binary. Then use that specific program by passing the required arguments, ownership, mode, SELinux context, source and destination directories.

However most probably the implementation would only be in a shared library to be accessed from Android framework. In that case you have to use some third party programs like unionfs-fuse. If you only want bind mount with correct permissions bindfs can also be used. For details see How to bind mount a folder inside /sdcard with correct permissions?

If you want real UnionFS, you'll have to rebuild kernel (probably with some patches). OverlayFS is a better choice, it's a part of mainliene Linux kernel (should've been built with CONFIG_OVERLAY_FS). You may ask a question if details required on a specific use case on Android. But that would be far more complicated to set up than a FUSE-based solution.