Persistent symlinks for devices with udev

  1. Locate the device: /dev/usb/hiddev0
    root@misaka:~# ls /dev/usb/hiddev0  -l
    crw------- 1 root root 180, 0 Dec 19 13:00 /dev/usb/hiddev0
  2. Get device characteristics from udev.
    root@misaka:~# udevadm info --name=/dev/usb/hiddev0 --attribute-walk
    
    ...snip...
      
      looking at device '/devices/pci0000:00/0000:00:1d.1/usb9/9-2/9-2:1.0/usbmisc/hiddev0':
        KERNEL=="hiddev0"
        SUBSYSTEM=="usbmisc"
        DRIVER==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.1/usb9/9-2/9-2:1.0':
        KERNELS=="9-2:1.0"
        SUBSYSTEMS=="usb"
        DRIVERS=="usbhid"
        ...snip...
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.1/usb9/9-2':
        KERNELS=="9-2"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ...snip...
        ATTRS{idProduct}=="0002"
        ATTRS{idVendor}=="051d"
        ATTRS{ltm_capable}=="no"
        ATTRS{manufacturer}=="APC"
        ATTRS{maxchild}=="0"
        ATTRS{product}=="Back-UPS 650 FW:822.A3.I USB FW:A3"
        ...snip...
      
      ...snip...
  3. Write udev rule
    /etc/udev/rules.d/99-apcups.rules
    ACTION=="add", SUBSYSTEM=="usbmisc", ATTRS{idProduct}=="0002", ATTRS{idVendor}=="051d", SYMLINK+="apcups"
  4. Reload udev
    root@misaka:~# udevadm control --reload-rules
  5. Try rules
    root@misaka:~# udevadm test --action=add $(udevadm info -q path -n /dev/usb/hiddev0)
    
    ... snip ...
    
    LINK 'apcups' /etc/udev/rules.d/99-apcups.rules:1
    handling device node '/dev/usb/hiddev0', devnum=c180:0, mode=0600, uid=0, gid=0
    preserve permissions /dev/usb/hiddev0, 020600, uid=0, gid=0
    preserve already existing symlink '/dev/char/180:0' to '../usb/hiddev0'
    found 'c180:0' claiming '/run/udev/links/\x2fapcups'
    creating link '/dev/apcups' to '/dev/usb/hiddev0'
    creating symlink '/dev/apcups' to 'usb/hiddev0'
    created db file '/run/udev/data/c180:0' for '/devices/pci0000:00/0000:00:1d.1/usb9/9-2/9-2:1.0/usbmisc/hiddev0'
    ACTION=add
    DEVLINKS=/dev/apcups
    DEVNAME=/dev/usb/hiddev0
    DEVPATH=/devices/pci0000:00/0000:00:1d.1/usb9/9-2/9-2:1.0/usbmisc/hiddev0
    MAJOR=180
    MINOR=0
    SUBSYSTEM=usbmisc
    UPOWER_BATTERY_TYPE=ups
    UPOWER_VENDOR=APC
    USEC_INITIALIZED=23088813
    Unload module index
    Unloaded link configuration context.
  6. Apply new rules
    root@misaka:~# udevadm trigger --sysname-match=hiddev0 --action=add --verbose
    /sys/devices/pci0000:00/0000:00:1d.1/usb9/9-2/9-2:1.0/usbmisc/hiddev0
    
    root@misaka:~# ls /dev/apcups -l
    lrwxrwxrwx 1 root root 11 Dec 20 01:00 /dev/apcups -> usb/hiddev0
Complete udev output in step 2

See Alsos