You are not logged in.

#1 2009-10-21 20:07:43

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Automounting with udev/hal

Hey,

I've gone through this, specifically:

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule" 
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k" 
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="%c"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM!="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="usbhd-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/%E{dir_name}" 
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /media/%E{dir_name}", OPTIONS="last_rule" 
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/%E{dir_name}", OPTIONS="last_rule" 
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/%E{dir_name}" 
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/%E{dir_name}", OPTIONS="last_rule"

The problem is that the folder in /media, created in the 4th add action has uid and gid root. Therefore, as a normal user I cannot write! Any thoughts how to make it storage, or something like that?

Thanks in advance!

Offline

#2 2009-10-21 20:27:33

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: Automounting with udev/hal

wouldn't this work?

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/chgrp storage /media/%E{dir_name}"

Offline

#3 2009-10-21 20:52:28

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Re: Automounting with udev/hal

Didn't work.
I tried to do it manually after the mount, and I get:

/bin/chgrp: changing group of `/media/(...)': Operation not permitted

Offline

#4 2009-10-22 15:18:43

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Re: Automounting with udev/hal

No one automounts with udev/hal?! yikes
What's the best alternative then? I use XMonad.

Offline

#5 2009-10-22 15:40:15

s3kt0r
Member
Registered: 2009-01-20
Posts: 208

Re: Automounting with udev/hal

I just use HAL and it works fine. Your user is a part of storage group?


box1: Arch (linux-3.17-rc5)
box2: Gentoo (linux-3.17-rc5)
wm: subtle

Offline

#6 2009-10-22 15:59:36

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Re: Automounting with udev/hal

Yeah.
The mounting part seems to be fine, since /dev/sdb[1..9] uid is root and gid corresponds to the one defined in the udev rule, GROUP="users".

The problem is that the directory under /media, created with mkdir -p in one of the RUN rules, has uid/gid root. I think that's understandable, since udev probably runs under root?

My question is, how do I change its gid to storage for example. I tried adding a new rule after the mkdir -p executing chgrp as suggested, but I get "operation not permitted".

Even if I try to do it manually after the automount, I still get that.

Also, if I manually unmount the device not only the /media sub-directory of the mount doesn't disappear it's gid changes to storage! But it's not mounted anymore, so it is empty. neutral

Last edited by tvale (2009-10-22 16:04:35)

Offline

#7 2009-10-22 23:25:58

s3kt0r
Member
Registered: 2009-01-20
Posts: 208

Re: Automounting with udev/hal

As I didn't know more, I went looking, although I don't have the time to read through it all, but here are the links:

http://bbs.archlinux.org/viewtopic.php?id=54378 and http://reactivated.net/writing_udev_rules.html

Another thing, I noticed that in your rules, you have:

ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k" 
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/%E{dir_name}"

Shouldn't the second line be like

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/%k"

Sorry if that doesn't help.

edit: code tags

Last edited by s3kt0r (2009-10-22 23:27:16)


box1: Arch (linux-3.17-rc5)
box2: Gentoo (linux-3.17-rc5)
wm: subtle

Offline

#8 2009-10-22 23:50:07

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Re: Automounting with udev/hal

As far as I understand, that would only change the name of the created folder. As above there is a rule defining an env value for either the label of the partition or usbhd-<stuff>, that's going to be the name of the folder.

Problem is the ownership of the directory. hmm

Oh well, thank you very much anyway!

Offline

#9 2009-10-23 16:42:31

s3kt0r
Member
Registered: 2009-01-20
Posts: 208

Re: Automounting with udev/hal

Maybe a more advanced user could help us/you out. Did you read all the stuff in the links I posted before? No help there huh.

If I find anything related to this, you'll be the first to know. Good luck.


box1: Arch (linux-3.17-rc5)
box2: Gentoo (linux-3.17-rc5)
wm: subtle

Offline

#10 2009-10-23 18:47:17

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Automounting with udev/hal

tvale wrote:

Didn't work.
I tried to do it manually after the mount, and I get:

/bin/chgrp: changing group of `/media/(...)': Operation not permitted

Did you run chgrp as root? It works when I do it on a mounted dir:

$ sudo chgrp users /media/usb_sdc1/

I can write to FAT flash drives even though the parent directory /media/$drivelabel is set to root:root.  Ext3/4 device folders are set to root:storage.  Both work.

For reference:

# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
#
# /etc/udev/rules.d/10-my-udev.rules

# automount usb block devices to /media with symlinks in /mnt
# /media uses volume label while /mnt uses sd[a-z][1-9]
# clean up both /media and /mnt when devices are removed
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usbhd_%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usbhd_%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="%c"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM!="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="usbhd_%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/%E{dir_name}"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /media/%E{dir_name} /mnt/usbhd_%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,users,noauto,flush,quiet,noatime,dmask=000,fmask=111 /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,users,noauto,sync,dirsync,noatime /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd_%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/%E{dir_name}"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /media/%E{dir_name}", OPTIONS="last_rule"

PS: Make sure you're a member of the storage group:

$ sudo gpasswd -a $USER storage

Last edited by thayer (2009-10-23 20:20:29)


thayer williams ~ cinderwick.ca

Offline

#11 2009-10-23 21:16:25

tvale
Member
From: Portugal
Registered: 2008-12-11
Posts: 175

Re: Automounting with udev/hal

thayer wrote:

Did you run chgrp as root? It works when I do it on a mounted dir:

$ sudo chgrp users /media/usb_sdc1/

I can write to FAT flash drives even though the parent directory /media/$drivelabel is set to root:root.  Ext3/4 device folders are set to root:storage.  Both work.

Aye, I ran it as root.

thayer wrote:

PS: Make sure you're a member of the storage group:

$ sudo gpasswd -a $USER storage

Aye again, I am a member of the storage group!

thayer wrote:

For reference:

# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
#
# /etc/udev/rules.d/10-my-udev.rules

# automount usb block devices to /media with symlinks in /mnt
# /media uses volume label while /mnt uses sd[a-z][1-9]
# clean up both /media and /mnt when devices are removed
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usbhd_%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usbhd_%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="%c"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM!="/lib/initcpio/udev/vol_id --label %N", ENV{dir_name}="usbhd_%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/%E{dir_name}"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /media/%E{dir_name} /mnt/usbhd_%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/initcpio/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,users,noauto,flush,quiet,noatime,dmask=000,fmask=111 /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,users,noauto,sync,dirsync,noatime /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd_%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/%E{dir_name}"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /media/%E{dir_name}", OPTIONS="last_rule"

After analysing your rules, I noticed that you have the users mounting options, which I curiously had already tried but appended to the end of all options unlike you.
I was coming to post my ugly work around, which included using the uid=$USER option. It's ok because it is a single user machine, but still.
Surprisingly, I tried your rules and it works fine!

Even more surprising, I tried again the rules from the udev wiki entry and guess what. It's working.
Something must've been wrong, I don't know what, but apparently it's fixed now. Oh well.

Thank you guys!

Last edited by tvale (2009-10-23 21:16:56)

Offline

Board footer

Powered by FluxBB