How to get the complete and exact list of mounted filesystems in Linux?
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?
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.
The definitive list of mounted filesystems is 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
.
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
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
As of version 2.27 there’s also support for JSON
output via -J
or --json
switch:
findmnt -Jo source,target,label,uuid -t ext4
{
"filesystems": [
{
"source": "/dev/nvme0n1p5",
"target": "/",
"label": "ARCH",
"uuid": "f21a53194-b02a-4e92-ad96-fdf9b8bc1db9",
"children": [
{
"source": "/dev/nvme0n1p6",
"target": "/run/media/data",
"label": "DATA",
"uuid": "321e288a-e67c-4b68-8d0b-89720210921f"
}
]
}
]
}
For more details read the man
page (and findmnt --help
to get the list of available columns).
If the mounted source for some reason is no longer accessible (in my case my domain password expired), the mount point directory is empty and (at least for me) the mount no longer shows up in /proc/mount
.
I desperately searched for any such mounts since I suspected there was some mount that frequently tried to access my domain account with old credentials (every few seconds) and thereby frequently locked the account. That´s why I found this question in the first place. But /proc/mounts
was not the solution for me.
I knew I had probably done some mounting from an Ubuntu server with a command like the below, but was unsure of what mount_point_dir
I could have used, since none of my regular mount_points seemed to be mounted.
$ mount.cifs <remotetarget> <mount_point_dir>
I finally found a verification that there actually existed some mounting with authorization problems from the syslog in /var/log/syslog
. I saw a lot of lines in this log with the following statements:
CIFS VFS: Free previous auth_key.response
Status code returned 0xc0000234 STATUS_ACCOUNT_LOCKED_OUT
That confirmed my suspicions and I could then get further confirmation from looking at the Stats and DebugData under the /proc/fs/cifs
folder.
See further information here.
Although I never actually saw the information about the target mount_point_dir
, only the mounted source, this was enough for me to solve my issue, since this motivated me to do a reboot of the server, after which the mounts were gone and also the account locking problem.