# Help Creating a UDEV Rule [Solved]

## jschweg

I need a little help. I'm trying to write a udev rule to map /dev/sdb1 to /dev/WDusb and can't get it to work. After processing the rule and reloading udev, the device still appears in /dev as sdb1.

Here is the dump for udevinfo -a -p $(udevinfo -q path -n /dev/sdb)

```

 looking at device '/block/sdb':

    KERNEL=="sdb"

    SUBSYSTEM=="block"

    DRIVER==""

    ATTR{stat}=="     141     1155     2479     6484        0        0        0        0        0     6484     6484"

    ATTR{size}=="156301488"

    ATTR{removable}=="0"

    ATTR{range}=="16"

    ATTR{dev}=="8:16"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0':

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

    SUBSYSTEMS=="scsi"

    DRIVERS=="sd"

    ATTRS{ioerr_cnt}=="0x0"

    ATTRS{iodone_cnt}=="0x94"

    ATTRS{iorequest_cnt}=="0x94"

    ATTRS{iocounterbits}=="32"

    ATTRS{timeout}=="30"

    ATTRS{state}=="running"

    ATTRS{rev}=="0602"

    ATTRS{model}=="800BB External  "

    ATTRS{vendor}=="WD      "

    ATTRS{scsi_level}=="3"

    ATTRS{type}=="0"

    ATTRS{queue_type}=="none"

    ATTRS{queue_depth}=="1"

    ATTRS{device_blocked}=="0"

    ATTRS{max_sectors}=="240"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host3/target3:0:0':

    KERNELS=="target3:0:0"

    SUBSYSTEMS==""

    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/host3':

    KERNELS=="host3"

    SUBSYSTEMS==""

    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0':

    KERNELS=="1-1:1.0"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb-storage"

    ATTRS{modalias}=="usb:v1058p0404d0602dc00dsc00dp00ic08isc06ip50"

    ATTRS{bInterfaceProtocol}=="50"

    ATTRS{bInterfaceSubClass}=="06"

    ATTRS{bInterfaceClass}=="08"

    ATTRS{bNumEndpoints}=="02"

    ATTRS{bAlternateSetting}==" 0"

    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1':

    KERNELS=="1-1"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb"

    ATTRS{serial}=="57442D5743414D3944363530313239"

    ATTRS{product}=="External HDD"

    ATTRS{manufacturer}=="Western Digital"

    ATTRS{maxchild}=="0"

    ATTRS{version}==" 2.00"

    ATTRS{devnum}=="2"

    ATTRS{speed}=="480"

    ATTRS{bMaxPacketSize0}=="64"

    ATTRS{bNumConfigurations}=="1"

    ATTRS{bDeviceProtocol}=="00"

    ATTRS{bDeviceSubClass}=="00"

    ATTRS{bDeviceClass}=="00"

    ATTRS{bcdDevice}=="0602"

    ATTRS{idProduct}=="0404"

    ATTRS{idVendor}=="1058"

    ATTRS{bMaxPower}=="100mA"

    ATTRS{bmAttributes}=="c0"

    ATTRS{bConfigurationValue}=="1"

    ATTRS{bNumInterfaces}==" 2"

    ATTRS{configuration}==""

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

    KERNELS=="usb1"

    SUBSYSTEMS=="usb"

    DRIVERS=="usb"

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

    ATTRS{product}=="EHCI Host Controller"

    ATTRS{manufacturer}=="Linux 2.6.20-gentoo-r8 ehci_hcd"

    ATTRS{maxchild}=="6"

    ATTRS{version}==" 2.00"

    ATTRS{devnum}=="1"

    ATTRS{speed}=="480"

    ATTRS{bMaxPacketSize0}=="64"

    ATTRS{bNumConfigurations}=="1"

    ATTRS{bDeviceProtocol}=="01"

    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}==""

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

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

    SUBSYSTEMS=="pci"

    DRIVERS=="ehci_hcd"

    ATTRS{msi_bus}==""

    ATTRS{broken_parity_status}=="0"

    ATTRS{enable}=="1"

    ATTRS{modalias}=="pci:v00008086d000024CDsv00001043sd00008089bc0Csc03i20"

    ATTRS{local_cpus}=="ff"

    ATTRS{irq}=="17"

    ATTRS{class}=="0x0c0320"

    ATTRS{subsystem_device}=="0x8089"

    ATTRS{subsystem_vendor}=="0x1043"

    ATTRS{device}=="0x24cd"

    ATTRS{vendor}=="0x8086"

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

    KERNELS=="pci0000:00"

    SUBSYSTEMS==""

    DRIVERS==""

```

Here is my udev rule:

```

SUBSYSTEMS=="usb", ATTRS{serial}=="57442D5743414D3944363530313239", NAME="WDusb"

```

It isn't making a match. Can anyone tell me what I'm doing wrong?Last edited by jschweg on Tue Jun 05, 2007 1:35 pm; edited 1 time in total

