Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from serverfault.com Mar 28 '10 at 11:01

This question came from our site for professional system and network administrators.

    
How is the filesystem being mounted? Things are not mounted automatically presumably you have some program/tool that is performing the mount for you. You need to determine what that is and replace it or fix it. –  Zoredache Mar 27 '10 at 21:39
    
In my case I normally use the KDE subsystem (presumably that is Dolphin, don't know which component is responsible for the actual mount command) –  Homer J. Simpson Mar 27 '10 at 21:45
1  
i wrote about handling automounts with uDev or with HALevt in answers to another question. those would be replacements for the KDE or GVFS subsystem, but the procedure might give you some ideas of where to look. it sounds like you want to tap into the Dbus mounts (desktop/userspace rather than kernel level). –  quack quixote May 5 '10 at 6:33

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.