Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a small USB HD I've bought for doing daily backups, which has an encfs system on it.

I've got an autorun script in the root that does a couple of things including mounting the enc-FS and that part works fine.

However if I forget to fusermount -u the enc-FS -before ejecting it, there is no warning about anything and the USB dismounts, leaving the encFS part apparently still mounted. Of course it isn't really, and attempting to access with nautilus say, causes the machine to "behave badly".

There's also the risk of lost files I suppose.

For some reason the systems doesn't seem to detect the drive is still active as it normally does, in this scenario.

Anyway my question is, is it possible to set up the equivalent of an autorun-on-dismount that runs when the USB eject occurs?


share|improve this question

Well I've come up with a not very elegant way to get round this. The autorun script looks something like this:



while : # loop isn't really needed ...
    sleep 999d # ...  because the script will idle for 999 days
    if (($?))
    # sleep closed abnormally, so tidy up
         exit 1

So when the drive eject occurs, the system detects sleep and bash are still running and puts up the warning dialogue; right-click sleep in the dialogue and end it then causes an exit status of 130 that means the dismount script gets called and when it returns the bash script terminates and the USB device then ejects cleanly.

share|improve this answer

Your Answer


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.