Skip to content

Instantly share code, notes, and snippets.

@imZack
Forked from dumbledore/mount-bitlocker
Created September 13, 2021 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imZack/988088901bfe0231dccb386c8626117d to your computer and use it in GitHub Desktop.
Save imZack/988088901bfe0231dccb386c8626117d 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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment