4

When I used INotify with /etc/mtab or /proc/mounts, it doesn't detect changes when things mount or unmount, even though /etc/mtab and /proc/mounts both have changed when I check manually. Why is this, and how can I track mounting and unmounting things?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
PyRulez
  • 636
  • 1
  • 6
  • 19
  • The duplicate is alsa-themed so not an exact match, but it does answer the question of why `inotify` doesn't work under `/proc`. As supplementary information, there is no alternate interface that I know of that will fire events that you can subscribe to when filesystems are mounted and unmounted. I've searched for it before. – Celada Mar 05 '16 at 21:45
  • 1
    ```stat /etc/mtab``` will tell you why the other answer is completely relevant – Shawn J. Goff Mar 06 '16 at 00:14

1 Answers1

5

From the inotify man page:

various pseudo-filesystems such as /proc, /sys, and /dev/pts are not monitorable with inotify.

and /etc/mtab is often just a link to /proc/mounts these days. You can use udisksctl monitor to see mounts happen, or set your own /etc/udev/rules.d/ rule file to run a program when a new device is added (before any mount), or run dbus-monitor to see mount events pass on that bus. All a bit complicated.

meuh
  • 49,672
  • 2
  • 52
  • 114