# How to populate /dev/tape/by-id?

## charlesnadeau

I recently hooked 2 SCSI tape backup units and 2 SCSI tape libraries to one of my machines.

After every reboot, the order of the devices as reported by lsscsi changes. Right now it is:

```

Mosix3 rules.d # lsscsi

[0:0:6:0]    tape    HP       C1537A           L706  /dev/st0

[0:0:8:0]    tape    QUANTUM  DLT7000          1E46  /dev/st1

[1:0:0:0]    disk    ATA      ST3500630AS      3.AA  /dev/sda

[4:0:0:0]    disk    ATA      ST3500630AS      3.AA  /dev/sdb

[5:0:0:0]    disk    ATA      ST3300831AS      3.02  /dev/sdc

[6:0:0:0]    mediumx HP       C7145-8000       206S  /dev/sch0

[6:0:1:0]    tape    QUANTUM  DLT8000          0114  /dev/st2

[7:0:0:0]    mediumx DEC      TL800    (C) DEC 0525  /dev/sch1

[7:0:4:0]    tape    DEC      TZ89     (C) DEC 2561  /dev/st3

[7:0:5:0]    tape    DEC      TZ89     (C) DEC 2561  /dev/st4

[8:0:0:0]    disk    OPNFILER VIRTUAL-DISK     0     /dev/sdd

```

But sometimes the top two SCSI drives appear at the bottom of the list shifting up the other tapes by 2.

The problem is that when the order changes, the units refered to in my bacula configuration files change. I would like to refer to my units using /dev/tape/by-id/ as the SCSI ID of the units doesn't change from boot to boot. Upon booting, udev populate /dev/tape/by-path/ but not /dev/tape/by-id/.

Why?

My /etc/udev/rules.d/60-persistent-storage-tape.rules is

```

Mosix3 rules.d # cat /etc/udev/rules.d/60-persistent-storage-tape.rules

# do not edit this file, it will be overwritten on update

# persistent storage links: /dev/tape/{by-id,by-path}

ACTION!="add|change", GOTO="persistent_storage_tape_end"

# type 8 devices are "Medium Changers"

KERNEL=="sg[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", SYMLINK+="tape/by-id/scsi-$env{ID_SERIAL}"

SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"

KERNEL=="st*[0-9]", ATTRS{ieee1394_id}=="?*", ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394"

KERNEL=="st*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", IMPORT{program}="usb_id --export %p"

KERNEL=="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", KERNELS=="[0-9]*:*[0-9]", ENV{BSG_DEV}="$root/bsg/$id"

KERNEL=="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", WAIT_FOR="$env{BSG_DEV}", IMPORT="scsi_id --whitelisted --export --device=$env{BSG_DEV}", ENV{ID_BUS}="scsi"

KERNEL=="st*[0-9]",  ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"

KERNEL=="nst*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-nst"

# by-path (shortest physical path)

KERNEL=="st*[0-9]", IMPORT{program}="path_id %p"

KERNEL=="st*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH}"

LABEL="persistent_storage_tape_end"

```

Should I change anything in this file?

Where are the rules related to /dev/sg*? I would like to refer to my tape libraries by a permanent path too.

Thanks!

Charles

----------

## jomateix

Take a look at this, should be pretty clear what to do: http://www.reactivated.net/writing_udev_rules.html

----------

## charlesnadeau

jomateix,

I looked at the document you are refering to, it is very well written.

I don't think I'll need to write new/more udev rules. I just wonder why these rules

```

# type 8 devices are "Medium Changers"

KERNEL=="sg[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", SYMLINK+="tape/by-id/scsi-$env{ID_SERIAL}"

KERNEL=="st*[0-9]",  ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"

KERNEL=="nst*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-nst"

```

do not trigger the creation of entries in /dev/tape/by-id/.

My problem is simillar to this one. It seems udev 122 fixes this issue but I am not 100% sure.

Thanks!

Charles

----------

