# udev rule for e-SATA HDD drive via PCMCIA

## djanderson

Hi, I just bought a new e-SATA HDD case, 200GB HDD, and a PCMCIA e-SATA controller.

I'm going to write/modify a backup script because my laptop is getting a little old and I've put way too much time into customizing packages to start over from scratch like I used to.

All the hardware works wonderfully and the HDD is automatically detected and assigned to /dev/sdb. I have two partitions on the drive, one for backups and one for other stuff.

```
# fdisk -l /dev/sdb

Disk /dev/sdb: 200.0 GB, 200049647616 bytes

255 heads, 63 sectors/track, 24321 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x15721e5c

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1       14590   117194143+  83  Linux

/dev/sdb2           14591       24321    78164257+  83  Linux

```

I want to write a custom udev rule to mount the drive as "esata" so that my script has a consistent device name to mount. I have read tons of stuff on gentoo-wiki and gotten suggestions from people on IRC #gentoo, but there's one unresolved issue. 

If I use this line:

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

# Automount Hitachi Travelstar 7200rpm 200GB on e-SATA

BUS=="scsi", ATTRS{model}=="Hitachi HTS72202", SYMLINK="esata"

```

then the symlink esata will be created with no numbers, like this:

```
$ ls /dev | egrep "esata|sdb"

esata

sdb

sdb1

sdb2

```

But if I use this line:

```
# Automount Hitachi Travelstar 7200rpm 200GB on e-SATA

BUS=="scsi", ATTRS{model}=="Hitachi HTS72202", SYMLINK="esata%n"
```

I will get: 

```
$ ls /dev | egrep "esata|sdb"

esata

esata0

esata1

esata2

sdb

sdb1

sdb2

```

I don't understand why that extra "esata0" is there... it probably doesn't really matter but I don't like it  :Smile:  I want it to go away.

It exhibits the same problem if I use NAME instead of SYMLINK or if I use SYMLINK+= instead of SYMLINK=... 

One last small issue. In my udev rule I'm identifying the HDD by its model, which is not as specific as I'd like to be. I'd like to identify it by its serial number, but udevinfo doesn't give me very much info:

```
$ udevinfo -a -p /sys/block/sdb/

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:1e.0/0000:0b:00.0/0000:0c:00.0/host3/target3:0:0/3:0:0:0/block/sdb':

    KERNEL=="sdb"

    SUBSYSTEM=="block"

    DRIVER==""

    ATTR{range}=="16"

    ATTR{removable}=="0"

    ATTR{size}=="390721968"

    ATTR{capability}=="12"

    ATTR{stat}=="      60     1416     2036      802        0        0        0        0        0      740      802"

  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:0b:00.0/0000:0c:00.0/host3/target3:0:0/3:0:0:0/block':

    KERNELS=="block"

    SUBSYSTEMS==""

    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:0b:00.0/0000:0c:00.0/host3/target3:0:0/3:0:0:0':

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

    SUBSYSTEMS=="scsi"

    DRIVERS=="sd"

    ATTRS{device_blocked}=="0"

    ATTRS{type}=="0"

    ATTRS{scsi_level}=="6"

    ATTRS{vendor}=="ATA     "

    ATTRS{model}=="Hitachi HTS72202"

    ATTRS{rev}=="DC4O"

    ATTRS{state}=="running"

    ATTRS{timeout}=="60"

    ATTRS{iocounterbits}=="32"

    ATTRS{iorequest_cnt}=="0x4a"

    ATTRS{iodone_cnt}=="0x4a"

    ATTRS{ioerr_cnt}=="0x0"

    ATTRS{modalias}=="scsi:t-0x00"

    ATTRS{evt_media_change}=="0"

    ATTRS{queue_depth}=="1"

    ATTRS{queue_type}=="none"

```

I can find the serial number with hdparm -I but udev is so picky about every single character being exactly as udev sees it that I haven't been able to get it to work. blkid or scsi_id doesn't return anything on the drive. Possibly because it's going through the PCMCIA controller?

Any hints appreciated!

-Doug

----------

## astaecker

Use the symlinks in /dev/disk/by-*

----------

## djanderson

That's neat  :Smile:  Thanks...

----------

