How to find original directory in case of bind mount?

In summary, the bind mount worked, and I was able to figure out the original directory of the bind mount by running the mount command and greping for books.
  • #1
Wrichik Basu
Science Advisor
Insights Author
Gold Member
2,116
2,691
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
  • #2
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.
 
  • #3
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.
 
  • #4
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
  • #5
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.
 
  • #6
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
  • #8
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.
 
  • #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.
 

1. How do I determine the original directory in a bind mount?

In order to find the original directory in a bind mount, you can use the "mount" command in the terminal. This will show you all the mounted filesystems and their corresponding mount points. The original directory will be listed under the "Source" column.

2. What is a bind mount and how does it work?

A bind mount is a type of mount in Linux that allows you to mount a directory from one location to another. It essentially creates a link between two directories, so any changes made to one directory will be reflected in the other. This is useful for sharing data between different locations.

3. Can I use a bind mount to access files from a different filesystem?

Yes, you can use a bind mount to access files from a different filesystem. However, both filesystems need to be mounted on the same system in order for the bind mount to work.

4. How do I create a bind mount?

To create a bind mount, you can use the "mount" command with the "-o bind" option. For example, "sudo mount -o bind /path/to/source /path/to/destination". This will create a bind mount from the source directory to the destination directory.

5. Is it possible to view all active bind mounts on my system?

Yes, you can view all active bind mounts on your system by using the "mount" command without any options. This will show you all the mounted filesystems, including any bind mounts that may be active.

Similar threads

Replies
16
Views
2K
  • Computing and Technology
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
Back
Top