[dm-crypt] Auto Mounting when file accessed?

Roger rogerx.oss at gmail.com
Thu Jan 13 01:57:02 CET 2011

>On Wed, Jan 12, 2011 at 10:05:00PM +0100, Ma Begaj wrote:
>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
>    fi

I tried this and, instead of using "mount /mnt/crypt", I designated a script to run instead of using "mount

I kept getting a superblock/e2fsck error.

My script "mount-crypt" is nearly error proof as it utilizes losetup,
cryptsetup, and then calls e2fsck each time before mounting to /mnt/crypt.

mount-crypt always calls umount-crypt encase losetup is halfway started, and then
always calls e2fsck before mounting to /mnt/crypt.

The other issues are:
1) Using inotify requires to be in a script and needing to be started at startup.
2) It needs to embed password or app-crypt/pinentry
3) pinentry or asking for a passphrase is likely going to only occur on the
terminal inotify script is started from, vs for the terminal wanting access to
file or folder.  Think #3 is going to be the real issue because it's calling
mount-crypt from another terminal or it's own bash process.  I know the
pinentry gui prompt is likely not an issue though.

...anyways, I likely need to research everything here again and do some more
testing.  Technically, everything I'm doing in mount-crypt should likely be
done behind the scenes.


More information about the dm-crypt mailing list