Linux: same device mounted on differences mount points

linuxmount

I have a system with following /etc/mtab:

/dev/disk/by-label/foobar /etc/somefile ext4 rw,relatime,data=ordered 0 0
/dev/disk/by-label/foobar /var/lib/somedir ext4 rw,relatime,data=ordered 0 0
/dev/disk/by-label/foobar /mnt/foobar ext4 rw,relatime,data=ordered 0 0
/dev/disk/by-label/foobar /mnt/foobar/somedir ext4 rw,relatime,data=ordered 0 0

i.e. the same device mounted in different mount points. What's more:

  1. Those directories have different contents (this precludes mount --bind case)
  2. Some of those mount points are regular files

Strangely enough, df -h shows only one of those mount points:

/dev/disk/by-label/foobar    2.8G   70M  2.6G   3% /mnt/foobar

How is this possible? What's going on?

Best Answer

/etc/mtab is showing the result of using bind mounts, is my guess. You can bind mount any directory, and I suspect you are seeing the result of that.

$ mkdir test/ /tmp/test
$ sudo mount --bind test/ /tmp/test
$ cat /proc/mounts
<..snip...>
/dev/root /tmp/test ext4 rw,noatime,data=ordered 0 0

This question provides a more in-depth explanation/example: https://unix.stackexchange.com/questions/128471/determine-what-device-a-directory-is-located-on

df -h is not showing these because bind mounts are 'dummy' filesystems, and df requires -a to show those.

Related Topic