I'm using debian testing, and I have a file, it's a LUKS container with ext4 filesystem. My system mounts it with every boot. I had to use the three following files in order to do so:
sda2_crypt UUID=727fa348-8804-4773-ae3d-f3e176d12dac none luks crypt_dropbox /media/Server/Dropbox/luks_dropbox sda2_crypt luks,keyscript=/lib/cryptsetup/scripts/decrypt_derived,noauto
# dropbox UUID=0d959e74-ec19-43bf-b779-60134c676aef /media/Dropbox ext4 defaults,noauto,user,nofail,noatime,commit=20 0 2
cryptdisks_start crypt_dropbox mount /media/Dropbox
The container can't be opened and mounted automatically at boot via
/etc/fstab because the dropbox volume is on a partition and has to be opened before the partition is mounted. So, that's why there's
/etc/crypttab . The filesystem inside that container can't also be mounted via
mount -a (at least at boot) because there's no device yet. The option
nofail exists to suppress the "no device" error. And the first phase is completed. The second phase is when boot is done, that's why I used
/etc/rc.local file. The first line opens without password (because of settings in /etc/crypttab) the dropbox volume, the second mounts it via /etc/fstab . And that works.
The error occurs while the system tries to unmount the partition where the dropbox volume is. I don't know exactly why but it could be because the filesystem of the dropbox volume is mounded, or maybe the container is opened, or even because of the loop0 device is still active. In order to close the dropbox volume completely, I have to use the following commands:
umount /media/Dropbox cryptdisks_stop crypt_dropbox losetup -d /dev/loop0
Is there a way to do it only when system goes down but before unmounting any other partition? Is there a file where I can insert these commands, similar to /etc/rc.local ?