Skip to content

Instantly share code, notes, and snippets.

@drbeh
Created April 3, 2019 23:46
Show Gist options
  • Save drbeh/dd8f9d2e39d9f1d4d77d317326324ed8 to your computer and use it in GitHub Desktop.
Save drbeh/dd8f9d2e39d9f1d4d77d317326324ed8 to your computer and use it in GitHub Desktop.
Mount and Unmount Disks Encrypted by "BitLocker To Go" on Mac Systems
#!/bin/bash
BITLOCKER_PARTITION="${1}"
BITLOCKER_PASSWORD="${2}"
BITLOCKER_NAME="${3}"
function usage() {
echo "$(basename ${0}) <partition> <password>"
echo "Unlocks and mounts a bitlocker partition as read-only"
}
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
# 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
if [ -z "${BITLOCKER_NAME}" ]
then
BITLOCKER_NAME="bitlocker.$(basename ${BITLOCKER_PARTITION})"
fi
BITLOCKER_FILE="/tmp/${BITLOCKER_NAME}"
BITLOCKER_MOUNT="/Volumes/${BITLOCKER_NAME}"
echo "Unlocking ${BITLOCKER_PARTITION} to ${BITLOCKER_FILE}"
dislocker -v -V "${BITLOCKER_PARTITION}" -r -u"${BITLOCKER_PASSWORD}" "${BITLOCKER_FILE}"
if [[ ${?} != 0 ]]
then
echo "Dislocker operation failed"
exit 1
fi
echo "Mounting unlocked image to ${BITLOCKER_MOUNT}"
hdiutil attach "${BITLOCKER_FILE}/dislocker-file" -imagekey diskimage-class=CRawDiskImage -mountpoint "${BITLOCKER_MOUNT}"
if [[ ${?} != 0 ]]
then
echo "Mounting the unlocked image failed"
exit 1
fi
echo "Bitlocker partition ${BITLOCKER_PARTITION} successfully mounted at ${BITLOCKER_MOUNT}"
#!/bin/bash
BITLOCKER_PARTITION="${1}"
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="bitlocker.$(basename ${BITLOCKER_PARTITION})"
BITLOCKER_FILE="/tmp/${BITLOCKER_NAME}"
BITLOCKER_MOUNT="/Volumes/${BITLOCKER_NAME}"
echo "Unmounting the unlocked image from ${BITLOCKER_MOUNT}"
hdiutil detach "${BITLOCKER_MOUNT}"
echo "Unmounting the bitlocker file from ${BITLOCKER_FILE}"
hdiutil detach "${BITLOCKER_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment