/etc/mtab vs. /proc/mounts
David M. Lloyd
david.lloyd at redhat.com
Mon Jan 31 12:20:14 PST 2011
On 01/31/2011 02:03 PM, Alan Bateman wrote:
> I think I need help to (re)understand the difference between /etc/mtab
> and /proc/mounts on Linux.
> On Linux, our getFileStores() is implemented to essentially enumerate
> /etc/mtab. That should give a similar list to what df(1) prints although
> the filtering may be slightly different. On the other hand the
> getFileStore method to get the FileStore for where a file is located
> uses /proc/mounts to find the mount point (folks on this list may recall
> the reasons why we switched to using /proc ). Using both leads to at
> least one reported anomaly where it has been observed that getFileStore
> returns a FileStore representing the root file system with both a name
> and type of rootfs but df -T (and getFileStores) report something
> different (/dev/sda1 and ext4 on one system I tried). I'm trying to
> figure if this code should be changed and what the right answer is for
> this case. Any suggestions?
I think you'll find that /proc/mounts returns *both* the rootfs and the
real filesystem mounted atop it (in other words, the mount point can be
The rootfs filesystem type is used as an early bootstrap phase in many
distributions (it replaces the older initramfs IIRC).
That said - /etc/mtab will give you the software's idea of what the
right mounts are. /proc/mounts will give you *everything* that is
currently mounted, even if multiple filesystems are mounted in the same
Using /proc/mounts to get the filesystem is probably *not* the right
approach, at least not by itself, because of the non-uniqueness of
mounts, however it is probably better than /etc/mtab which may have
inaccurate information. You *might* be able to rely on /proc/mounts
ordering though, I'd have to look that up to be sure. If that is the
case then you can use a longest-match-then-latest-match kind of
algorithm and get an accurate result.
Either way I'd recommend not using /etc/mtab as the information source
for either method.
More information about the nio-dev