# Automounting USB thumb drives with different partition types

## storri

I have two thumb drives for working with Windows and Linux. One drive is formated Fat32 for transfering files between a Windows and Linux machines. The other drive is formated with reiserfs for exclusive use with Linux. My original setup was having a entry in the /etc/fstab file for the Fat32 thumb drive so it was automounted when I inserted the drive as my normal user. Now if I put the other thumb drive into the USB port on the machine it ofcourse cannot be mounted since its the wrong filesystem type. How can I make it such that regardless of what is placed into the USB port as a normal user it is mounted with the correct filesystem type?

----------

## Section_8

I would look at writing udev rules for them so that each drive gets its own pre-configured symlink in /dev and then you can put an entry for each drive in fstab with the right mount options.

Info on writing udev rules:

http://www.reactivated.net/writing_udev_rules.html

http://gentoo-wiki.com/HOWTO_Customizing_UDEV

----------

## storri

Here is one rule for the Lexar USB drive (FAT32):

 *Quote:*   

> 
> 
> BUS=="usb", ATTRS{serial}=="302AC710074255240905", KERNEL=="sd?1", NAME="%k", SYMLINK="lexar_usb"
> 
> 

 

I got the ATTRS value from the udevinfo output:

 *Quote:*   

> 
> 
>  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-5':
> 
>     KERNELS=="1-5"
> ...

 

When I mount the drive I do not see /dev/lexar_usb. How do I change the mount name? For example its being mounted as /media/disk. I cannot tell if my udev file, 10-local.rules, in /etc/udev/rules.d/ directory is being checked.

----------

## vandien

I use autofs which handles this well:

http://gentoo-wiki.com/HOWTO_Auto_mount_filesystems

```
usb     -fstype=auto :/dev/sdb1
```

results in /dev/sdb1 being automatically mounted whenever any program tries to access /mnt/usb, and then umounted automatically when the program is not using it anymore.

----------

## Section_8

Did you do

```
udevcontrol reload_rules

udevstart
```

After you saved your rule?

----------

## storri

I did not restart udev since I did not know how to do it until you show me. Thanks.

Now its following the Lexar rule but its mounting it in /media with the name 'disk'. I would like to change it mount location to /mnt.

Any ideas on how to do that? Is it another udev attribute in the rules file? I didn't see anything in the man page.

----------

## Section_8

Try putting an entry for it in /etc/fstab with the mount point and options you want (mkdir /mnt/whatever first).

----------

## storri

How can I put an entry in the /etc/fstab file for each of the USB drives? Right now I want to know who is mounting the drive? Is it udev or another service? I have HAL installed. Is it detecting the drive and mounting it for me? I would like to mount either USB and have it appear in the /mnt directory. I don't want to confuse things by having the same name for the mount point. It would be nice to alter that as well. For now I need to figure who is mounting the drive.

----------

## Section_8

Ok, I'm not exactly sure what you want - I reread your original post - do you want either drive to mount to the same mount point under /mnt?  You could try editing your /etc/fstab entry and change the file system option to auto so it would work for either file system.  I have 2 flash drives - they use the /dev/sda1 node and auto-mount to /mnt/flash with this:

```
/dev/sda1       /mnt/flash  auto        noauto,user,noatime     0 0
```

They are both vfat but I don't think it would matter what file system they were.  This works unless I try to plug them both in.

I was assuming you wanted to give each of them a different, dedicated mount point (say /mnt/flash1 and /mnt/flash2) in which case you would probably need udev rules to create a different /dev node for each drive and something like this in /etc/fstab:

```
/dev/lexar       /mnt/lexar  auto        noauto,user,noatime     0 0

/dev/whatever       /mnt/whatever  auto        noauto,user,noatime     0 0
```

You could also try autofs as vandien suggested - I've never used that but I may play with it when I get the time.

----------

## storri

I apologize for the confusion. What I want to do is the second option of having multiple mount points. I made the changes to the fstab file for the drives:

 *Quote:*   

> 
> 
> /dev/lexar_usb          /mnt/lexar      auto            noauto,rw,user,noatime  0 0
> 
> /dev/corsair_usb        /mnt/corsair    auto            noauto,rw,user,noatime  0 0
> ...

 

No the only issue is to convince kde to use the new mount points rather than the standard /media/sdb1 point. Any ideas on this?

----------

## Section_8

Ok, I have KDE and putting those entries in fstab caused KDE to use them.  If I let KDE open a konq window when I plug in a flash drive, konq says the directory is "system:/media/sda1", but if I look at the actual mounts (df command), it has actually used the "/mnt/flash" mount point in fstab.  The /media/sda1 mount point is apparently a virtual kioslave directory.

----------

## storri

When I now put the USB drive in I get a message back saying "permission denied". Konqueror opens and starts to display /media/sdb1. That is when the pop up window appears. The drive is not mounted at that point. If I do 'mount /mnt/lexar' in a terminal then the drive is mounted. The internal mount point is still with root permission (/mnt/lexar) but the contents of the drive are mounted with user permissions. So I cannot figure out from the vague error message what the reason is for "permission denied".

----------

## Section_8

This section of that udev-rules howto web page tells how to setup permissions:

http://www.reactivated.net/writing_udev_rules.html#ownership

Did you play around with that?  I'm not at home to look at it, but I had to write a udev rule for a usb card reader about a year ago and I think I had to set permissions there.  

I have tried to configure my system with autofs and it's pretty cool because it automagically mounts the drive the first time anything tries to access its /mnt mount point.  The one snag I hit is that I couldn't unmount it as user from the kde device icon because (I assume) autofs mounts it in kernel mode so only root could unmount it.  I set it up to mount with the users (instead of user) option and that seemed to take care of it.

----------

## storri

Here are my rules that I have right now:

 *Quote:*   

> 
> 
> BUS=="usb", ATTRS{serial}=="A196000000000032", KERNEL=="sd?1", NAME="%k", SYMLINK="corsair_usb", GROUP="usb"
> 
> BUS=="usb", ATTRS{serial}=="302AC710074255240905", KERNEL=="sd?1", NAME="%k", SYMLINK="lexar_usb", GROUP="usb"
> ...

 

My user is a part of the usb group. This should be similar to using the 'users' group.

----------

## Section_8

Do you get the permission denied using the mount command or just kde?  

I've been playing with this some.  I've found that if I use the /dev symlink my udev rule creates in /etc/fstab, I can mount a usb device as user with the mount command, but if I try to mount it from the kde storage media icon, I get a permission denied error.  If I use the actual udev name (/dev/sdc1) in /etc/fstab, I can mount it from the storage media icon.  I don't know what the difference is.

----------

## storri

 *Quote:*   

> 
> 
> Do you get the permission denied using the mount command or just kde?
> 
> 

 

Just in kde. Right now I am rebuilding things so I will test your theory later.[/quote]

----------

## zigver

 *Section_8 wrote:*   

> Do you get the permission denied using the mount command or just kde?  
> 
> I've been playing with this some.  I've found that if I use the /dev symlink my udev rule creates in /etc/fstab, I can mount a usb device as user with the mount command, but if I try to mount it from the kde storage media icon, I get a permission denied error.  If I use the actual udev name (/dev/sdc1) in /etc/fstab, I can mount it from the storage media icon.  I don't know what the difference is.

 

I messed with this today for a couple hours, too.  I tried using udev and putting in fstab entries using the symbolic, but kde storage media didn't like that and gave the permission denied problem.  Yet manual mounting via fstab entry worked flawlessly.  Then I noticed you can set a property on the device and specify the mountpoint through kde storage media.  Although it must start with /media, it worked fine even when I removed my custom udev rules.

What I didn't check, since I don't have the hardware, is to see if it will distinguish between identical types of devices.  Excepting that, the kde media applet seems to handle devices on its own without needing extra udev rules.

----------

