Linux – understanding mount -o bind

linux

Few questions after the following commands:

mount -o bind /new_disk/home/user/ /home/user/

mount -o bind --no-mtab /new_disk/home/user/ /home/user/
  1. What is the difference between the two commands other than " Mount without writing in /etc/mtab. This is necessary for example when /etc is on a read-only filesystem."

  2. What is the difference between mount -o bind and mount –bind …if there are

  3. Let's suppose i don't know there is a partition mounted using -o bind –no-mtab…where can I find if there is any mount point with bind ?
    The only way i can detect this is grep user /proc/mounts but in that line there is no info abut bind.

Thank you.

Best Answer

  1. None.
  2. None.
  3. Hmm, never knew that. You could find duplicate source devices and stat both mountpoints. If inodes differ, you have a bind mount:

    dennis@lightning:/tmp/foo1$ grep uuid /proc/mounts
    /dev/disk/by-uuid/ae2c3836-ea2d-4d0e-8409-75d682889d1f / ext3 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0
    /dev/disk/by-uuid/ae2c3836-ea2d-4d0e-8409-75d682889d1f /tmp/bar1 ext3 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0
    
    dennis@lightning:/tmp/foo1$ stat -c %i /tmp/bar1 /
    1228938
    2
    

    However, if you bindmount one mountpoint to another (e.g. bindmounting / to /tmp/bar1), the inode numbers will be the same. Thus making it impossible to distinguish between a bind-mounted filesytem or a device simply mounted twice.