# automount usb device and add usb to user [SOLVED]

## cwc

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?

----------

## amdg

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:

```
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).

----------

## cwc

I'll give this a try and let you know how it goes.

thank you!

----------

## cwc

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

----------

## lpgasparotto

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.

----------

## genmich

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

----------

