Hello,
I have a small computer with Ubuntu 12.10 and XBMC for entertainment. My media (pictures, music, ...) is on an external USB (raid) harddrive. It is encrypted with LUKS/dm-crypt, on top of that is ZFS filesystem. A small usb thumbdrive with the password key is connected to the computer.
Now everytime I connect the harddrive I have to do the following:
[root] cryptsetup luksOpen --key-file=/media/THUMBDRIVE/mykey.key /dev/sdb HDCRYPTED
(/dev/sdb can also be called by /dev/disk/by-id/ata-H_W_RAID5_[...])
--> now there is /dev/mapper/HDCRYPTED
[root] zpool import MEDIAHD
--> now there is /media/MEDIAHD and I can read/write to it
(the mountpoint property of the ZFS filesystem is set to /media/MEDIAHD
After e.g. watching I put the computer via remote to sleep, pm.sleep does the following:
zpool export MEDIAHD
(unmounting)
cryptsetup luksClose /dev/mapper/HDCRYPTED
and the computer goes to standby.
How can I automate the mounting process as stated above? I guess udev would be the best, but can anybody please tell me how the rule file should look like as udev is really confusing to me and my previous attempts didn't work...
Currently I have those udev files:
************************************************************
cat /etc/udev/rules.d/11-media-by-label-auto-mount.rules
Code:
# Start at sdb to avoid system harddrive.
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
************************************************************
************************************************************
cat /etc/udev/rules.d/85-xbmc.rules
Code:
#Remote Control
SUBSYSTEM=="usb" , ATTRS{idVendor}=="0471", ATTRS{idProduct}=="20cc", SYMLINK+="remote", ACTION=="add", RUN+="/sbin/initctl --quiet emit --no-wait ir-ready"
************************************************************