Subject: df: detection of overmounted filesystems is not quite complete

From: Alan Jenkins <[email-masked]>
Date: Mon, 2 Oct 2017 13:27:02 +0100

Scenario 1 - lovely diagnostic

$ df -h /dev/sda1
df: cannot access '/dev/sda1': over-mounted by another device

$ mount | grep boot/efi
/dev/sda6 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sda1 on /boot/efi type vfat 
(rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)
none on /boot/efi type tmpfs (rw,relatime,seclabel)

Scenario 2 - breaks down

$ df -h |grep /dev/sda1
$ df -ah |grep /dev/sda1
/dev/sda1                             -     -     -    - /boot/efi

above is consistent (same output as in scenario 1), but below is bad:

$ df -h /dev/sda1  # or same output  from `/boot/efi`
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       3.9G     0  3.9G   0% /boot/efi

Case 2 situation is as follows:

$ mount | grep boot
/dev/sda6 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sda1 on /boot/efi type vfat 
(rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)
none on /boot type tmpfs (rw,relatime,seclabel)

i.e. the tmpfs on /boot is the most recent mount, masking the /boot/efi 
mount (and I created a dummy `/boot/efi` directory in the tmpfs).

The practical use-case is that people get very confused when their 
distribution sets up pam_ecryptfs.  If `df` was more reliable about 
detecting overmounts, then it would provide better diagnostics for when 
pam_ecryptfs overmounts a filesystem which was mounted by fstab.

https://unix.stackexchange.com/questions/370043/mounting-a-subdirectory-of-home-onto-an-own-partition-confuses-disk-usage-report/395630?noredirect=1#comment706009_395630