LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 09-25-2022, 07:04 AM   #1
werain
LQ Newbie
 
Registered: Sep 2022
Posts: 5

Rep: Reputation: 0
Udev monitor does not display any event on If I mount or unmount a partition


I'm observing udevadm monitor to detect when the usb is un-mounted, or partition (USB) is removed.

if the partition /dev/sda1 is mounted at /mnt/mydisk

If I remove the partition /dev/sda1 via physically removing the USB stick. I see remove event appearing on udevadm monitor but if try to just umount the disk /mnt/mydisk.

umount /mnt/mydisk

No event of changes appear in udevadm monitor. Likewise the event for mount also does not show up on monitor

mount /dev/sda1 /mnt/mydisk

Is it even possible to get such changes event in udev.

I have no udev rule laid in /etc/udev/rules.d
 
Old 09-25-2022, 11:17 AM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,665

Rep: Reputation: Disabled
By mounting you are not making any changes to your devices, you are merely starting to use the filesystem laid on it. Therefore it is not an event for udev.
 
Old 09-26-2022, 01:48 AM   #3
werain
LQ Newbie
 
Registered: Sep 2022
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Emerson View Post
By mounting you are not making any changes to your devices, you are merely starting to use the filesystem laid on it. Therefore it is not an event for udev.
Is there by any means possible to get a notification for such behaviour?
 
Old 09-26-2022, 03:21 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,153

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Why do you care ?. Who (what) will be issuing the [u]mount if it's not you ?.

What info do you require ?. Just the fact the command has been issued, the device node involved, the mount point ... ?. How disciplined are the mount-points - always the same, or unpredictable ?. If you are prepared to sit on udevadm, what about polling the mount command to see what has changed ?. Not event notification but might suffice.

inotify might be the best bet, but depends on at least some of the answers above.
 
Old 09-26-2022, 07:54 PM   #5
werain
LQ Newbie
 
Registered: Sep 2022
Posts: 5

Original Poster
Rep: Reputation: 0
Well for starters we are sure about the mount point.


It is required as the running script operates along with the mounted drive, and if for some reason the mounted point is removed, the script should halt.

Polling is an option but it's expensive once hence was vouching on Kernel event msg for a better result.
plus /proc/mount is somewhat unreliable since I have seen occurrences where the USB stick has been physically removed but the associated entry in proc still exists.

ionotify might be the best bet I tried this but its just work over umount I still need a way to know if the partition is mounted at a known path.
 
Old 09-26-2022, 08:16 PM   #6
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,665

Rep: Reputation: Disabled
There is probably gazillion ways to do it, 'mount | grep mountpoint' is one.
 
Old 09-27-2022, 09:01 AM   #7
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
I had a similar problem about a NFS disk that sometimes disappeared. A script wrote some files on it, and when unmounted, the files ended up in the /mnt/diskname folder. I could maybe check the mount points, events or something. But the fast and easy way was to just create a file on the disk. In the writing script, I just checked if that file exist, and if not, send an alert and write somewhere else.

I don't think inotify /proc/mounts will work. It's not a file, so you would have to read it again and again to compare.
 
Old 09-27-2022, 02:18 PM   #8
werain
LQ Newbie
 
Registered: Sep 2022
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Emerson View Post
There is probably gazillion ways to do it, 'mount | grep mountpoint' is one.
Agreed but not evented like netlink . I know its not a big deal but having and evented is way better than polling the mountpoint.

Also I think the latest version of linux have few syscall that monitor this(version >5.10) so it an obvious concern to them. Which also make me believe for linux version less than 5.10 there exist no such feature.
 
Old 09-27-2022, 02:21 PM   #9
werain
LQ Newbie
 
Registered: Sep 2022
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Guttorm View Post
I had a similar problem about a NFS disk that sometimes disappeared. A script wrote some files on it, and when unmounted, the files ended up in the /mnt/diskname folder. I could maybe check the mount points, events or something. But the fast and easy way was to just create a file on the disk. In the writing script, I just checked if that file exist, and if not, send an alert and write somewhere else.

I don't think inotify /proc/mounts will work. It's not a file, so you would have to read it again and again to compare.

If the system is mounted and then its umounted I confirm that Umount event are triggered. Using inotify

Last edited by werain; 09-27-2022 at 02:23 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't unmount -- oops, can't fsck after unmount upnort Slackware 4 05-18-2019 11:41 AM
shutdown tumbleweed: failed to unmount /home; failed to unmount /var JZL240I-U Linux - Software 3 04-03-2017 07:23 AM
Does Linux unmount the root partition when the partition is about 80% full? winger9 Linux - General 5 06-07-2014 04:46 AM
Missing unmount and unmount.cifs johnmccarthy Linux - Newbie 3 11-19-2011 07:01 AM
command 'unmount' not found - how can i unmount??? GloVe Linux - General 1 10-04-2003 06:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration