大网数据广告活动
服务器运维问答

Linux: same device mounted on differences mount points

· 52CE 我爱测

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/foob…

问题原文

原帖链接 · el.pescado - нет войне · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · iwaseatenbyagrue · CC BY-SA 3.0

/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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。