Last active
November 9, 2018 02:59
-
-
Save bearx3f/1d7dd007ac1a35727b3a038797a0f147 to your computer and use it in GitHub Desktop.
Mount script for VeraCrypt volumes mounted from /etc/fstab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Mount script for VeraCrypt volumes mounted from /etc/fstab | |
# | |
# Based on | |
# http://en.gentoo-wiki.com/wiki/TrueCrypt#Mount_volume_via_fstab | |
# | |
# Copyright (c) 2011, Florian Rathgeber | |
# This file is released under the | |
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 | |
# license | |
# | |
# ------------------------------------------------------------ | |
# Forks from | |
# https://gist.github.com/kynan/1101739 | |
# | |
# Tested On: | |
# - CentOS 7.2 | |
# ------------------------------------------------------------ | |
# History: | |
# 2016-11-13: Intialized. | |
# ------------------------------------------------------------ | |
DEV="$1" | |
MNTPT="$2" | |
OPTIONS="" | |
TCOPTIONS="" | |
KEYOPTIONS="-k ''" | |
TCMODE="" | |
# skip device, mountpoint and '-o' | |
shift 3 | |
IFS=',' | |
for arg in $*; do | |
# System encryption | |
if [ "${arg}" == "system" ]; then | |
TCOPTIONS="${TCOPTIONS}-m=system " | |
# File system | |
elif [[ "${arg}" == fs=* ]]; then | |
FS=${arg#*=} | |
if [ "${FS}" == "fat" ]; then | |
TCOPTIONS="${TCOPTIONS}--filesystem=\"fat\" " | |
else | |
# VeraCrypt inherit most source code from truecrypt, they ignore other filesystem. | |
TCOPTIONS="${TCOPTIONS}--filesystem=none " | |
fi | |
# Key files | |
elif [[ "${arg}" == k=* ]]; then | |
KEYOPTIONS="--keyfiles=\"${arg#*=}\"" | |
# Hidden volume protection on | |
elif [ "${arg}" == "protect" ]; then | |
TCOPTIONS="${TCOPTIONS}--protect-hidden=\"yes\" " | |
# Hidden volume protection off | |
elif [ "${arg}" == "noprotect" ]; then | |
TCOPTIONS="${TCOPTIONS}--protect-hidden=\"no\" " | |
# mounting truecrypt volumn | |
elif [ "${arg}" == "tc" ]; then | |
TCMODE="--truecrypt" | |
# Slot: reserve mounting slot. | |
elif [[ "${arg}" == slot=* ]]; then | |
SLOT=${arg#*=} | |
TCOPTIONS="${TCOPTIONS}--slot=\"${arg#*=}\" " | |
# PIM: Personal Iterations Multiplier | |
elif [[ "${arg}" == pim=* ]]; then | |
TCOPTIONS="${TCOPTIONS}--pim=\"${arg#*=}\" " | |
# Mount without password | |
elif [ "${arg}" == "nopasswd" ]; then | |
TCOPTIONS="${TCOPTIONS}--password=\"\" " | |
# Anything else is interpreted as file system options | |
else | |
OPTIONS="${OPTIONS}${arg}," | |
fi | |
done | |
CMD="/usr/bin/veracrypt ${TCMODE} -t ${DEV} ${MNTPT} ${KEYOPTIONS} ${TCOPTIONS% *} --fs-options="${OPTIONS%,*}"" | |
# Mount the volume | |
sh -c "${CMD}" | |
mount -t ${FS} "/dev/mapper/veracrypt${SLOT}" "${MNTPT}" | |
# To umount: | |
# sudo umount ${MNTPT} | |
# veracrypt -d ${DEV} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment