You are not logged in.

#1 2012-10-24 20:22:57

jwesley
Member
Registered: 2012-10-16
Posts: 4

UDEV and USB Automount

Hoping someone can shed some light on this issue.
I'm writing own udev rule to automatically mount a USB drive used for backing up my system. The below udev rule works fine:

KERNEL=="sdc1", NAME="%k", RUNSYMLINK+="usb_storage"

The problem I'm having now is with the RUN+="<shell script here>"

The script will not execute. Does anyone see something that stands out in my rule?

Offline

#2 2012-10-24 21:47:44

tomegun
Developer
From: France
Registered: 2010-05-28
Posts: 661

Re: UDEV and USB Automount

Seems there was a copy/paste error there. There is no RUNSYMLINK key.

Regardless of that, you should be aware that it is strongly discouraged to mount things directly from udev rules. You should rather use a storage daemon such as udisks (for stuff that should be owned by the active user) or fstab (for stuff that should be owned by the system). In the latter case you really want systemd in order to handle hotplugging properly though, as initscripts can't do that.

Offline

#3 2012-10-25 01:14:08

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

Re: UDEV and USB Automount

jwesley wrote:

KERNEL=="sdc1"

That's a terrible way of matching. Use e.g.:

ACTION=="add", KERNEL=="sd*", ATTRS{serial}=="0042597blahblah", SYMLINK+="mydrive%n", RUN+="mount /media/mydrive"

To get the serial, use e.g.:

udevadm info -a --name /dev/sdc1 | grep serial

And of course, there should be an entry in /etc/fstab, e.g.:

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

And the mountpoint should already exist:

mkdir -p /media/mydrive

Edit: Another nice udev rule is:

ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},flush,utf8,gid=100,umask=002"

Last edited by brebs (2013-05-22 09:48:11)

Offline

Board footer

Powered by FluxBB