Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

working udev automount rule

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
6 posts • Page 1 of 1
Author
Message
jodel
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 113
Joined: Tue Sep 28, 2004 5:55 pm

working udev automount rule

  • Quote

Post by jodel » Wed Mar 10, 2010 8:04 am

Hi
This is my udev rule for automounting any usb stick and sd cards. It works on my arch linux machine but not in gentoo.
the directories are created but not mounted[/code]

Code: Select all

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid -p %N", GOTO="media_by_label_auto_mount_end"

# Open luks partition if necessary
PROGRAM=="/sbin/blkid -o value -p -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"
ENV{crypto}!="?*", ENV{device}="%N"
ACTION=="add", ENV{crypto}=="?*", PROGRAM=="/usr/bin/xterm -display :0.0 -e '/usr/sbin/cryptsetup luksOpen %N %k'"
ACTION=="add", ENV{crypto}=="?*", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"

# Global mount options
ACTION=="add", ENV{mount_options}="noatime,users"
# Filesystem specific options
ACTION=="add", PROGRAM=="/sbin/blkid -o value -p -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"

# Get label
ACTION=="add", PROGRAM=="/sbin/blkid -o value -p -s LABEL %E{device}", ENV{dir_name}="%c"
ACTION=="add", ENV{dir_name}!="?*", ENV{dir_name}="usbhd-%k"

ACTION=="add", ENV{dir_name}=="?*", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k /media/%E{dir_name}"
ACTION=="remove", ENV{dir_name}=="?*", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
ACTION=="remove", ENV{crypto}=="?*", RUN+="/usr/sbin/cryptsetup luksClose %k"
LABEL="media_by_label_auto_mount_end"
Top
Heinz
n00b
n00b
User avatar
Posts: 3
Joined: Thu Nov 05, 2009 6:53 pm
Location: Germany,Frankfurt

Can't confirm it

  • Quote

Post by Heinz » Tue Jun 01, 2010 5:13 pm

It is working fine on my box, directories are created and mounted with your code.
mfg
Top
Hu
Administrator
Administrator
Posts: 24398
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Wed Jun 02, 2010 2:05 am

If you attach a dev-util/strace to udev prior to plugging in the card, do you see it run the mount command? Does mount print any error messages?
Top
M
Guru
Guru
Posts: 432
Joined: Tue Dec 12, 2006 11:59 am

  • Quote

Post by M » Wed Jun 02, 2010 11:12 am

Maybe you can try http://proj.mgorny.alt.pl/uam/?html ? I use it and am very satisfied. Those are also just udev rules and some shell scripts.

Edit: ah, I see now that you use cryptsetup etc. nevermind...
Top
khippy
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 79
Joined: Thu Aug 29, 2002 8:32 pm
Location: Braunschweig - Germany
Contact:
Contact khippy
Website

  • Quote

Post by khippy » Tue Apr 19, 2011 1:30 am

Here the same. I have cryptsetup settled at /sbin/ though adjusting your udev-rule hasn't changed a thing.
When plugging in an encrypted drive, the directory at /media is created, but there is no xterm popping up. Even adding sudo before /sbin/cryptsetup has no effect.

Heinz, are you running your desktop as root?
--
there are no silly questions
Top
khippy
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 79
Joined: Thu Aug 29, 2002 8:32 pm
Location: Braunschweig - Germany
Contact:
Contact khippy
Website

  • Quote

Post by khippy » Thu Apr 21, 2011 11:34 pm

I have got it working:

/etc/udev/rules.d/99-crypt.mount.rules

Code: Select all

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid -p %N", GOTO="media_by_label_auto_mount_end"

# Open luks partition if necessary 
PROGRAM=="/sbin/blkid -o value -p -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"
ENV{crypto}!="?*", ENV{device}="%N"
ACTION=="add", ENV{crypto}=="?*", PROGRAM=="/root/bin/crypt.mount.sh %N %k"
ACTION=="add", ENV{crypto}=="?*", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"

# Global mount options 
ACTION=="add", ENV{mount_options}="noatime,users"
# Filesystem specific options 
ACTION=="add", PROGRAM=="/sbin/blkid -o value -p -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"

# Get label 
ACTION=="add", PROGRAM=="/sbin/blkid -o value -p -s LABEL %E{device}", ENV{dir_name}="%c"
ACTION=="add", ENV{dir_name}!="?*"

ACTION=="add", ENV{dir_name}=="?*", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k /media/%E{dir_name}"
ACTION=="remove", ENV{dir_name}=="?*", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
ACTION=="remove", ENV{crypto}=="?*", RUN+="/sbin/cryptsetup luksClose %k"
LABEL="media_by_label_auto_mount_end"
/root/bin/crypt.mount.sh

Code: Select all

#!/bin/sh
export DISPLAY=":0.0"
WHAT=$1
WHERE=$2
WHO=<place your desktop username here>
/usr/bin/sudo -u $WHO  /usr/bin/zenity --entry --hide-text=LUKS --text="LUKS open $WHAT at $WHERE"  --title "Luks Passphrase" --width 500 | /usr/bin/sudo /sbin/cryptsetup -t 15 luksOpen $WHAT $WHERE
Works perfectly at jwm with rox desktop.

Placing the contents of the crypt.mount.sh external script at /etc/udev/rules.d/99-crypt.mount.rules as the author of this thread did hasn't worked. Putting it out of it solved this issue. I don't know why.
I use gnome-extra/zenity to get a nice desktop window instead of an xterm.

Finally I am done with it. It was one a the longest run ever since using cryptsetup and a windowmanager which isn't shipped with a helper like this.

Thanks for the good start which helped finishing it enourmously.
--
there are no silly questions
Top
Post Reply

6 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic