6

Same partition mounted twice, showing a different content on each mountpoint. How is that possible ?

# mkdir /mnt/tmp
# mount -t ext4 -o noatime /dev/block/sda1 /mnt/tmp/

# mount | grep sda1
/dev/block/sda1 on /data type ext4 (rw,seclabel,noatime)
/dev/block/sda1 on /mnt/tmp type ext4 (rw,seclabel,noatime)

# ll /data
drwx------  2 root     root       4096 2021-08-19 18:34 adb
drwxrwxr-x  2 system   system     4096 2021-08-19 18:34 anr
drwxrwx--x  8 system   system     4096 2021-08-21 22:42 app
(...)
drwx--x--x  2 system   system     4096 2021-08-19 18:34 user
drwx--x--x  3 system   system     4096 2021-08-19 18:34 user_de
drwxrwx--x  3 root     root       4096 2021-08-19 18:34 vendor

# ll /mnt/tmp/                                                    
drwxr-xr-x 3 root root 4096 2021-08-19 18:33 android-8.1-r6
drwxr-xr-x 2 root root 4096 2021-08-19 18:33 grub
drwx------ 2 root root 4096 1970-01-01 01:00 lost+found

The same partition, /dev/block/sda1, is mounted twice, and each mountpoint (/data and /mnt/tmp) shows a different content.

Background : I wanted to modify GRUB's menu.lst file, and in android-x86 it appears that file is only available from withing GRUB's debug mode, or from android itself by mounting /dev/block/sda1. I did that, and indeed I could then access menu.lst (/mnt/tmp/grub/menu.lst), but how this works, and why /dev/block/sda1 shows a different content depending on the mountpoint is beyond me !

[ EDIT : answer given by user488112 below ]

It appears /data is in fact mounted on /android-8.1-r6/data, a sub-directory of /dev/block/sda1, and not on the "root" of dev/block/sda1. # mount is incomplete (it only shows the device block, not the "root" of the mount) :

# egrep '/data|/mnt/tmp' /proc/self/mountinfo                         
18 15 8:1 /android-8.1-r6/data /data rw,noatime shared:3 - ext4 /dev/block/sda1 rw,seclabel
237 28 8:1 / /mnt/tmp rw,noatime shared:23 - ext4 /dev/block/sda1 rw,seclabel
2
  • maybe you monted the /mnt one after /mnt has already somthing mounted in ? or maybe the /mnt/tmp mounted is not syncronized if so try sync your cache ; and then try again ls
    – francois P
    Aug 23, 2021 at 10:54
  • @francoisP : I added some more tests. /mnt is indeed already mounted, as tmpfs. # sync didn't change nothing. I think it's probably android-x86 specific, but how ???
    – ChennyStar
    Aug 23, 2021 at 11:10

1 Answer 1

7

Here's how:

# cd /tmp
# mkdir foo bar
# mount -B /usr/bin foo
# mount -B /var/log bar
# mount | egrep 'foo|bar'
/dev/sda1 on /tmp/foo type ext4 (rw,relatime,errors=remount-ro)
/dev/sda1 on /tmp/bar type ext4 (rw,relatime,errors=remount-ro)

tl;dr; the output of the mount command is not reliable on modern versions of Linux. Use cat /proc/self/mountinfo instead (the format is documented in man 5 mountinfo), which is also showing the "root" of the mount, not just its "device":

# egrep 'foo|bar' /proc/self/mountinfo 
380 26 8:1 /usr/bin /tmp/foo rw,relatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro
457 26 8:1 /var/log /tmp/bar rw,relatime shared:1 - ext4 /dev/sda1 rw,errors=remount-ro
3
  • 1
    Yep, that's it. I didn't know that mount was unreliable. I updated my original question to add the result of egrep '/data|/mnt/tmp' /proc/self/mountinfo. Thanks
    – ChennyStar
    Aug 23, 2021 at 11:50
  • 1
    @ChennyStar Or simply use findmnt instead. Aug 23, 2021 at 19:59
  • 2
    @Roman : yes, findmnt is accurate too. Btw man mount recommends the us of findmnt : [mount] is maintained for backward compatibility only. For more robust and customizable output use findmnt, especially in your scripts.. But note that findmnt is not always available (specifically it's not available in android-x86, on which I did my tests, even with busybox installed). Whereas egrep ... /proc/self/mountinfo seems to work everywhere
    – ChennyStar
    Aug 24, 2021 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .