Search code examples
linuxmountprocfs

Ordering of /proc/mounts and /etc/mtab


Does anyone know whether /proc/mounts is guaranteed to be in the order in which devices are mounted?

For instance:

[root@machine proc]# cat /proc/mounts 
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,data=ordered 0 0
/dev /dev tmpfs rw 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
devpts /dev/pts devpts rw 0 0
/dev/sda1 /boot ext3 rw,data=ordered 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/root /boot ext3 rw,data=ordered 0 0

In the above case, can I be sure that /boot will currently show /dev/root rather than /dev/sda1, which is currently hidden.

I'm guessing the same answer should be true of /etc/mtab.

I'm on RHEL 5.5.


Solution

  • The mount points in /proc/mounts are in mounted order. If you mount a new file system it gets appended to the list of filesystems, essentially obscuring the original mount point.

    There are absolutely no guarantees about the content of /etc/mtab, it is purely managed by the userland mount command, so can be bypassed or rewritten arbitrarily, plus you can use the '-n' option to mount will actually omit placing entries in the /etc/mtab, thus making it incorrect relative to the kernel.

    As a silly question, why do you need this information?