Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dumbledore
Created February 20, 2018 21:05
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save dumbledore/2c9f2a6410763c3f96516945b65bc5bb to your computer and use it in GitHub Desktop.
Save dumbledore/2c9f2a6410763c3f96516945b65bc5bb to your computer and use it in GitHub Desktop.
Mount/umount wrapper for dislocker on MacOS
#!/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"
}
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
BITLOCKER_NAME="bitlocker.$(basename ${BITLOCKER_PARTITION})"
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}"
@AlexandreGohier
Copy link

This is pretty great thanks a lot for sharing your code! I only found out about dislocker today and your wrapper makes it much easier to mount / unmount bitlocker volumes on MacOs (it's easier and more documented on Linux).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment