Skip to content

Instantly share code, notes, and snippets.

@gigawatts
Created September 8, 2021 00:57
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 gigawatts/0d1e3b713a22ce7850f29ed599bd03f4 to your computer and use it in GitHub Desktop.
Save gigawatts/0d1e3b713a22ce7850f29ed599bd03f4 to your computer and use it in GitHub Desktop.
Bitlocker encrypted VHD mount / un-mount scripts
#!/bin/bash
if [ -z "$1" ]
then
echo "No argument supplied"
exit 1
fi
VHD=$1
if [ ! -f "$VHD" ]; then
echo "${VHD} does not exists"
exit 1
fi
## enable network block devices
sudo modprobe nbd max_part=8
## mount VHD disk image to a nbd block device, optionally --read-only
sudo qemu-nbd --connect=/dev/nbd0 ${VHD}
## view partitions of disk image
sudo fdisk -l /dev/nbd0
## create a decrypted block device from encrypted block device
sudo mkdir /mnt/blfile /mnt/bitlocker
sudo dislocker -v -V /dev/nbd0p2 -u -- /mnt/blfile
## mount the decrypted block device to a mount point
sudo mount -o loop /mnt/blfile/dislocker-file /mnt/bitlocker
#!/bin/bash
sudo umount /mnt/bitlocker /mnt/blfile && sudo rmdir /mnt/bitlocker /mnt/blfile && sudo qemu-nbd --disconnect /dev/nbd0 && sudo rmmod nbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment