• I have a small computer with 2 USB sockets : A and B.
  • I want any external USB disk, attached to socket A - to be mounted as "deviceA"
  • I want any external USB disk, attached to socket B - to be mounted as "deviceB"

Any amount of different disks may be attached to socket A. They all shall be mounted as "devicesA".
Because of this case I can not use UUIDs of disks and have to identify the sockets.

I am using udev rules to automount the disks. How would I implement that?


Take a look at the output of udevadm(8). For me the disk I used was /dev/sdd so I used:

udevadm info --attribute-walk --name=/dev/sdd

This gives me information about the device itself and the parent devices. One of the parent devices seemingly corresponds to the USB port it is connected to and varies depending on where I connected the disk. For me it is this entry which I'd use for mathing in the udev(7) rule:

looking at parent device '/devices/pci0000:00/0000:00:12.2/usb1/1-4/1-4:1.0':

Note the name is KERNELS, SUBSYSTEMS and DRIVERS and not KERNEL, SUBSYSTEM and DRIVER here. According to the page at http://www.reactivated.net/writing_udev_rules.html and the man page for udev(7) these are matching not only the device itself (as the variants not ending in S do), but also the parent devices.

Thus it should be possible to give USB storage on a given USB port a fixed name by using this data for matching in the udev rule. The actual mount can then also be done with a "RUN" inside an udev rule as far as I understand the man page for udev(7). It might be necessary to use a separate rule for the mount, though.

  • Right, I have found a detailed describtion about parsing the parent device string in order to get the mountname: jonnor.com/2010/08/… – Skip Jan 5 '14 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.