Is there an auto-dismount in veracrypt or should I always unmount veracrypt volumes manually before shutting down to prevent a broken filesystem/container?
I found the answer for Windows in the veracrypt FAQ, but not for Linux / Ubuntu.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Here is an update, which should be the right answer!
I learned in the veracrypt forums that the option to control dismounting upon shutdown and/or suspend was introduced in version 1.19. There is no need to create the init.d scripts described above.
You can see this for yourself. I use the Ubuntu ppa provided a veracrypt package, in which there is a file called
/etc/default/veracrypt in which the following setings are included:
# If enabled, the following option calls 'veracrypt -d' at shutdown. Although # all filesystems are unmounted automatically at shutdown, only calling # 'veracrypt -d' will stop the VeraCrypt processes and remove any device mappings. # It probably isn't necessary to do this, but it shouldn't hurt. VERACRYPT_SHUTDOWN_UNMOUNT="yes" # If enabled, the following option calls 'veracrypt -d' during suspend and hibernate. VERACRYPT_SUSPEND_UNMOUNT="yes"
In case you want to try, here's the ppa file:
deb http://ppa.launchpad.net/unit193/encryption/ubuntu cosmic main deb-src http://ppa.launchpad.net/unit193/encryption/ubuntu cosmic main
and the version as of 2018-12-26,
There are so-called run levels and script are executed when a new run level is entered. On Ubuntu, these are stored in
/etc/rc<run level>.d. Run level 0 is shutdown and run level 6 is reboot. So you want your script to be in
/etc/rc0.d and in
Create the file
/etc/init.d/unmount-veracrypt-volumes.sh and make this its content:
#!/bin/sh veracrypt -d -f sleep 3
Then execute these commands:
sudo chown root /etc/init.d/unmount-veracrypt-volumes.sh sudo chmod 751 /etc/init.d/unmount-veracrypt-volumes.sh sudo ln -s /etc/init.d/unmount-veracrypt-volumes.sh /etc/rc0.d/K00-unmount-veracrypt-volumes.sh sudo ln -s /etc/init.d/unmount-veracrypt-volumes.sh /etc/rc6.d/K00-unmount-veracrypt-volumes.sh
K00 so the script is executed as the very first one when one of the run levels is entered. Those scripts are executed in increasing ASCII order, so the smaller the number of the symlink's name, the earlier a script is executed.