# Trying to set up my first udev rule and failing.

## greedyfly

Following guide at http://www.reactivated.net/writing_udev_rules.html

using following as example

```
# udevinfo -a -p /sys/block/sda

  looking at device '/block/sda':

    KERNEL=="sda"

    SUBSYSTEM=="block"

    ATTR{stat}=="  128535     2246  2788977   766188    73998   317300  3132216  5735004        0   516516  6503316"

    ATTR{size}=="234441648"

    ATTR{removable}=="0"

    ATTR{range}=="16"

    ATTR{dev}=="8:0"

  looking at parent device '/devices/pci0000:00/0000:00:07.0/host0/target0:0:0/0:0:0:0':

    KERNELS=="0:0:0:0"

    SUBSYSTEMS=="scsi"

    DRIVERS=="sd"

    ATTRS{ioerr_cnt}=="0x0"

    ATTRS{iodone_cnt}=="0x31737"

    ATTRS{iorequest_cnt}=="0x31737"

    ATTRS{iocounterbits}=="32"

    ATTRS{timeout}=="30"

    ATTRS{state}=="running"

    ATTRS{rev}=="3.42"

    ATTRS{model}=="ST3120827AS     "

    ATTRS{vendor}=="ATA     "

    ATTRS{scsi_level}=="6"

    ATTRS{type}=="0"

    ATTRS{queue_type}=="none"

    ATTRS{queue_depth}=="1"

    ATTRS{device_blocked}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:07.0':

    KERNELS=="0000:00:07.0"

    SUBSYSTEMS=="pci"

    DRIVERS=="sata_nv"

    ATTRS{vendor}=="0x10de"

    ATTRS{device}=="0x037f"

 As you can see, udevinfo simply produces a list of attributes you can use as-is as match keys in your udev rules. From the above example, I could produce (e.g.) either of the following two rules for this device: 

SUBSYSTEM=="block", ATTR{size}=="234441648", NAME="my_hard_disk"
```

so i do the following on my system

```
udevinfo -a -p /sys/bus/usb-serial/devices/ttyUSB0

Udevinfo starts with the device specified by the devpath and then

walks up the chain of parent devices. It prints for every device

found, all possible attributes in the udev rules key format.

A rule to match, can be composed by the attributes of the device

and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0':

    KERNEL=="ttyUSB0"

    SUBSYSTEM=="usb-serial"

    DRIVER=="cp2101"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0':

    KERNELS=="2-2:1.0"

    SUBSYSTEMS=="usb"

    DRIVERS=="cp2101"

    ATTRS{interface}=="CP2102 USB to UART Bridge Controller"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2':

    KERNELS=="2-2"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb"

    ATTRS{serial}=="0001"

    ATTRS{product}=="CP2102 USB to UART Bridge Controller"

    ATTRS{manufacturer}=="Silicon Labs"

    ATTRS{quirks}=="0x0"

    ATTRS{maxchild}=="0"

    ATTRS{version}==" 1.10"

    ATTRS{devnum}=="7"

    ATTRS{busnum}=="2"

    ATTRS{speed}=="12"

    ATTRS{bMaxPacketSize0}=="64"

    ATTRS{bNumConfigurations}=="1"

    ATTRS{bDeviceProtocol}=="00"

    ATTRS{bDeviceSubClass}=="00"

    ATTRS{bDeviceClass}=="00"

    ATTRS{bcdDevice}=="0100"

    ATTRS{idProduct}=="ea60"

    ATTRS{idVendor}=="10c4"

    ATTRS{bMaxPower}=="100mA"

    ATTRS{bmAttributes}=="80"

    ATTRS{bConfigurationValue}=="1"

    ATTRS{bNumInterfaces}==" 1"

    ATTRS{configuration}==""

    ATTRS{dev}=="189:134"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2':

    KERNELS=="usb2"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb"

    ATTRS{serial}=="0000:00:1d.0"

    ATTRS{product}=="UHCI Host Controller"

    ATTRS{manufacturer}=="Linux 2.6.23-hardened-r2_PhosZoe uhci_hcd"

    ATTRS{quirks}=="0x0"

    ATTRS{maxchild}=="2"

    ATTRS{version}==" 1.10"

    ATTRS{devnum}=="1"

    ATTRS{busnum}=="2"

    ATTRS{speed}=="12"

    ATTRS{bMaxPacketSize0}=="64"

    ATTRS{bNumConfigurations}=="1"

    ATTRS{bDeviceProtocol}=="00"

    ATTRS{bDeviceSubClass}=="00"

    ATTRS{bDeviceClass}=="09"

    ATTRS{bcdDevice}=="0206"

    ATTRS{idProduct}=="0000"

    ATTRS{idVendor}=="0000"

    ATTRS{bMaxPower}=="  0mA"

    ATTRS{bmAttributes}=="e0"

    ATTRS{bConfigurationValue}=="1"

    ATTRS{bNumInterfaces}==" 1"

    ATTRS{configuration}==""

    ATTRS{dev}=="189:128"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0':

    KERNELS=="0000:00:1d.0"

    SUBSYSTEMS=="pci"

    DRIVERS=="uhci_hcd"

    ATTRS{msi_bus}==""

    ATTRS{broken_parity_status}=="0"

    ATTRS{enable}=="1"

    ATTRS{modalias}=="pci:v00008086d000024C2sv00000E11sd000000B8bc0Csc03i00"

    ATTRS{local_cpus}=="ffffffff"

    ATTRS{irq}=="20"

    ATTRS{class}=="0x0c0300"

    ATTRS{subsystem_device}=="0x00b8"

    ATTRS{subsystem_vendor}=="0x0e11"

    ATTRS{device}=="0x24c2"

    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':

    KERNELS=="pci0000:00"

    SUBSYSTEMS==""

    DRIVERS==""

```

