is there a way to provide post-mount and pre-umount scripts in Linux?
I am trying to do some scripts on storage media when mounted and before umounting (eg, for synching).
Any help appreciated.
feedback
|
This question came from our site for system administrators and desktop support professionals.
|
you could write a udev rule to do that. I have used something like this for automatically backing up stuff to a usb drive. Fun stuff. | |||
|
feedback
|
|
You can probably use the inotify kernel hook, although a pre-unmount event may be really tricky to catch as I'm not sure if there is an inotify event sent before the directory is umounted. | |||
|
feedback
|
|
If you are trying to do this for people invoking the /sbin/mount and /sbin/umount command, all you'd have to do is make a wrapper program for both and program what you want into these wrapper programs. A wrapper program being replace the /sbin/mount with the wrapper program that calls the real /sbin/mount (renamed to something like /sbin/mount-real or /sbin/umount-real). To prevent anybody from calling the real program, use group permissions to restrict it and set the SGID bit on the wrapper programs. If you are looking to fix the mount(2) library call, well that is an effort and probably difficult and probably not advisable as this could cause problems for internal systems processing especially during startup and shutdown. Even with a wrapper program you'd probably have to throughly test it to avoid system interference and made appropriate adjustments. | |||
|
feedback
|