Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm working on setting up a system where I want to have certain devices always named the same way when they are plugged into certain ports. I originally set up a udev rules file with the devices plugged directly into the computer. So I had rules like:

ACTION=="add", KERNEL=="<namePattern>", KERNELS=="7-3", SYMLINK+="<newName>"

where 7-3 specified a specific USB port on a PCI card in the computer (I figured out the numbers for each port using dmesg or udevadm info -q path -n <deviceName>).

However, I now need to plug the devices into a USB hub to allow them to be further away from the computer. When I plug the USB hub into that same port, it shows up under the number 4-5 instead of 7-3, which confuses me. So, devices plugged into the hub end up under numbers like 4-5.2 instead of 7-3.2 like I would have expected.

As I understand it, the first number before the dash indicates which USB bus the device is on, while the string of numbers after the dash indicate the port number for each successive hub that the device is plugged into. So, it doesn't make sense to me why those numbers would suddenly change to 4-5 when I plug a hub in when they've always been 7-3 for everything else I've plugged into that port. I would expect the earlier numbers to stay the same, but with an extra port number tacked on to the end to indicate that it's going through another USB hub.

Given that the first hub is numbered 4-5, the numbering does follow my expectations when I daisy chain a second hub in. I end up with devices under numbers like 4-5.2.x or 4-5.3.x depending on which port on the first hub that I plug the second hub into. So, the 4-5 part stays the same, while the port numbers on the first and second hubs get tacked on.

I'm wondering why the first hub shows up with the number 4-5 instead of 7-3 like everything else plugged into that port? Apparently, I'm missing part of the understanding of how the numbering works in different situations.

Update: I played around with the system some more, and it turns out that the weird renumbering only happens when I plug the USB hub into one of the ports on the PCI card. When I plug it into the ports on the motherboard (or on front of the computer, which just goes to the mobo anyway), it keeps the same numbers as I would expect. I still don't understand why this would happen even with the PCI card, but at least the renumbering appears to be consistent. So, I can still set up rules that will work. If anyone has any good intuition on what's happening, I'm still curious to understand what's going on.

share|improve this question
    
No idea, but I'm going to guess that it has something to do with the fact that you're adding a new hub, not just a device. –  Joe Aug 21 '13 at 19:36
    
If your devices are disk drives,they get assigned unique uuids when the partitions are formatted. You can use those to access the devices uniquely wherever they get plugged in. You can also find them by their partition labels (good reason to use human readable labels). Check out /dev/disk/by-uuid and /dev/disk/by-label using ls -l to see what's where. I don't know of anything similar for non-disk devices, but there may be something in hal land that can help you. I have bash functions I can post for dealing with disk labels and uuids if that would help. –  Joe Aug 21 '13 at 19:43
    
Again, for disk devices only, you can also add entries for them to /etc/fstab using their uuids and control whether and how they get mounted when plugged in. That's a whole separate question/answer to cover the details, but it's not too complicated. –  Joe Aug 21 '13 at 19:48
    
@Joe The devices are cameras and weatherboards, not disk drives. I'm thinking it's just some kind of weird (and possibly buggy) behavior being exhibited by the PCI card since it doesn't happen when I plug the hubs into ports on the mobo. As I understand it, the fact that it's a hub shouldn't change earlier numbers, but just tack a new one on the end. For example, I can plug a device into port 2-1.1 on the mobo. Or I can plug the hub into port 2-1.1 and plug the device into port 2 on the hub, in which case the device gets listed under port number 2-1.1.2. –  Brandon Aug 21 '13 at 21:40
1  
@fabby I'm don't remember what the PCI cards were off the top of my head, but could perhaps dig that information up if I remember to. I have occasionally seen the hub boot up under 7-3 instead of 4-5 despite not changing any of the configuration. I figured it might be caused by some randomness in the order in which devices initialized or something, but the PCI card dynamically recognizing a hub and adjusting accordingly seems to make sense as well. Making udev rules that covered both cases ensured it would always work regardless. –  Brandon 16 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.