I'm working with mass testing and duplication of USB flash memory on Linux.

The script I wrote for this stores paths to /dev/disk/by-path to detect if a device was plugged into a specific USB port - this way the user can connect what is displayed to what is physically present on the desk.

Sometimes a problem occurs when multiple symlinks in /dev/disk/by-path point to the same /dev/sd* device file - creating confusing results - for example the user inserts a device into port A, and ports A,B,C and D report inserted devices, while the user can see that these ports are physically empty.

I've created a one-liner that can check if this condition occurs:

file /dev/disk/by-path/* | grep -v "broken symbolic link" | cut -d'/' -f7 | sort | uniq -D | wc -l

This will return number of duplicated link destinations in /dev/disk/by-path.

It should return zero at all times.

Is there a way I can fix this without rebooting the system?

I've also asked a possibly related question: Broken links in /dev/disk/by-path

  • If all the disks are USB disks, this is a duplicate of your other question. – dirkt Oct 11 '18 at 9:24
  • Yes - they are all USB flash drives, but I deal with both broken links and duplicate links - they cause different problems. I can filter out broken links and just ignore them - but I can't do the same for the duplicated link destinations - that's why I made them two separate questions. – unfa Oct 11 '18 at 10:09
  • Both broken and duplicate links have the same reason: udev rules to remove them don't get run when the kernel doesn't generate the "remove" events. So the fix is the same: Remove all links (broken, duplicate, correct) if necessary; re-enumerate all USB devices, and create only the correct links via udev rules when re-enumerating. This won't work for links not belonging to USB devices (unless you reset their root controller, too), so don't delete those. – dirkt Oct 11 '18 at 10:13
  • I see. Would a udevadm trigger command re-enumarate the devices for me? – unfa Oct 11 '18 at 10:17
  • udevadm trigger would run the udev rules, but not actually enumerate the devices. Possibly you can also make some sort of solution with that, though. (Also, please write up whatever you end up doing in a single answer.) – dirkt Oct 11 '18 at 10:21

Your Answer

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

Browse other questions tagged or ask your own question.