LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Automount encrypted Windows partition (truecrypt) (http://www.linuxquestions.org/questions/slackware-14/automount-encrypted-windows-partition-truecrypt-781854/)

piratesmack 01-12-2010 11:25 PM

Automount encrypted Windows partition (truecrypt)
 
I'm trying to automount my encrypted Windows partition in Slackware-Current.

With help from the Gentoo wiki, I came up with this script:
Code:

#!/bin/sh
# /sbin/mount.truecrypt

DEV="$1"
MNTPNT="$2"
FS=""
MNTOPTS=""
FSOPTS=""

shift 3
IFS=","
for arg in $@; do
  case $arg in
    system)
      MNTOPTS="system"
    ;;
    fs=*)
      FS="${arg#fs=}"
    ;;
    password=*)
      PASS="${arg#password=}"
    ;;
    *)
      FSOPTS="${FSOPTS}${arg},"
    ;;
  esac
done

/usr/bin/truecrypt \
  --mount \
  --mount-options="$MNTOPTS" \
  --password="$PASS" \
  --filesystem="$FS" \
  --fs-options="${FSOPTS%,}" \
$DEV $MNTPNT

Then I added this to my fstab:
Code:

/dev/sda4 /mnt/windows truecrypt rw,system,pw=MYPASS,fs=ntfs-3g,umask=000,noatime 1 0
I get this error when I try to mount my partition (as root):
Code:

# mount /mnt/windows/
No protocol specified
Error: Unable to initialize gtk, is DISPLAY set properly?

But if I run my script like this (exactly how mount runs it), it works fine:
Code:

# /sbin/mount.truecrypt /dev/sda4 /mnt/windows -o rw,noatime,system,password=MYPASS,fs=ntfs-3g,umask=000
Any ideas?

EDIT

Fixed it with the -t option.
But if anybody has a better solution, let me know.

New script
Code:

#!/bin/sh
#/sbin/mount.truecrypt

DEV="$1"
MNTPNT="$2"
FS=""
MNTOPTS=""
FSOPTS=""
PASS=""

ARGS="$(echo $@ | sed -e 's/,/ /g')"
for arg in $ARGS; do
  case $arg in
    $DEV | $MNTPNT | -v | -o)
      #ignore these
    ;;
    headerbak | nokernelcrypto | readonly | ro | system | timestamp | ts)
      MNTOPTS="${MNTOPTS}${arg},"
    ;;
    fs=*)
      FS="${arg#fs=}"
    ;;
    pw=*)
      PASS="${arg#pw=}"
    ;;
    *)
      FSOPTS="${FSOPTS}${arg},"
    ;;
  esac
done

#Remove the last comma in list
MNTOPTS="${MNTOPTS%,}"
FSOPTS="${FSOPTS%,}"

echo "$DEV on $MNTPNT type $FS ($FSOPTS)"
[ -n "$MNTOPTS" ] && MNTOPTS="-m=${MNTOPTS}"
[ -n "$FS" ] && FS="--filesystem=${FS}"
[ -n "$FSOPTS" ] && FSOPTS="--fs-options=${FSOPTS}"

/usr/bin/truecrypt -t $MNTOPTS $FS $FSOPTS $DEV $MNTPNT 1>/dev/null <<EOF
$PASS

n
EOF


mostlyharmless 01-13-2010 04:34 PM

Are you working from an xterm or from the console? I only get the dreaded "Error: Unable to initialize gtk, is DISPLAY set properly?" when logged in as non-root in X (don't ever run as root) but run commands as root in an xterm. There's a way around that exporting your DISPLAY, but since that's basically over my head :), I can't remember how do it without looking it up.

piratesmack 01-13-2010 11:38 PM

Quote:

Originally Posted by mostlyharmless (Post 3825598)
Are you working from an xterm or from the console? I only get the dreaded "Error: Unable to initialize gtk, is DISPLAY set properly?" when logged in as non-root in X (don't ever run as root) but run commands as root in an xterm. There's a way around that exporting your DISPLAY, but since that's basically over my head :), I can't remember how do it without looking it up.



I was working from an xterm.
The command worked fine when I ran it manually (as both root and my user account), I only got the error when mount tried to run the script.

Oh well, I guess I need the -t switch anyway since I want this mounted on boot.

Bonus question:
Is there any way to make my truecrypt volume unmount with "umount /mnt/windows" instead of "truecrypt -t -d"?

I tried making a script "/sbin/umount.truecrypt", but it doesn't seem to run it.


All times are GMT -5. The time now is 03:43 AM.