You are not logged in.

#1 2011-03-21 13:08:34

Wintershade
Member
From: Croatia
Registered: 2008-02-18
Posts: 175
Website

Mounting CD/DVD under specific point, and automounting - udev rules?

Hi, I've been tinkering with udev for the past few days and I'm not really sure where I'm going with this...
Also I'm not really sure if I can achieve what I want with udev (I probably can, so I'm hoping someone here can tell me how).
Anyway, I have two problems which I'm stuck with.

First of all, my udev is not automounting CDs or DVDs, or removable drives sad
I can mount them with KDE Device Notifier plasmoid (I'm using KDE), but I'd like to have them mounted automatically upon insertion, without any additional clicking or typing.
I've been tinkering around with the rules, however the furthest I've come to solving this problem is no different from the ruleset by user tomk which I found on the wiki:

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

# Get label
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"
# use basename to correctly handle labels such as ../mnt/foo
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"

ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su wintershade -c '/usr/bin/pmount %N %E{dir_name}'"
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su wintershade -c '/usr/bin/pumount /media/%E{dir_name}'"
LABEL="media_by_label_auto_mount_end"

(I've changed his username to my own, as described in the wiki)
This set of rules does automatically mount USB drives, but not optical (CD/DVD) discs.
Also, the problem I have with these rules is that I still can't unmount it as a user. When I click on the "eject" button in KDE Device Notifier plasmoid, it attempts to remove the device, but cannot do it until I give it the root password. This kinda puzzles me, because pmount and pumount are supposed to be run by user, right?
Is there a way to prevent KDE from asking me the root password every time? What am I doing wrong?



Secondly, I would like to mount my optical discs (CDs and DVDs) under a specific (custom) mountpoint
(i.e. I want all my optical discs to be mounted under /media/disc, rather than /media/<disc_label>. I've done this once via HAL rules, with the help of you guys, but now I'm totally lost.
So far I've got this...

KERNEL!="sr0", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"

ACTION=="add", RUN+="/bin/su wintershade -c '/usr/bin/pmount %N disc'"
ACTION=="remove", RUN+="/bin/su wintershade -c '/usr/bin/pumount /media/disc'"
LABEL="media_by_label_auto_mount_end"

(basically it's almost the same thing as above, it just omits the part where udev gets the drive label. also, I've replaced the "KERNEL!=sd[a-z]*" expression with "KERNEL!=sr0" - my optical device - but that doesn't seem to work.)
Unfortunately this doesn't either automount my optical discs, nor does it mount as /media/disc, but as /media/<disc label>.


What am I doing wrong? Any help would be much appreciated.
Thanks in advance! smile

Last edited by Wintershade (2011-03-21 13:11:15)


Only the best is good enough.

Offline

#2 2011-03-21 17:07:49

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: Mounting CD/DVD under specific point, and automounting - udev rules?

It is good to see that you already searched and tried to solve your problem by yourself before posting. Nice!

Wintershade wrote:

This set of rules does automatically mount USB drives, but not optical (CD/DVD) discs.

That's normal as the preceding set of rules concerns only devices of the form sd[b-z]* which is not the case of optical disks with device /dev/sr0.

Wintershade wrote:

Also, the problem I have with these rules is that I still can't unmount it as a user. When I click on the "eject" button in KDE Device Notifier plasmoid, it attempts to remove the device, but cannot do it until I give it the root password. This kinda puzzles me, because pmount and pumount are supposed to be run by user, right?

I think the eject function uses umount and not pumount, only pumount can unmount devices under user login.
So you can change the eject command used by KDE for a script which pumounts the device and then ejects it wilthout unmounting.

Wintershade wrote:

Secondly, I would like to mount my optical discs (CDs and DVDs) under a specific (custom) mountpoint
(i.e. I want all my optical discs to be mounted under /media/disc, rather than /media/<disc_label>.
So far I've got this...

KERNEL!="sr0", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"

ACTION=="add", RUN+="/bin/su wintershade -c '/usr/bin/pmount %N disc'"
ACTION=="remove", RUN+="/bin/su wintershade -c '/usr/bin/pumount /media/disc'"
LABEL="media_by_label_auto_mount_end"

That cannot work as you expect because /dev/sr0 always exists, from the boot of your machine, it is not created when you insert a CD/DVD.
So the rules will not be triggered when you want them to be.

I suggest that you follow the wiki advice :

Mount CDs

To auto mount a CD a simple UDisks wrapper will get the job done properly.

The UDisks wrapper can also be used to automount removable devices without writing udev rules.
You may find an easier solution looking in this direction.
But If you want to use udev rules, it's your choice for removable medias (personally I don't like the idea to unmount a device when plugged out).
I don't think it's possible to manage optical disks automounting with udev rules though.
I hope you to find the solution which gives you the result you expect.

Last edited by berbae (2011-03-21 22:20:46)

Offline

#3 2011-03-23 09:50:35

Wintershade
Member
From: Croatia
Registered: 2008-02-18
Posts: 175
Website

Re: Mounting CD/DVD under specific point, and automounting - udev rules?

@berbae, thank you for the hints you've provided and the good will to help.

Okay, I've mostly solved what I currently need. My main problem was specified here, i.e. I wanted to mount optical media in such a way in order to access it from WINE. Since that part is solved, I don't really need to mount optical media under a specific mountpoint (e.g. /media/disc, as noted before) for any other reason.

So I'm currently using udiskie to automatically mount all media, including optical discs, and I can access /media/cd with WINE for any CD/DVD I insert.

What do you guys think of this solution?
I've read somewhere that udiskie is also obsolete/unneeded, but I'm not sure if that was coming from a very legit source.
So what gives? If udiskie gets abandoned, am I going to have to dig through manuals, tutorials and ask you people on the forum for advice again, or will udev come up with some elegant solution for automounting?

Thanks once again! smile


Only the best is good enough.

Offline

Board footer

Powered by FluxBB