Fix the device path for a SCSI device with multiple HBA adapters

I was installing Bacula on my server, and I got the following problem: Because I have several SCSI adapters, something changed the enumeration order of the adapters, causing the SCSI devices to be enumerated in a different order. Now, for hard drives it is mostly a non-issue, as the uuid and LVM take care of mounting the correct partition on the right place. The exception to this is during boot, but that can be solved one way or another.

However, the situation is different for tape drives (and my autochanger). The change in order moved the generic SCSI device number, and swapped the number of both my tape drives. So it ended up in Bacula that the autochanger was not the autochanger, the tape drive of the autoloader was not the one in the changer, and the comands where sent to all the wrong devices. Besides changing the reference, I wanted to avoid this from happening again.

I searched and found some half broken references on how to fix this on debian using udev. Basically, it needs to create a symlink that is tied to an specific device. To do that, first we need to get an unique ID for each device. This we can get from the udev utilities as:

/lib/udev/scsi_id -g -u -s /dev/sgXX

where /dev/sgXX is the generic SCSI device for the device we want to identify. This returns a string that is unique for each device. After we do this for each device, we can add the corresponding rules in /etc/udev/rules.d/60-persistent-storage-tape.rules

For the changer

KERNEL=="sg[0-9]*", PROGRAM=="scsi_id -g -u -s $tempnode", \
RESULT=="CHANGER-ID", SYMLINK+="tape/changer0"

For each tape

KERNEL=="nst*[0-9]", \
PROGRAM=="scsi_id -g -u -s $tempnode", \

This will create the symlinks /dev/tape/changer0 and /dev/tape/lto0 for the changer and the tape, and we can use these symlinks safely from Bacula.

Leave a Reply

Your email address will not be published. Required fields are marked *