udev usb everytime different path

809 views Asked by At

I have following problem with my Linux board: My USB media device every time mounted as different device in /dev/ folder:

First time I attach the USB, it appears as

/dev/sdb1

Then, I remove usb and plug it in again and it gets different name:

/dev/sdc1

And so on and so forth.

I want it to have constant name always, so I wrote following udev rule:

SUBSYSTEM=="block",ENV{ID_SERIAL}==" serial id ",NAME="myusbmedia"

This rule doesn't work. I could have symbolic name with following rule:

SUBSYSTEM=="block",ENV{ID_SERIAL}==" serial id ",SYMLINK="myusbmedia"

This rule works, but it doesn't solve the problem, because usb still gets /dev/sd[b,c,d, ...] names...

Does anyone have an idea how to make USB appear in /dev/ under the same device node with the same name?

2

There are 2 answers

1
Idan On

When you connect your device, i assume you use mount in order to approach its files. You should unmount the drive (using the umount command) before you disconnect it, and then it should stay as the same device at the /dev folder.

For example:

umount /dev/sdc1
0
Uwe Geuder On

The problem is unsolvable, at least using udev. The device node is created by the kernel, not by udev. So you need to modify the kernel.

From man page udev(7):

 The following keys can get values assigned:
       NAME
          The name to use for a network interface. The name of a device 
           node cannot be changed by udev, only additional symlinks
           can be created.

See also http://lists.kernelnewbies.org/pipermail/kernelnewbies/2015-April/013889.html

Something in that direction has been proposed to the kernel, but it has not been accepted into mainline Linux http://thread.gmane.org/gmane.linux.scsi/70947