I created an encrypted container via
#!/bin/bash
dd if=/dev/zero of=$1 bs=1 count=0 seek=$2
MAPPER=$(mktemp -up /dev/mapper)
LOOPDEV=$(losetup --find --show $1)
cryptsetup luksFormat $LOOPDEV
cryptsetup luksOpen $LOOPDEV $(basename $MAPPER)
mkfs.ext3 $MAPPER
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
i.e. a file e.g. container specified to this script will contain a ext3 filesystem encrypted via cryptsetup luksFormat.
To mount it, I currently use another script, say dm.mount container /mnt/decrypted:
#!/bin/bash
set -e
MAPPER=$(mktemp -up /dev/mapper)
LOOPDEV=$(losetup --find --show $1)
cryptsetup luksOpen $LOOPDEV $(basename $MAPPER) || losetup -d $LOOPDEV
mount $MAPPER $2 || (
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
)
and to unmount it dm.umount /mnt/decrypted:
#!/bin/bash
set -e
MAPPER=$(basename $(mount | grep $1 | gawk ' { print $1 } '))
LOOPDEV=$(cryptsetup status $MAPPER | grep device | gawk ' { print $2 } ')
umount $1
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
There's a lot of redundancy and manually grabbing a loop device and mapper both of which could remain anonymous. Is there a way to simply do something like mount -o luks ~/container /mnt/decrypted (prompting for the passphrase) and umount /mnt/decrypted the easy way instead?
edit Basically I am happy with my scripts above (although the error checking could be improved...), so
How can a mount option
-o luks=~/containerbe implemented similar to-o loop ~/loopfileusing the scripts I wrote?
Can this be achieved without rewriting mount? Or alternatively, could -t luks -o loop ~/container be implemented?