I have encrypted my external harddrives using cryptsetup and a key file. My goal is now to automatically decrypt and mount them upon plugin. I used to do so using this blog post (unfortunately in German). This used to work on my old Ubuntu 16.04 machine, but since I upgraded to Focal this does not work anymore. What I have done specifically is:
- Added
/dev/mapper/extdrive /mnt/extdrive xfs defaults,noauto 0 2
to/etc/fstab
. - Added
ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", ATTRS{serial}=="123456789", RUN+="/sbin/cryptsetup --key-file /root/.kf luksOpen $env{DEVNAME} extdrive"
to/etc/udev/rules.d/85-extdrive.rules
- Added
ACTION=="add|change", SUBSYSTEM=="block", ENV{DM_NAME}=="extdrive", RUN+="/bin/mount /dev/mapper/$env{DM_NAME}"
to/etc/udev/rules.d/85-extdrive.rules
It seems like the drive is opened via luksOpen but is not mounted, i.e., the "add|change" rule does not fire. How can I figure out why the automount fails? If I execute the respective commands manually, all seems fine. Bonus: Why did this approach used to work in 16.04 but does not anymore in 20.04?
Thank you!