Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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}"
@WilliamCocker

This comment has been minimized.

Copy link

commented Aug 10, 2018

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
You can’t perform that action at this time.