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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 48 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
    
What's the point of mount maintaining /etc/mtab if it can't be relied upon? Wouldn't it be better if mount presented information from /proc/mounts instead? – Piotr Dobrogost Feb 12 '15 at 10:31
    
@PiotrDobrogost /etc/mtab can record information that the kernel doesn't track, such as the options originally requested, and bind mounts appearing as such instead of appearing as duplicate entries for devices. Nonetheless many distributions are moving towards making /etc/mtab a symlink to /proc/mounts. – Gilles Feb 12 '15 at 10:41
1  
Nonetheless many distributions are moving towards making /etc/mtab a symlink to /proc/mounts. Good to hear – adding this information to answer would make it even better. Do you think tracking requested options by the kernel would be feasible and beneficial? – Piotr Dobrogost Feb 12 '15 at 11:13
2  
Note that you'll need to un-escape the contents of /proc/mounts. As described on the getmntent(3) page, space (\040), tab (\011), newline (\012) and backslash (\134) need to be handled specially. Especially if user mounts are enabled, you'll need to be very careful when working with these paths. – Eric Aug 31 '15 at 15:50
    
Hi, I see a mount point in the list, although it is old line and there is not real mount there, how can it be ? – ransh Sep 10 '15 at 5:40

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

As of v. 2.18 (July 2010) util-linux includes a tool that allows you to display a list of currently mounted file systems:

findmnt

You can switch from the default tree view to list view with -l, define output columns with -o (similar to lsblk), filter results based on filesystem type with -t etc...

findmnt -lo source,target,fstype,label,options,used -t ext4
SOURCE    TARGET      FSTYPE LABEL OPTIONS                           USED
/dev/sda1 /           ext4   ARCH  rw,noatime,discard,data=ordered  17.6G
/dev/sdb2 /media/DATA ext4   DATA  rw,noatime,discard,data=ordered    44M

For more details read the man page (and findmnt --help to get the list of available columns)

share|improve this answer

Maybe because it has been 5 years since this question was answered things have changed. The cat /proc/mounts creates a lot of info you do not care about. Today, IMHO, I find this to be the ultimate solution.

df -h --output=source,target

when you read the man pages there are all kinds of options you can do but this is what you what. For example to clean up the results even more you can exclude file types of "tmpfs" with this command:

df -hx tmpfs --output=source,target

df works on the filesystem level and not the file level.

The commands above will include network mounts as well.

To see a little more information use this:

df -hT

NOTE With slow mounted network connections this can take several minutes!

If you don't have or care about mounted network connections (and you have root permissions) than this is even better:

sudo lsblk -f
share|improve this answer
    
You don't have to be root but some of the fields/columns (such as Label) will have null data, which might still be okay in that the questions wants to know what filesystems are mounted. – Rick Feb 18 at 23:55
    
Ubuntu. However I just discovered "findmnt" that doesn't use root and it lists network mounted filesystems. I was thinking of editing my answer to include that knowledge. – Rick Feb 19 at 0:03
    
:-) I tired to give your answer a vote but can't until I have a rep of 15+ – Rick Feb 19 at 0:07
    
Btw, if you're trying to use --output with something like Ubuntu 12 which doesn't accept those options, check out don_crissti's findmnt answer below which does. – Mat Schaffer Jun 8 at 2:36
    
findmnt seems to need higher capabilities (tested with root; root has all capabilities) to display labels. – richard 2 days ago

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.