and write the following rule

```
cat /etc/udev/rules.d/10-local.rules

SUBSYSTEM=="usb-serial",  DRIVER=="cp2101", SYMLINK+="vantagepro"

```

I try 

```
udevtest /sys/bus/usb-serial/devices/ttyUSB0

This program is for debugging only, it does not run any program,

specified by a RUN key. It may show incorrect results, because

some values may be different, or not available at a simulation run.

parse_file: reading '/etc/udev/rules.d/05-udev-early.rules' as rules file

parse_file: reading '/etc/udev/rules.d/10-local.rules' as rules file

parse_file: reading '/dev/.udev/rules.d/10-root-link.rules' as rules file

parse_file: reading '/etc/udev/rules.d/30-kernel-compat.rules' as rules file

parse_file: reading '/etc/udev/rules.d/40-alsa.rules' as rules file

parse_file: reading '/etc/udev/rules.d/40-gentoo.rules' as rules file

parse_file: reading '/etc/udev/rules.d/40-video.rules' as rules file

parse_file: reading '/etc/udev/rules.d/50-udev-default.rules' as rules file

parse_file: reading '/etc/udev/rules.d/60-cdrom_id.rules' as rules file

parse_file: reading '/etc/udev/rules.d/60-persistent-input.rules' as rules file

parse_file: reading '/etc/udev/rules.d/60-persistent-storage-tape.rules' as rules file

parse_file: reading '/etc/udev/rules.d/60-persistent-storage.rules' as rules file

parse_file: reading '/etc/udev/rules.d/61-persistent-storage-edd.rules' as rules file

parse_file: reading '/etc/udev/rules.d/64-device-mapper.rules' as rules file

parse_file: reading '/etc/udev/rules.d/65-permissions.rules' as rules file

parse_file: reading '/etc/udev/rules.d/70-persistent-cd.rules' as rules file

parse_file: reading '/etc/udev/rules.d/70-persistent-net.rules' as rules file

parse_file: reading '/etc/udev/rules.d/75-cd-aliases-generator.rules' as rules file

parse_file: reading '/etc/udev/rules.d/75-persistent-net-generator.rules' as rules file

parse_file: reading '/etc/udev/rules.d/80-drivers.rules' as rules file

parse_file: reading '/etc/udev/rules.d/90-network.rules' as rules file

parse_file: reading '/etc/udev/rules.d/95-udev-late.rules' as rules file

import_uevent_var: import into environment: 'DRIVER=cp2101'

import_uevent_var: import into environment: 'PHYSDEVBUS=usb-serial'

import_uevent_var: import into environment: 'PHYSDEVDRIVER=cp2101'

udevtest: looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0' from subsystem 'usb-serial'

wait_for_sysfs: file '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0/bus' appeared after 0 loops

udevtest: run: 'socket:/org/kernel/udev/monitor'

```

but it doesn't work for me. I can't see what I am doing wrong, can you?

from plugging and unplugging in vain...

```

cp2101 ttyUSB0: cp2101 converter now disconnected from ttyUSB0

cp2101 2-2:1.0: device disconnected

usb 2-2: new full speed USB device using uhci_hcd and address 6

usb 2-2: configuration #1 chosen from 1 choice

cp2101 2-2:1.0: cp2101 converter detected

usb 2-2: reset full speed USB device using uhci_hcd and address 6

usb 2-2: cp2101 converter now attached to ttyUSB0

usb 2-2: USB disconnect, address 6

cp2101 ttyUSB0: cp2101 converter now disconnected from ttyUSB0

cp2101 2-2:1.0: device disconnected

usb 2-2: new full speed USB device using uhci_hcd and address 7

usb 2-2: configuration #1 chosen from 1 choice

cp2101 2-2:1.0: cp2101 converter detected

usb 2-2: reset full speed USB device using uhci_hcd and address 7

usb 2-2: cp2101 converter now attached to ttyUSB0

```

----------

## jcat

have you restarted udev with 

```
udevstart
```

?

Cheers,

jcat

----------

## greedyfly

yes but I get...

```
bash: udevstart: command not found

```

I reemerged udev and still no udevstart available

Thanks for the quick response tho.  :Smile: 

----------

## jcat

You need to be "root"   :Smile:  then it should work.

If you're using sudo instead of su, then maybe you need to specify the path, so...

```
/sbin/udevstart
```

Cheers,

jcat

----------

## PaulBredbury

 *greedyfly wrote:*   

> udevstart: command not found

 

Depends on udev version. Later versions don't have "udevstart".

----------

## greedyfly

there is no /sbin/udevstart

I also ran a locate -u and can't locate udevstart. 

I am logged in as root and when I emerged the package I saw udevstart.o flash by but for some reason it is not available to me  :Sad: 

----------

## greedyfly

 *PaulBredbury wrote:*   

>  *greedyfly wrote:*   udevstart: command not found 
> 
> Depends on udev version. Later versions don't have "udevstart".

 

using udev-117

----------

## jcat

I'm on 115-r1, so I'm not sure what to tell you know   :Wink: 

Paul, can you enlighten us as to the correct way to restart udev without the udevstart command in the most recent versions?

If all else fails, just kill the udevd process, and start it again with 

```
/sbin/udevd --daemon &
```

But I'm sure there's an official and better way..

Cheers,

jcat

----------

## PaulBredbury

Yep.

```
$ ps ax | grep udev

/sbin/udevd --daemon
```

So run:

```
killall udevd && udevd --daemon
```

----------

## greedyfly

Well, that doesn't work either. I am at a loss...

----------

## PaulBredbury

So Googling for "udev debugging" returns zero results, does it...

----------

