Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
automount usb device and add usb to user [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
cwc
Veteran
Veteran


Joined: 20 Mar 2006
Posts: 1402
Location: Tri-Cities, WA USA

PostPosted: Mon Dec 22, 2008 2:22 pm    Post subject: automount usb device and add usb to user [SOLVED] Reply with quote

I'd like to automount a usb device and add usb to a non-root user.

First: How do you make a usb group to add to a user?

Socond: What's the best howto to get help with automounting?
_________________
Without diversity there can be no evolution:)


Last edited by cwc on Wed Dec 24, 2008 6:01 am; edited 1 time in total
Back to top
View user's profile Send private message
amdg
n00b
n00b


Joined: 27 Oct 2008
Posts: 45

PostPosted: Mon Dec 22, 2008 4:19 pm    Post subject: Reply with quote

I got this from one of the udev tutorials floating around the net (will post the link if I can find it again). Drop this in /etc/udev/rules.d:

Code:
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n"
ACTION=="add", KERNEL=="sd[b-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 /mnt/usb%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /mnt/usb%n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"


Name the file 10-automount-usb.rules or something. It doesn't matter what you call it as long as it ends with .rules and starts with a low number (so they get loaded before everything else).

You do have to adjust the KERNEL regex parameters above to match what your USB devices will be potentially named (i.e. it should read sd[c-z][0-9] if your devices start showing up as /dev/sdc and so forth).
Back to top
View user's profile Send private message
cwc
Veteran
Veteran


Joined: 20 Mar 2006
Posts: 1402
Location: Tri-Cities, WA USA

PostPosted: Mon Dec 22, 2008 4:21 pm    Post subject: thank you Reply with quote

I'll give this a try and let you know how it goes.
thank you!
_________________
Without diversity there can be no evolution:)
Back to top
View user's profile Send private message
cwc
Veteran
Veteran


Joined: 20 Mar 2006
Posts: 1402
Location: Tri-Cities, WA USA

PostPosted: Tue Dec 23, 2008 5:46 am    Post subject: Reply with quote

Works great. Nice. I can even write to the usb drive.
The script that was provided creates a /mnt/usb1 directory.
I mount the usb flash drive at /mnt/usb1. I'm assuming the usb1 is due to the script.

I added this script to /etc/udev/rules.d

I did not have to modified my fstab to get this work:
/dev/sda1 /mnt/usb auto noauto,users,rw 0 0


Thanks
_________________
Without diversity there can be no evolution:)
Back to top
View user's profile Send private message
lpgasparotto
n00b
n00b


Joined: 29 Jan 2009
Posts: 12
Location: Buenos Aires, Argentina

PostPosted: Wed Feb 04, 2009 1:01 am    Post subject: Reply with quote

Hi,

The script also works great for me (I changed mnt for media) but when I try to unmount de pendrive I get this:
umount /media/usb1
umount: /media/usb1 is not in the fstab (and you are not root)

Then if I do:
sudo umount /media/usb1
It works!

I don't have that problem with CDs or DVDs.

I added my user to groups plugdev, users and usb.

I'd like to be able to umount usb storage devices as a user. Also I'd like xFce create an icon when an USB device is plugged in in the same way it happens with CD ROMs.

Thank you very much in advance.
Back to top
View user's profile Send private message
genmich
Apprentice
Apprentice


Joined: 03 Apr 2003
Posts: 196

PostPosted: Fri Jun 12, 2009 9:58 am    Post subject: Reply with quote

How do I need to change the udev-rule to mount fully formated usb sticks (/dev/sdb/)? It seems to work only with /dev/sdbX instead of /dev/sdb
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum