Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I usually use mount to check which filesystems are mounted. I also know there is some connection between mount and /etc/mtab but I'm not sure about the details. After reading How to check if /proc/ is mounted I get more confused.

My question is: How to get the most precise list of mounted filesystems? Should I just use mount, or read the contents of /etc/mtab, or contents of /proc/mounts? What would give the most trustworthy result?

share|improve this question
2  
You should also read the accepted answer to this question: unix.stackexchange.com/questions/12040/… –  nozimica Nov 8 '11 at 20:21

2 Answers 2

up vote 17 down vote accepted

The definitive list of mounted filesystems in in /proc/mounts.

If you have any form of containers on your system, /proc/mounts only lists the filesystems that are in your present container. For example, in a chroot, /proc/mounts lists only the filesystems whose mount point is within the chroot. (There are ways to escape the chroot, mind.)

There's also a list of mounted filesystems in /etc/mtab. This list is maintained by the mount and umount commands. That means that if you don't use these commands (which is pretty rare), your action (mount or unmount) won't be recorded. In practice, it's mostly in a chroot that you'll find /etc/mtab files that differ wildly from the state of the system (also mounts performed in the chroot will be reflected in the chroot's /etc/mtab but not in the main /etc/mtab). Actions performed while /etc/mtab is on a read-only filesystem are also not recorded there. The reason why you'd sometimes want to consult /etc/mtab in preference to or in addition to /proc/mounts is that because it has access to the mount command line, it's sometimes able to present information in a way that's easier to understand; for example you see mount options as requested (whereas /proc/mounts lists the mount and kernel defaults as well), and bind mounts appear as such in /etc/mtab.

share|improve this answer

Most of the time, mount is the most convenient method. For a complete and exact list of currently mounted filesystems, you should read the contents of /proc/mounts (e.g., with cat /proc/mounts).

For example, if mounting / readwrite failed and it was then mounted readonly as a fallback, /etc/mtab (which the mount command reads from to tell you what's mounted, and writes to--if it can--when it changes what is mounted) would not be updated to reflect that / (which contains /etc/mtab) is currently mounted readonly. In this situation, running mount would typically tell you (incorrectly) that / was mounted readwrite.

Under normal conditions (i.e., when the filesystem that contains it can be written to), /etc/mtab contains a list of currently mounted filesystems. This is not to be confused with /etc/fstab, which contains a list of filesystems that are supposed to get mounted automatically when the system starts up.

Of course, if the /proc virtual filesystem is itself not mounted, then you cannot read any of the virtual files in it, which would include /proc/mounts. This very rarely is the case. In this situation, mount is probably your best option for seeing what's mounted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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