Skip to content

Instantly share code, notes, and snippets.

@ffflorian
Last active November 1, 2020 03:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffflorian/146e1b9ae4f83fdfb88f to your computer and use it in GitHub Desktop.
Save ffflorian/146e1b9ae4f83fdfb88f to your computer and use it in GitHub Desktop.
Mount BitLocker drive with DisLocker
#!/bin/bash
HARDDRIVE=/dev/sdb2
BITLOCK_MOUNT=/media/bitlocker
DECRYPTED_MOUNT=/media/mount
USAGE="Usage: dislock [options]
Options:
-k, --recoverykey KEY The BitLocker recovery key to use for mounting
-u, --umount Unmount the mounted BitLocker volume
"
# run this script as root.
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
if [ "$1" == "-k" ] || [ "$1" == "--recoverykey" ]; then
if [ -n "$2" ]; then
RECOVERYKEY="$2"
if [ "$(ls -A $BITLOCK_MOUNT)" ]; then
echo "The directory $BITLOCK_MOUNT is not empty. Maybe the BitLocker volume is already mounted?"
exit 1
else
mkdir -p "$BITLOCK_MOUNT" "$DECRYPTED_MOUNT"
dislocker -v -V "$HARDDRIVE" -p"$RECOVERYKEY" -- "$BITLOCK_MOUNT"
mount -o loop,ro $BITLOCK_MOUNT/dislocker-file "$DECRYPTED_MOUNT"
echo "BitLocker is now mounted at $DECRYPTED_MOUNT."
exit 0
fi
else
printf "Option '%s' requires an argument.\n$USAGE" "$1"
exit 1
fi
elif [ "$1" == "-u" ] || [ "$1" == "--umount" ]; then
if [ "$(ls -A $DECRYPTED_MOUNT)" ]; then
umount "$DECRYPTED_MOUNT"
umount "$BITLOCK_MOUNT"
echo "BitLocker is now unmounted."
exit 0
else
echo "The directory $BITLOCK_MOUNT is empty. Maybe the BitLocker volume is not mounted?"
exit 1
fi
elif [ -z "$1" ]; then
echo "$USAGE"
else
printf "dislock: invalid option '%s'.\n$USAGE" "$1"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment