You are not logged in.

#1 2008-02-28 00:56:42

solanoalves
Member
From: Curitiba Brazil
Registered: 2007-12-02
Posts: 54

[S] how do I create a link symbolic in Desktop through rules in udev ?

Hi everyone!

My Rule:

[solano@localhost ~]$ cat /etc/udev/rules.d/01-montagem.rules
KERNEL=="sd[c-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/mkdir -p /media/usb%n"

ACTION=="add", KERNEL=="sd[c-z][0-9]", PROGRAM=="/lib/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/usb%n", OPTIONS="last_rule"

ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usb%n", OPTIONS="last_rule"

ACTION=="remove", KERNEL=="sd[c-z][0-9]", RUN+="/bin/umount -l /media/usb%n"
ACTION=="remove", KERNEL=="sd[c-z][0-9]", RUN+="/bin/rmdir /media/usb%n", OPTIONS="last_rule"

I dont got configure my arch to create a icon in desktop when I plug a USB device, thus I try add a line in my udev.rules in /etc/udev/rules.d/01-montagem.rules to create a link in desktop when mounted device by add :

ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/cp /media/usb%n /home/solano/Desktop/usb%n"

however it dont work, then I come here for help of you to try  'fix ' it.

Thanks and sorry by poor english.

Last edited by solanoalves (2008-02-28 03:34:36)


big_smile How did you know? I love this song! big_smile

Offline

#2 2008-02-28 02:49:58

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: [S] how do I create a link symbolic in Desktop through rules in udev ?

Try these rules

ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/ln -s /media/usb%k /home/solano/Desktop/usb%k"
ACTION=="remove", KERNEL=="sd[c-z][0-9]", RUN+="/bin/rm -f /home/solano/Desktop/usb%k"

The first rule should be placed before your mount rule and the second rule should be placed before your umount rule (it's important because mount rules are using OPTIONS="last_rule"). Also I'm using %k not %n because when you unplug your usb stick %n might return an empty string causing the second rule to not work. However if %n works for you (which means the link is created and deleted on usb stick removal) you can change %k to %n (the replacement must be done in all rules of course).

Last edited by lanrat (2008-02-28 02:50:53)

Offline

#3 2008-02-28 03:34:11

solanoalves
Member
From: Curitiba Brazil
Registered: 2007-12-02
Posts: 54

Re: [S] how do I create a link symbolic in Desktop through rules in udev ?

yeah it work!! thank you so much Ianrat. Is too hard create a device icon instead of folder icon in desktop when I mount my device?


big_smile How did you know? I love this song! big_smile

Offline

#4 2008-02-28 16:06:32

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: [S] how do I create a link symbolic in Desktop through rules in udev ?

I have no idea :-) I've never done it. I guess that depends what you're using for your DE. I think you should first try to manually create an icon on the desktop and change it to the icon picture that you want. It should create some file (*.desktop ?) that you could use in your udev script (possibly changing its contents with sed or something like this to include correct path to the device). If there is no file defining an icon you can try to use some tool from your DE (like dcop in KDE) but I don't know much about this, sorry.

Offline

#5 2008-03-08 17:51:19

solanoalves
Member
From: Curitiba Brazil
Registered: 2007-12-02
Posts: 54

Re: [S] how do I create a link symbolic in Desktop through rules in udev ?

How do I umount a device mounted by udev ? Now when I plug my camera in usb a icon is created in desktop but I dont know how umount it


big_smile How did you know? I love this song! big_smile

Offline

#6 2008-03-09 00:21:47

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: [S] how do I create a link symbolic in Desktop through rules in udev ?

It should be umounted by udev rules with ACTION=="remove". In fact, you don't umount it at all. You just unplug the device (which is safe if you're using flush and not async in mount options) and udev simply cleans up with umount -l ("lazy" umount - check the mount manpage to know how it works). If you're creating any additional files/directories (like /media/usb-something) you should add another rule to simply remove it with rm or rmdir (just like in your first example). If it doesn't work for some reason (you can see the device still mounted or a directory/file still exists) doublecheck the syntax and switch from %n to %k in all rules.

Last edited by lanrat (2008-03-09 00:24:44)

Offline

Board footer

Powered by FluxBB