You are not logged in.

#1 2014-09-10 17:38:59

ttmdear
Member
Registered: 2014-08-26
Posts: 9

udev and mount usb

Hi gues

I''m new in arche and generalny in linux .

Lately I wanted to automount my MP3 player when i plug in him.
Let's move to the point .

Firstly i writen script to mount

#!/bin/bash
sleep 10
echo "pawel" >> /home/lenovo/pawel.txt
/bin/mount -o ro /dev/sony_walkman /mnt/sony_walkman
exit

Next

My udev rule 
SUBSYSTEM=="block", ATTRS{ventor}=="SONY", SYMLINK+="sony_walkman:, RUN+="/bin/sh -c 'sudo /home/lenovo/.scripts/mount_sony_walkman.sh'"

When i plug the mp3 player the script i called because the file pawel.txt is changed .
By disk is not mount

When i invoke the script in console than the disk is mounting.

Offline

#2 2014-09-10 19:38:48

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: udev and mount usb

You have not closed the quotes for SYMLINK+=".....   <NO " HERE>    (if that's clear smile

Also, ATTRS will match too many levels, make the rule specific to the appropriate level, then you won't need hacks like "sleep 10".

See example.

Last edited by brebs (2014-09-10 19:39:51)

Offline

#3 2014-09-10 20:08:31

progandy
Member
Registered: 2012-05-17
Posts: 5,196

Re: udev and mount usb

Oh, and udev kills the shell after a few seconds, so your sleep(10) might prevent your script from doing anything before that time.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#4 2014-09-10 21:12:42

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: udev and mount usb

And finally - udev is the wrong tool for automounting removable drives. You need something based on udisks/udisks2.

This functionality is typically built in to DEs such as GNOME, KDE, etc, and smaller utilities such as udiskie can be used with slimmer setups.

Offline

#5 2014-09-10 21:14:54

ttmdear
Member
Registered: 2014-08-26
Posts: 9

Re: udev and mount usb

Thanks for reply .

brebs
I am doing according with that you've written in example but nothing happend .
The disk isn't mounted.
I'am tired now , so maybe i do somethnig in wrong way . I will check once again tomorrow .

Member
that it means the script has to be short ?

Forum Fellow
I see , so generally i'd like to run any script when my device is plug in and it  should not be removable
disk. I took it as example .
How can i achieve this without udev .

I think that I can write script whose check in some time interval if something appeared in /dev
If I would plugin the mp3 player and udev create symlink "sony_walkman" than my script
which is checking can react

I don't know if it is good idea , maybe there is better solution.

Last edited by ttmdear (2014-09-11 04:33:32)

Offline

#6 2014-09-11 09:10:05

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

Re: udev and mount usb

I don't use it myself, but I think devmon can launch a command when a device is plugged in.

Offline

#7 2014-09-11 15:22:05

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: udev and mount usb

ttmdear wrote:

I wanted to automount my MP3 player when i plug in him

ttmdear wrote:

i'd like to run any script when my device is plug in

These are two different requirements - which one do you want?

BTW, "Member" and "Forum Fellow" are titles, not user names. It's customary to address people by their user name, as you managed to do with brebs.

Offline

#8 2014-09-11 18:44:19

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: udev and mount usb

I use a slightly better method these days, which is:

In /etc/udev/rules.d/10-local.rules

ACTION=="add", KERNEL=="sd*1", ATTRS{serial}=="BIGLONGLISTOFHEXCHARS", SYMLINK+="mydrive%n", RUN+="/root/bin/mntmydrive"

And that file contains, essentially:

if ! mountpoint -q /media/mydrive ; then
    mount /media/mydrive
fi

And there's an appropriate entry in /etc/fstab, e.g.:

/dev/mydrive1  /media/mydrive  vfat  noauto,noatime,users,flush,gid=100,umask=007

If it doesn't work for you, do some debugging.

Remember to run this, after changing udev rules:

udevadm control --reload

Offline

Board footer

Powered by FluxBB