-
-
Save machsix/17932d8d4578587e4e936873ad24f7f8 to your computer and use it in GitHub Desktop.
Mount/umount wrapper for dislocker on Linux x64
This file contains 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
#!/bin/bash | |
BITLOCKER_PARTITION="${1}" | |
BITLOCKER_PASSWORD="${2}" | |
function usage() { | |
echo "$(basename ${0}) <partition> <password>" | |
echo "Unlocks and mounts a bitlocker partition as read-only" | |
echo "Get by lsblk -f" | |
} | |
if [ -z "${BITLOCKER_PARTITION}" ] | |
then | |
echo "Please provide partiton" | |
usage | |
exit 1 | |
fi | |
# Make sure the partition exists | |
if [ ! -e "${BITLOCKER_PARTITION}" ] | |
then | |
echo "'${BITLOCKER_PARTITION}' does not exist" | |
usage | |
exit 1 | |
fi | |
# Make sure it is indeed a block device | |
if [ ! -b "${BITLOCKER_PARTITION}" ] | |
then | |
echo "'${BITLOCKER_PARTITION}' is not a block device" | |
usage | |
exit 1 | |
fi | |
# Now verify there's a password | |
if [ -z "${BITLOCKER_PASSWORD}" ] | |
then | |
echo "Please, provide a password" | |
usage | |
exit 1 | |
fi | |
# Make sure runnign as rootw | |
if [[ ${EUID} > 0 ]] | |
then | |
echo "Please, run as root" | |
usage | |
exit 1 | |
fi | |
BITLOCKER_NAME=$(basename ${BITLOCKER_PARTITION}) | |
BITLOCKER_VMOUNT="/media/.bitlocker/${BITLOCKER_NAME}" | |
BITLOCKER_FILE="${BITLOCKER_VMOUNT}/dislocker-file" | |
BITLOCKER_MOUNT="/media/${BITLOCKER_NAME}" | |
echo "Unlocking ${BITLOCKER_PARTITION} to ${BITLOCKER_FILE}" | |
mkdir -p ${BITLOCKER_VMOUNT} | |
mkdir -p ${BITLOCKER_MOUNT} | |
dislocker -v -V "${BITLOCKER_PARTITION}" -u"${BITLOCKER_PASSWORD}" -- "${BITLOCKER_VMOUNT}" | |
if [[ ${?} != 0 ]] | |
then | |
echo "Dislocker operation failed" | |
exit 1 | |
fi | |
echo "Mounting unlocked image to ${BITLOCKER_MOUNT}" | |
mount -o loop -o allow_other ${BITLOCKER_FILE} ${BITLOCKER_MOUNT} | |
if [[ ${?} != 0 ]] | |
then | |
echo "Mounting the unlocked image failed" | |
exit 1 | |
fi | |
echo "Bitlocker partition ${BITLOCKER_PARTITION} successfully mounted at ${BITLOCKER_MOUNT}" |
This file contains 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
#!/bin/bash | |
BITLOCKER_PARTITION="${1}" | |
set -e | |
function usage() { | |
echo "$(basename ${0}) <partition>" | |
echo "Unmounts a previously unlocked bitlocker partition" | |
} | |
if [ -z "${BITLOCKER_PARTITION}" ] | |
then | |
echo "Please provide partiton" | |
usage | |
exit 1 | |
fi | |
# Make sure the partition exists | |
if [ ! -e "${BITLOCKER_PARTITION}" ] | |
then | |
echo "File '${BITLOCKER_PARTITION}' does not exist" | |
usage | |
exit 1 | |
fi | |
# Make sure it is indeed a block device | |
if [ ! -b "${BITLOCKER_PARTITION}" ] | |
then | |
echo "File '${BITLOCKER_PARTITION}' is not a block device" | |
usage | |
exit 1 | |
fi | |
# Make sure running as root | |
if [[ ${EUID} > 0 ]] | |
then | |
echo "Please, run as root" | |
usage | |
exit 1 | |
fi | |
BITLOCKER_NAME=$(basename ${BITLOCKER_PARTITION}) | |
BITLOCKER_VMOUNT="/media/.bitlocker/${BITLOCKER_NAME}" | |
BITLOCKER_FILE="${BITLOCKER_VMOUNT}/dislocker-file" | |
BITLOCKER_MOUNT="/media/${BITLOCKER_NAME}" | |
echo "Unmounting the unlocked image from ${BITLOCKER_MOUNT}" | |
umount ${BITLOCKER_MOUNT} | |
if [[ ${?} != 0 ]] | |
then | |
echo "Try to use lsof | grep ${BITLOCKER_PARTITION}" | |
exit 1 | |
fi | |
rm -rf ${BITLOCKER_MOUNT} | |
echo "Unmounting the bitlocker file from ${BITLOCKER_FILE}" | |
umount ${BITLOCKER_VMOUNT} | |
rm -rf ${BITLOCKER_VMOUNT} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment