Python script to mount a Veracrypt volume via the command line in both Linux and Windows.
I personally use this script to share an Veracrypt-encrypted ext4 drive between Fedora and Windows OSes. It will likely be just as useful for users of a Linux or Windows machine, regardless of if it is single- or dual-boot.
This Python script is inspired by Aheno Barbus's PowerShell script on SourceForge: (See https://sourceforge.net/p/veracrypt/discussion/technical/thread/027f5f92bf/).
- If running this script in Windows, your Veracrypt partition must be on a separate drive from your Windows partition! This is a known limitation of WSL 2 as of the writing of this README.
- Python cannot run external applications interactively. Thus, if errors occur after Veracrypt's command-line takes over, they may not be displayed.
- Python 3 installed
- Veracrypt installed
If using Windows:
- WSL 2 installed
- Linux OS installed in WSL
- Veracrypt installed within WSL Linux OS
- Copy "mount_veracrypt_volume.py" and "veracrypt_volume_settings.example.ini" to the directory "$HOME/bin/".
- Rename "veracrypt_volume_settings.example.ini" to "veracrypt_volume_settings.ini".
- Set
DRIVE_PARTITION
in "veracrypt_volume_settings.ini" to the Linux name of the encrypted partition. - (Optional) Modify other settings within "veracrypt_volume_settings.ini" as desired.
- (Optional) Copy "mount_veracrypt_volume.desktop" to your Desktop folder.
6a. If using the desktop icon, double click the desktop icon.
6b. Otherwise, run
sudo -i python $HOME/bin/mount_veracrypt_volume.py -c $HOME/bin/veracrypt_volume_settings.ini
in the terminal. - Follow the prompts to enter your administrative password and partition password (if not set in the settings file).
- The encrypted Veracrypt volume should be mounted!
- Copy "mount_veracrypt_volume.py" and "veracrypt_volume_settings.example.ini" to the directory "%USERPROFILE%\bin".
- Rename "veracrypt_volume_settings.example.ini" to "veracrypt_volume_settings.ini".
- Set
DRIVE_PARTITION
in "veracrypt_volume_settings.ini" to the Linux name of the encrypted partition. - (Optional) Modify other settings within "veracrypt_volume_settings.ini" as desired.
5a. Run
python %USERPROFILE%\bin\mount_veracrypt_volume.py -c veracrypt_volume_settings.ini
in a command prompt with administrative permissions. 5b. Create a shortcut with administrative permissions that runs the above command (replacingpython
with the path to your python 3 executable), and double-click that shortcut instead. - Follow the prompts to enter your administrative password and partition password (if not set in the settings file).
- The encrypted Veracrypt volume should be mounted!
In general, the script will attempt to give you sensible error messages if there are errors, and should prompt for any missing data it needs to decrypt the partition.
If you run the script with DRIVE_PARTITION
unset, it should display a list of drive partitions it finds.
If that fails, check out https://sourceforge.net/p/veracrypt/discussion/technical/thread/027f5f92bf/ for more detailed instructions of how to list the Linux drive partition names.