This is untested but I did come across this page: automounting usb flash drives on linux with udev and pmount
The general idea is that you make a UDEV action that will automount using pmount instead. If you look in the comments there's a
punmount -l which will do a lazy unmount which should be safer.
Here is a solution for automounting usb flash drives / memory sticks on linux using only udev and pmount.
add a file
put the following lines in it
# automounting usb flash drives
# umask is used to allow every user to write on the stick
# we use --sync in order to enable physical removing of mounted memory
# sticks -- this is OK for fat-based sticks
# I don't automount sda since in my system this is the internal hard
# drive depending on your hardware config, usb sticks might be other
# devices than sdb*
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"
reload the udev rules:
udevadm control --reload-rules
NOTE: If you want to make this setup more tolerant to unmounting then you'll want to include the
-l for lazy unmounting to
ACTION=="remove", KERNEL=="sda*", RUN+="/usr/bin/pumount -l %k"
pumount's man page:
Lazy unmount. Detach the filesystem from the filesystem hierarchy
now, and cleanup all references to the filesystem as soon as it is
not busy anymore. (Requires kernel 2.4.11 or later.)
IMPORTANT NOTES This option should not be used unless you really
know what you are doing, as chances are high that it will result
in data loss on the removable drive. Please run pumount manually
and wait until it finishes. In addition, pumount will not
luksClose a device which was unmounted lazily.