----------

## desultory

Have you tried using SYMLINK instead of NAME?

----------

## PaulBredbury

Specify which file this rule has been placed in. The order that the udev rules are processed is important - read man udev.

 *Quote:*   

>        NAME
> 
>            The name of the node to be created, or the name the network
> 
>            interface should be renamed to. Only one rule can set the node
> ...

 

So put it in /etc/udev/rules.d/10-local.rules - or better still, use SYMLINK instead:

```
SUBSYSTEMS=="usb", ATTRS{serial}=="57442D5743414D3944363530313239", SYMLINK+="wdusb"
```

I wouldn't use upper-case characters - see any in /dev?

----------

## jschweg

The rule was originally placed in /etc/udev/rules.d/10-local.rules

Good point on the lowercase, I will try that, along with changing the name to symlink instead. I'll have to wait until I get back later since I forgot to power up the drive before I left this morning.

----------

## jschweg

Okay, if I use SYMLINK instead of NAME, it does indeed create a symlink to sdb1, so the rule is properly matching. The problem is that I need the actual device node to be called wdhdd, which is why I was trying to use NAME.

My ipod and my external USB drive both fight over sdb, and if both are plugged in, my ipod is the only one that works. If I could tell them to use a different device node, like wdhdd and ipod, I could put them in my fstab and everything would be happy.

----------

## PaulBredbury

 *jschweg wrote:*   

> The problem is that I need the actual device node to be called wdhdd, which is why I was trying to use NAME.

 

What is this "need"? Kindly explain your need. A symlink is all I've needed.

 *Quote:*   

> My ipod and my external USB drive both fight over sdb

 

Then refine your udev rules. Or at least show them, so that other people can criticize them  :Wink: 

----------

## jschweg

 *PaulBredbury wrote:*   

> 
> 
> What is this "need"? Kindly explain your need. A symlink is all I've needed.
> 
> 

 

I guess my perceived need was that if both devices were fighting over the same device node, I would write some rules to seperate them. If I plug in my ipod, it grabs sdb. If I then plug in my hdd, nothing happens, and nothing gets added to dev. If I unplug my ipod, then plug in my hdd, it grabs sdb.

If I'm going about this wrong, then maybe a better question would be, what am I supposed to be doing to resolve this?

 *PaulBredbury wrote:*   

> 
> 
> Then refine your udev rules. Or at least show them, so that other people can criticize them 
> 
> 

 

Other than the the rule I was trying to write above, I haven't touched the anything else.

----------

## PaulBredbury

Write udev rules for SYMLINK+="petname", and ignore whether their NAME is sdb or sdc. In /etc/fstab you can refer to /dev/petname.

Check that this is blank:

```
grep sdb /etc/udev/rules.d/*
```

----------

## jschweg

 *PaulBredbury wrote:*   

> Write udev rules for SYMLINK+="petname", and ignore whether their NAME is sdb or sdc. In /etc/fstab you can refer to /dev/petname.
> 
> Check that this is blank:
> 
> ```
> ...

 

Yes, this comes back blank.

----------

## desultory

 *jschweg wrote:*   

> My ipod and my external USB drive both fight over sdb, and if both are plugged in, my ipod is the only one that works. If I could tell them to use a different device node, like wdhdd and ipod, I could put them in my fstab and everything would be happy.

 Have you checked whether a block device was created under a name you were not expecting when both devices are connected (try using ls /sys/block), without having any custom udev rules for either device? Have you checked for the presence of links for both devices under /dev/disk? If you have, please post your findings.

----------

## jschweg

Sorry, was away this weekend. I will check this later.

----------

## jschweg

Ok.

If both of the devices are plugged in, the ipod grabs sdb and can be seen under both /dev/disks and /sys/block. The USB HDD appears nowhere. If I unplug the ipod and fire up the HDD, it then grabs sdb and is shown under /dev/disks and /sys/block.

boo.

----------

## PaulBredbury

 *jschweg wrote:*   

> The USB HDD appears nowhere.

 

That would very much surprise me, although it is possible with e.g. OPTIONS="ignore_device". How about plugging it in and then immediately:

```
ls -ltr /dev
```

And then look at the bottom part of the listing.

Anyway, just debug it.

----------

## jschweg

Finally Success.

There must have been some type of conflict. I ended up moving one of the devices to a different USB port and they are now both being detected at the same time, and it doesn't matter which one gets pugged in first. Now I can use symlink and everything works perfectly. Final rules are below.

```

SUBSYSTEMS=="usb", KERNEL=="sd?1", ATTRS{serial}=="57442D5743414D3944363530313239", SYMLINK+="wdhdd"

SUBSYSTEMS=="usb", KERNEL=="sd?", ATTRS{serial}=="000A27001141D4FD", SYMLINK+="ipod"

```

Thanks for all of your help everyone  :Smile: 

----------

