Scripted truecrypt mount, without using /dev/ or UUID

722 Views Asked by At

I have 5 truecrypt encrypted drives. Running ubuntu 13.04. I'm trying to run the following command in a script to mount my drives.

truecrypt -t /dev/disk/by-uuid/25f8c629-d0c8-4c39-b4c2-aacba38b5882 /media/P --password="$password"  -k "" --protect-hidden=no

Because of the way truecrypt works I cant use this, because the UUID is only accessible once the drives are mounted.

Is it possible to do the same thing but with hard-drive serial numbers, or model numbers? Something a bit more permanent?

I cant use the /dev/ as they change randomly nearly every time I reboot the PC. This is due to 2 of my drives being connected via a PCI card.

1

There are 1 best solutions below

0
On

Use Disk ID instead:

#!/bin/bash

# Run this script as root to avoid entering the root password twice

secret=0xa52f2c38

# Generate tempfile
tempfile=fdisk.tmp
sudo fdisk -l > $tempfile

# --------------------------------------------------------------------------
# Locate secret drive and mount it
# --------------------------------------------------------------------------
num=$[ $(grep -n "^Disk identifier: $secret" $tempfile | cut -f1 -d:) - 5 ]
if [ $num \> 0 ] # num will be greater than 0 if drive exists
then

 # Get line containing /dev
 # ----------------------------------------------------------------------
 dev=$(sed -n "${num}p" $tempfile | cut -f2 -d' ' | sed 's/://')
 truecrypt $dev /media/secret

# Check (Create .truecrypt on the mounted volumen beforehand)
# ----------------------------------------------------------------------
 if [ ! -f /media/secret/.truecrypt ]
 then
   zenity --error --text="There was a problem mounting secret"
 fi
fi

rm $tempfile

The source of the script is: http://delightlylinux.wordpress.com/2012/05/21/mounting-truecrypt-volumes-by-disk-id/ I recommend you to read it through if you have difficulty understanding what the script is doing. The explanation is thorough.