How to find original directory in case of bind mount?

  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    Android Linux
Click For Summary
The discussion revolves around the use of bind mounts in Android, leveraging its Linux foundation. A user successfully created a bind mount from an SD card directory to internal storage on a rooted Android device, confirming the operation with the mountpoint command. The user then sought to identify the original directory of a bind mount and found that using the mount command with grep effectively revealed the source directory. The conversation shifted to Samsung's implementation of bind mounts for social media app data storage, where the user encountered unexpected output related to "libunionfs." It was clarified that libunionfs is not a directory but a virtual filesystem type, which complicates traditional bind mounting. The discussion also touched on the risks of operating as a root user and suggested using VirtualBox for practicing Linux commands safely. Overall, the thread highlights practical applications of Linux commands in Android and the complexities of virtual filesystems.
Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,180
Reaction score
2,721
I was trying out the Linux concept bind mount in Android. As everyone knows, Android is developed on Linux framework. I have a rooted phone, and also a terminal emulator with a busybox that supports most of the important Linux commamds.

I ran the following commands:
Code:
$su
#cd /storage/emulated/0
#mkdir Books
#mount -o bind /storage/6333-6461/Books ./Books
#mountpoint Books
Here, 6333-6461 is my sd card, and emulated/0 is the internal storage as usual. su is the same as sudo in linux.

The bind mount was successful as mountpoint returned a positive result, and I could see the effect in my file browser.

Now, what if I wanted to view the original directory of the bind mount? That is, if I were given the directory Books in /storage/emulated/0, how can I figure out that it's original directory is /storage/6333-6461/Books? What Linux command(s) will help me do this? (If you tell me the solution in Linux, I will try it out in Android.)
 
Technology news on Phys.org
The mount command with no arguments should show you all active mounts, including what is mounted (which will be the original directory in your case) and the mount point. If you want just the one mount you're interested in, you can grep the output to get just the relevant line.
 
Thanks @PeterDonis. I ran the command #mount |grep -i books, got an output, and it worked.
Code:
/mnt/media_rw/6333-6461 /storage/emulated/0/Books sdcardfs rw,seclabel,nosuid,nodev,noexec,relatime,low_uid=1023,low_gid=1023,gid=1015,mask=0006 0 0
/mnt/media_rw/6333-6461 /mnt/runtime/default/emulated/0/Books sdcardfs rw,seclabel,nosuid,nodev,noexec,relatime,low_uid=1023,low_gid=1023,gid=1015,mask=0006 0 0
The first directory in each line is the original directory, the second is its bind mount.

Now, Samsung has devised a system in the stock ROM such that any data saved by social media apps can be linked to a folder in SD card, whereby space will be saved in internal storage. I am sure that this is done by bind mount; I ran mountpoint on the probable 4 directories and they indeed are mount points. But I get a strange output when I run #mount |grep -i whatsapp:
Code:
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
The second directory in each line is the bind mount. I had checked these four with mountpoint previously. But what directory is libunionfs? I can't find it with a cd libunionfs command. mount | grep libunionfs returns the same output as above.
 
Wrichik Basu said:
what directory is libunionfs?

It's not a directory, it's a virtual file system type.

The first item in each line of the output of mount is not a "directory"; it's a source filesystem or filesystem type. If the source filesystem happens to have a defined directory location, that's what will appear; but not all source filesystems do. For example, the "proc" directory tree on a Linux system let's you see various parameters for active processes; in the mount output, the first item on that directory tree's output line is just "proc" since the source filesystem in this case is not a directory anywhere, it's just the kernel's process info.
 
  • Like
Likes Wrichik Basu
PeterDonis said:
It's not a directory, it's a virtual file system type.
Interesting. If it's a virtual file system, how can I bind mount some directory to it? Normal mount -o bind didn't work.

Sorry if the questions are too trivial; I am new to Linux file systems.
 
Wrichik Basu said:
If it's a virtual file system, how can I bind mount some directory to it?

The virtual filesystem mounts are not bind mounts. There might be a different way to mount them using other options to the mount command, but I've never done that and am not familiar with it.
 
  • Like
Likes jim mcnamara
FWIW - if you are not well acquainted with UNIX, being a root user is a really terrible idea. Your question kind of points to that. Get an old windows box and throw a linux distro onto it. Back it up completely. First. Then play.
 
jim mcnamara said:
Get an old windows box and throw a linux distro onto it.

A Windows box? Surely you jest. o_O

You can set up a virtualbox on a linux machine to run another linux distro in a virtual machine.

https://en.wikipedia.org/wiki/VirtualBox
 
  • #10
jim mcnamara said:
FWIW - if you are not well acquainted with UNIX, being a root user is a really terrible idea. Your question kind of points to that. Get an old windows box and throw a linux distro onto it. Back it up completely. First. Then play.
PeterDonis said:
You can set up a virtualbox on a linux machine
I generally practice on VirtualBox before trying out things on the phone.