LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-23-2013, 05:41 AM   #1
cybtrash
LQ Newbie
 
Registered: Feb 2013
Posts: 1

Rep: Reputation: Disabled
how to write an udev rule for auto mounting crypted LUKS hd with ZFS filesystem?


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"
************************************************************
 
Old 03-25-2013, 07:01 AM   #2
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Usually what is done to auto mount a device is to set it on the file fstab, which is much easier and safe.

Regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UDEV and auto mounting external devices enine Slackware 6 11-06-2011 07:57 AM
[SOLVED] Creating an udev rule mounting all usb drive as 666 Linux.tar.gz Linux - Hardware 20 11-23-2010 05:56 AM
[SOLVED] Write udev rule to change harddisk timeout EricTRA Linux - Virtualization and Cloud 9 06-11-2010 06:55 AM
cryptsetup won't open crypted fs on raid5 with known luks passphrase luboss Linux - Security 3 11-13-2008 01:55 PM
need help: write udev rule for LIRC, digital setopbox NoMoreReinstallMS Linux - Hardware 0 11-24-2006 03:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration