[dm-crypt] Auto Mounting when file accessed?

Ma Begaj derliebegott at gmail.com
Wed Jan 12 22:05:00 CET 2011

2011/1/12 Roger <rogerx.oss at gmail.com>:
> Is there a known method, when a user accesses a file/folder of an
> unmounted dm-crypt partition, the action can spawn an attempt to automatically
> mount this partition.
> For the password prompt, as I constantly am working within a terminal and not
> GUI desktop for obvious reasons, pinentry is commonly used for prompting in a
> terminal or by GUI for a password when using GNUPG.
> app-crypt/pinentry
> http://gnupg.org/aegypten2/index.html
> Any thoughts on this?  (Kernel DBUS/UDEV script or something?)
> The type of current setup targeted is a file containing an encrypted EXT3
> filesystem using dm-crypt, for which is mounted to /mnt/crypt.
> This is usually left in an unmounted state until wanting access to something
> within /mnt/crypt/somefile/orfolder.
> ie. "vi /mnt/crypt/myfile or abook /mnt/crypt/addressbook --datafile
> /home/roger/.abook/addressbook"
> I'm thinking, something within the dbus/udev (kernel script) is needed.
> Another thought, what if TAB Bash Completion is used?

inotify-tools could probably help you... something like this could
work, i think;


# watch for folders
inotifywait -m -r --format "%e %w%f" /mnt/crypt | while read event file; do

    # and mount if not mounted
    if ! df | grep /mnt/crypt >/dev/null ; then
        mount /mnt/crypt

More information about the dm-crypt mailing list