5

I have a partition, /dev/sdb1, that gets mounted at /data. In /etc/fstab I have:

/dev/sdb1           /data           ext4  defaults  1 2

After that partition gets mounted, I then have the following bind mounts:

/data/backups/f17/opt   /opt            none  rw,bind   0 0
/data/backups/f17/home  /home           none  rw,bind   0 0
/data/var/www/html      /var/www/html/  none  rw,bind   0 0

All the mounting is done just fine.

The problem is that when I run df, the only entry I get relating to sdb1 points to "/opt", not "/data".

e.g.:

/dev/sdb1   240233144 196081648 31925236 86% /opt

I expect/want df to show the original mount point, that is /data, instead of /opt. Or at the very least, show all the mount points related to sdb1. If I umount the /opt bind mount point, then df happily shows /data (even though the other two bind mounts are still mounted, strangely).

There is no difference in behavior if I do the mounting commands in the terminal (vs letting the system do it via mount -a, which uses /etc/fstab).

I know I can use something like findmnt --df to get a better picture of all mounted filesystems, but I want to use df (and I don't want to alias df to anything else).

  • Fedora 21
  • kernel 3.19.3-200.fc21.x86_64
  • df (GNU coreutils) 8.22
  • mount from util-linux 2.25.2

thanks.

UPDATE
(adding more information)

The file /proc/mounts shows all four mount points:

/dev/sdb1 /data ext4 rw,relatime,data=ordered 0 0
/dev/sdb1 /var/www/html ext4 rw,relatime,data=ordered 0 0
/dev/sdb1 /home ext4 rw,relatime,data=ordered 0 0
/dev/sdb1 /opt ext4 rw,relatime,data=ordered 0 0
  • Perhaps it shows the shortest mountpoint? What are the contents of /proc/mounts and /etc/mtab (if the latter is not a symlink to the latter)? – wurtel Apr 9 '15 at 14:33
  • /etc/mtab is a link to /proc/self/mounts. /proc/mounts shows all 4 entries, will add to post. – atreyu Apr 9 '15 at 16:28
4

A bind mount is equivalent to the original. There isn't one that's marked as the original and one that's marked as a copy. Bind mounts are like hard links in this respect, not like symbolic links.

Since GNU coreutils 8.21 (if I read the changelog correctly), df strives to report each filesystem only once. Older versions included one entry per non-ignored mount point, so a bind mount would result in multiple entries. df shows the latest mount point for each filesystem, as far as it can determine. In your case, df reports /opt, not /data, because /opt was added last.

Pass the option -a to get even recent coreutils to report all entries for each filesystem. This also causes filesystems that would normally be ignored to be listed, if you don't pass a path argument. If you do pass a path argument, I think df never reports anything but the latest mount point.

If you don't want to alias df to something else, you'll either have to replace df by a custom implementation or have to live with df reporting something different from what you'd like. If you need the earliest mount point rather than the latest one, a sane solution would be to call df -a and retain only the first match for the device that you're interested in.

  • Thanks, Gilles, df -a will suffice. – atreyu Apr 10 '15 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.