Skip to content

Instantly share code, notes, and snippets.

@Nama
Last active June 8, 2016 11:40
Show Gist options
  • Save Nama/8ac667d78713c34b6f67a0873aecc9a6 to your computer and use it in GitHub Desktop.
Save Nama/8ac667d78713c34b6f67a0873aecc9a6 to your computer and use it in GitHub Desktop.
Easy mount devices encrypted with cryptsetup. I use this code in /etc/profile.d/
#!/bin/bash
mnthdd() {
# The full mount-path is put together bei $MOUNTPATH and $DRIVES
# In this example it would be /media/ + your parameter
MOUNTPATH="/media/"
# /etc/fstab
## hdd1
#/dev/mapper/hdd1 /media/hdd1 ext4 noauto,defaults 0 0
#
## hdd2
#/dev/mapper/hdd2 /media/hdd2 ext4 noauto,defaults 0 0
# Define your drives.
# The mapper-name is free to choose.
# The letter is the device-letter in /dev/sdX1
declare -A DRIVES
# DRIVES[mapper-name]="X"
DRIVES[hdd1]="b"
DRIVES[hdd2]="c"
if [ -z ${DRIVES[$1]} ]; then
echo "Unknown device. Aborting."
else
if [[ -z "$2" ]]; then
sudo cryptsetup status $1 > /dev/null
if [[ $? == 4 ]]; then
echo "Opening $1"
sudo cryptsetup luksOpen /dev/sd${DRIVES[$1]}1 $1
sudo mount $MOUNTPATH$1
echo "$1 mounted"
else
echo "$1 might be already luksOpen'd"
fi
elif [[ $2 == "u" ]]; then
sudo umount $MOUNTPATH$1
sudo cryptsetup luksClose $1
echo "$1 unmounted"
else
echo "Unknown parameter $2. Aborting."
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment