This script automatically decrypts and mounts BitLocker-encrypted hard drive partitions on Linux. It is particularly useful for dual-boot systems where Windows partitions are encrypted with BitLocker but need to be accessed from Linux. The script supports two methods to unlock BitLocker partitions:
- User password – The standard BitLocker password used for unlocking the drive.
- Recovery key – A 48-digit recovery key, useful if the password is unavailable.
-
Download and Extract:
- Download the script's ZIP file.
- Extract it and place the folder in a location of your choice.
-
Update Path:
- In
bitlocker-startup.sh
, replaceSCRIPT_DIRECTORY
with the full path to to the script folder.
- In
sudo apt install dislocker
To ensure proper package isolation, a Python virtual environment is required.
- Create a virtual environment:
sudo apt install python3-venv
python3 -m venv /SCRIPT_DIRECTORY/python3-venv
- Activate the virtual environment:
source /SCRIPT_DIRECTORY/python3-venv/bin/activate
- Install required Python packages:
pip install cryptography getpass_asterisk
3. Configure drives.json
Create or edit drives.json
to store your BitLocker partition details.
Each drive entry must include:
NAME
: A label for the drive (e.g.,"ssd1"
).PARTUUID
: The unique identifier of the partition.PASSWORD
: Either the BitLocker password or 48-digit recovery key.
Run the following command:
lsblk -o NAME,PARTUUID,FSTYPE,MOUNTPOINT
4. Encrypt drives.json
Once drives.json
is ready, encrypt it for security using encrypt.py
.
You will be prompted to enter a password, which will be required to decrypt the file later.
5. Secure drives.json
After encrypting drives.json
, delete the unencrypted version to protect your drive passwords.
If you may need to edit the drive information later, store an unencrypted backup on an encrypted partition. Only the encrypted drives.json.enc should be kept for regular use.
However, if your entire Linux system is already encrypted, keeping the unencrypted drives.json
is generally safe.
To run the script automatically at startup, can either:
- Add the startup script to your startup applications manually:
/SCRIPT_FOLDER_LOCATION/mount-on-startup/bitlocker-startup.sh
- Use the included
.desktop
file:
Place thebitlocker-unlock-mount.py.desktop
file inside~/.config/autostart/
to automatically launch the script at startup. Before doing so, modify theExec
path in the.desktop
file to point to the correct location ofbitlocker-startup.sh
.
It is necessary to allow executing the .sh
file as a program. To do this, run:
chmod +x /SCRIPT_FOLDER_LOCATION/mount-on-startup/bitlocker-startup.sh
sudo chmod +x /SCRIPT_FOLDER_LOCATION/unmount-on-shutdown/unmount_dislocker.sh
sudo cp /SCRIPT_FOLDER_LOCATION/unmount-on-shutdown/dislocker-cleanup.service /etc/systemd/system/dislocker-cleanup.service
sudo systemctl enable dislocker-cleanup.service
If you want to manually run bitlocker-unlock-mount.py
, follow these steps:
- Activate the virtual environment:
source /SCRIPT_DIRECTORY/python3-venv/bin/activate
- Run the script:
python /SCRIPT_DIRECTORY/bitlocker-unlock-mount.py
After logging in, a terminal will automatically open, prompting you to:
- Enter your user login password for
sudo
permissions. - Enter the password that was used to encrypt
drives.json
.
Once both passwords are entered correctly, the script will decrypt the drives.json.enc
file and proceed to unlock and mount your BitLocker-encrypted drives.
This script has been tested on Ubuntu 22.04 and Debian 13.
If you encounter issues:
This script is open-source and available under the MIT License.