/etc/mtab vs. /proc/mounts

David M. Lloyd david.lloyd at redhat.com
Tue Feb 1 02:49:41 PST 2011


On 02/01/2011 01:50 AM, John Hendrikx wrote:
> David M. Lloyd wrote:
>> 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 [1]). 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 non-unique).
>>
>> 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 spot.
> Not sure what you mean by that, but if I mount two ISO images on the
> same spot (say /iso-image), both of the mounts show up in /etc/mtab,
> /proc/mounts and in df, even though only one is accessible. See here:
>
> # cat /etc/mtab
> (...)
> /temp/debian.iso /iso-image iso9660 rw,loop=/dev/loop1 0 0
> /temp/ubuntu.iso /iso-image iso9660 rw,loop=/dev/loop2 0 0
>
> # cat /proc/mounts
> (...)
> /dev/loop1 /iso-image iso9660 ro,relatime 0 0
> /dev/loop2 /iso-image iso9660 ro,relatime 0 0
>
> # df
> Filesystem 1K-blocks Used Available Use% Mounted on
> (...)
> /temp/debian.iso 1527898 1527898 0 100% /iso-image
> /temp/ubuntu.iso 1527898 1527898 0 100% /iso-image
>
> Note that only the last one mounted is accessible.

Sure.  My point is that mtab contains whatever the mount command puts in 
there.  /proc/self/mounts contains *everything* (it comes from the 
kernel, as opposed to a userspace program).

-- 
- DML


More information about the nio-dev mailing list