Смотрим точки монтирования в Linux
Известное отличие Linux от Windows заключется в предоставлении пользователям возможности прозрачно управлять монтированием разделов диска. В свою очередь жто дает право управлять гибким образом настроить структуру каталогов, использовать несколько файловых систем, где каждая будет выполнять свое предназначение.
Точка монтирования — что это?
Для понимания термина точки монтирования достаточно ознакомиться с аналогией. Представим большое поле, на котором вы желаете высадить овощи. Но потребность есть не в одном, а нескольких сортах, например, картофеля. Чтобы реализовать задачу, поле необходимо поделить на участки, на каждом из них высадить нужный сорт. Когда приходит время собирать урожай, независимо от сорта, картошку следует выкопать и вывезти, а к полю идёт только одна дорога и вся полученная картошка будет вывезена именно по этой дороге. То есть тоже независимо от того, с какого участка был собран урожай.
Теперь перейдем ближе к делу. Допустим, у вас есть один объемный жесткий диск, на который надо записать данные. Фактически это и есть наше поле. Но нужна файловая система без журналирования для каталога /boot, отдельная файловая система для корня и для /home. Поэтому жесткий диск разбивается на разделы. Дальше эти разделы подлежат форматированию в нужную файловую систему. Как на примере различных сортов картофеля. Процесс монтирования это и есть дорога, по которой картофель вывозят с участка. На каком бы из разделов не находились данные, получить к ним доступ можно только с помощью корневого каталога /. Все разделы монтируются сюда, если не к самому корню, то в одну из папок. Такая папка и называется точкой монтирования и её содержимое во время монтирования заменяется на содержимое раздела.
Смотрим точки монтирования
Для просмотра точек монтирования необходимо использовать следующую команду:

С появлением snap и flatpack точки монтирования Linux засорены монтированием различных snap пакетов и их содержимого к файловой системе. Однако здесь можно разобрать и смонтированные жесткие диски. Чтобы отфильтровать только жесткие диски используйте программу grep:

Таким образом можно не просто посмотреть, но и настроить точки монтирования можно с помощью файла /etc/fstab.
How to find out mount/partition a directory or file is on? (Linux Server) [closed]
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago .
Is there a Linux command to easily find out which partition/mount a directory or file is on?
(This is probably a RTM question, and I feel guilty for asking it, but somehow, I can’t find a good answer on google just yet..)
Как посмотреть точки монтирования Linux
Одно из самых заметных отличий Linux от Windows, это то, что операционная система позволяет пользователям прозрачно управлять монтированием разделов диска. Это позволяет гибким образом настроить структуру каталогов, использовать несколько файловых систем, где каждая будет выполнять свое предназначение.
Благодаря такой возможности, вы можете переустановить операционную систему и не потерять пользовательские файлы, обращаться к параметрам ядра с помощью каталогов /proc и /sys, а к блочным устройствам с помощью каталога /dev. В этой статье мы разберемся что такое точки монтирования, а также как посмотреть точки монтирования в Linux.
Что такое точки монтирования в Linux?
Чтобы понять как тут всё происходит, давайте проведём аналогию. Допустим, у вас есть большое поле и вы на нём хотите посадить картошку. Но выращивать вы хотите несколько сортов. Поэтому вы делите поле на несколько участков и на каждом из них садите нужный сорт. Когда приходит время собирать урожай, независимо от сорта картошку надо выкопать и вывезти, а к полю идёт только одна дорога и вся полученная картошка будет вывезена именно по ней не зависимо от того, с какого участка она была собрана.
Допустим, у вас есть один большой жесткий диск, на который надо записать данные. Это наше поле. Но вам надо файловая система без журналирования для каталога /boot, отдельная файловая система для корня и для /home. Поэтому жесткий диск разбивается на разделы. Дальше эти разделы надо отформатировать в нужную файловую систему. Это аналогия сорта картошки. А монтирование — это аналогия дороги, по которой картошку вывозят с поля. На каком бы разделе диска или части оперативной памяти не располагались данные, получить к ним доступ вы сможете только с помощью корневого каталога /. Все разделы монтируются сюда, если не к самому корню, то в одну из папок. Такая папка и называется точкой монтирования и её содержимое во время монтирования заменяется на содержимое раздела.
Как посмотреть точки монтирования?
Для просмотра точек монтирования можно использовать команду mount. Её надо запустить без параметров:

С появлением технологии snap и flatpack, точки монтирования Linux слегка засорены монтированием различных snap пакетов и их содержимого к файловой системе, но всё же здесь можно разобрать и смонтированные жесткие диски. Чтобы отфильтровать только жесткие диски используйте утилиту grep:
mount | grep ^/dev

Не только посмотреть, но и настроить точки монтирования можно с помощью файла /etc/fstab. Здесь перечислены все разделы диска, которые монтируются к системе.

Более подробно о его настройке я писал в этой статье.
Выводы
Из этой статьи вы узнали что такое точки монтирования Linux, а также как их посмотреть и настроить. А что вы думаете по поводу них? Удобнее ли это чем в Windows? Напишите в комментариях!
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?
5 Answers 5
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 .
![]()
As of v. 2.18 (July 2010) util-linux includes a tool that allows you to display a list of currently mounted file systems:
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.
As of version 2.27 there’s also support for JSON output via -J or —json switch:
For more details read the man page (and findmnt —help to get the list of available columns).
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.
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 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:
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:
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.
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.
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:
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.