# Automount USB disk where I want?

## bjorntj

At the moment, whenever I connect an usb stick or disk it gets autmounted under /media/disk but I would like to differentiate where each usb device is mounted... So how can tell udev (not sure if it is udev that does the automounting but I think so) where to mount a specific device?

I.e. I want my usb disk under /media/usb and my camera memory card under /media/camera, etc?

Regards,

BTJ

----------

## Dralnu

 *bjorntj wrote:*   

> At the moment, whenever I connect an usb stick or disk it gets autmounted under /media/disk but I would like to differentiate where each usb device is mounted... So how can tell udev (not sure if it is udev that does the automounting but I think so) where to mount a specific device?
> 
> I.e. I want my usb disk under /media/usb and my camera memory card under /media/camera, etc?
> 
> Regards,
> ...

 

Need to write some udev rules. I take it you are using Ubuntu here?

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

----------

## bjorntj

 *Dralnu wrote:*   

>  *bjorntj wrote:*   At the moment, whenever I connect an usb stick or disk it gets autmounted under /media/disk but I would like to differentiate where each usb device is mounted... So how can tell udev (not sure if it is udev that does the automounting but I think so) where to mount a specific device?
> 
> I.e. I want my usb disk under /media/usb and my camera memory card under /media/camera, etc?
> 
> Regards,
> ...

 

I was hoping for an easier way than to learn udev but....

And no, I am not using Ubuntu...

BTJ

----------

## Dralnu

 *bjorntj wrote:*   

>  *Dralnu wrote:*    *bjorntj wrote:*   At the moment, whenever I connect an usb stick or disk it gets autmounted under /media/disk but I would like to differentiate where each usb device is mounted... So how can tell udev (not sure if it is udev that does the automounting but I think so) where to mount a specific device?
> 
> I.e. I want my usb disk under /media/usb and my camera memory card under /media/camera, etc?
> 
> Regards,
> ...

 

I think that is pretty much the best way. I asked a similar thing, and got a similar answer  :Smile: 

----------

## bjorntj

 *Dralnu wrote:*   

>  *bjorntj wrote:*    *Dralnu wrote:*    *bjorntj wrote:*   At the moment, whenever I connect an usb stick or disk it gets autmounted under /media/disk but I would like to differentiate where each usb device is mounted... So how can tell udev (not sure if it is udev that does the automounting but I think so) where to mount a specific device?
> 
> I.e. I want my usb disk under /media/usb and my camera memory card under /media/camera, etc?
> 
> Regards,
> ...

 

Ok, but the problem is that using udev doesn't really help me... I have looked at that webpage and I now can create a symlink for my usb disk but I still haven't any controll on where it is automatically mounted....

BTJ

----------

## bjorntj

Is this really not possible?

BTJ

----------

## Yukimura

For usb it is possible to simply write this line in fstab:

 *Quote:*   

> /dev/sda1               /media/usb       auto            noauto,rw,user  0 0

 

But note that this way every device that can be found in /dev and says "hello computer I'm a sda1", will be mounted in /media/usb so for your camera you'll just have to find another way out.  :Wink: 

I hope this was helpful.  :Smile: 

Uh and another thing, first create a dir /media/usb.

Kind regards  :Smile: 

----------

## bjorntj

 *Yukimura wrote:*   

> For usb it is possible to simply write this line in fstab:
> 
>  *Quote:*   /dev/sda1               /media/usb       auto            noauto,rw,user  0 0 
> 
> But note that this way every device that can be found in /dev and says "hello computer I'm a sda1", will be mounted in /media/usb so for your camera you'll just have to find another way out. 
> ...

 

Well, helped a bit... But I still want a more finer control, so not every "sda1" disks get mounted in chosen directory....

BTJ

----------

## Yukimura

Well if you find any other solution let me know.  :Wink: 

For some time I wanted to have a bit nicer solution myself, but reading about udev was too frustrating for me.  :Very Happy: 

----------

## Dralnu

udev rules to have whatever mounted to, say /dev/camera, then in fstab /dev/camera ... /mnt/camera ...

----------

## bjorntj

 *Dralnu wrote:*   

> udev rules to have whatever mounted to, say /dev/camera, then in fstab /dev/camera ... /mnt/camera ...

 

I have a filed called 10-local.rules that contains..:

```
 

KERNEL=="sd?1", BUS=="scsi", SYSFS{model}=="SAMSUNG SP2504C ", SYMLINK+="dbdisk"

```

but it doesn't seem to work....

Any idea why?

Regards,

BTJ

----------

## bjorntj

I did a recheck and it seems that I have copied the wrong model... With the correct model name, it works like a charm... Thx...  :Smile: 

BTJ

----------

## manouchk

I think I have the "problem".

I have an external hard drive. It has severals partitions. 

When I connect it. It creates 

the devices /dev/sda1 /dev/sda5 /dev/sda7

and mount this partitions on /media/disk /media/disk-1 /media/disk-2

I'd like to mount /dev/sda7 on /media/sda7 (because I use unison to synchronise my entire home and it seems to need the same name)

So far, I've been able to modify the device name to:

/dev/aaasda1 ...

using this udev rule

BUS=="usb", KERNEL=="sd*", SYSFS{serial}=="A00000014777", NAME="aaa%k", SYMLINK+="dbdisk"

but that's not what I want!

apparently, the option SYMLINK have no effect?

Any solutions??

----------

## Yukimura

manouchk I have a less complicate solution for you.  

In your case I'd rather keep it simple in /etc/fstab. 

 */etc/fstab wrote:*   

> /dev/sda1 /media/sda1 auto noauto,rw,user 0 0
> 
> /dev/sda5 /media/sda1 auto noauto,rw,user 0 0
> 
> /dev/sda7 /media/sda1 auto noauto,rw,user 0 0

 

Juste make sure you make folders in /media.

 *Quote:*   

> mkdir /media/sda1
> 
> mkdir /media/sda5
> 
> mkdir /media/sda7

 

----------

## manouchk

Good suggestion!

Here is what I used :

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

BUS=="usb", KERNEL=="sd*", SYSFS{serial}=="A00000014777", NAME="hd_usb%n", SYMLINK+="dbdisk"

manu manu # cat /etc/fstab|grep hd_usb

/dev/hd_usb7 /media/sda7 auto noauto,rw,user 0 0

With that, partition number 7 of that specific external hard drive is mounted automatically on /media/sda7 !   :Very Happy: 

By the way I also tried that and there were a problem of permission with 

manu manu # cat /etc/udev/rules.d/10-local.rules

BUS=="usb", KERNEL=="sd*", SYSFS{serial}=="A00000014777", NAME=""%k, SYMLINK+="hd_usb%n"

manu manu # cat /etc/fstab|grep hd_usb

/dev/hd_usb7 /media/sda7 auto noauto,rw,user 0 0

With the last configuration, using NAME=""%k, the advantage is that in KDE when right click on the hd icone and select option "safely unplug or something similar", it umounts all partitions. In the former case (NAME="hd_usb%n") it does just unmout one partition and therefore partitions needs to umounted one by one

I'm already happy with the actual solution but is that possible to have both advantages?

----------

## Yukimura

How about going to terminal and writing down umount /dev/sda ? 

I don't know if it works but I also don't know if it doesn't.  :Very Happy: 

----------

