How to identify which scsi device is the tape media changer on Linux

How to identify which scsi device is the tape media changer on Linux

On a Linux server running RHEL or CentOS, when you have a Tape library connected to it. mtx and mt-st driver are the most popular driver for the scsi library.

You can run lsscsi to list these scsi devices:

# lsscsi
[0:2:0:0]    disk    DELL     PERC H730 Mini   4.27  /dev/sda 
[0:2:1:0]    disk    DELL     PERC H730 Mini   4.27  /dev/sdb 
[10:0:0:0]   cd/dvd  PLDS     DVD-ROM DU-8D5LH 3D51  /dev/sr0 
[11:0:0:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st1 
[11:0:0:1]   mediumx IBM      03584L32         1304  /dev/sch0
[11:0:1:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st0 
[11:0:1:1]   mediumx IBM      03584L32         1304  /dev/sch1
[11:0:2:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st3 
[11:0:3:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st4 
[12:0:0:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st2 
[12:0:1:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st5 
[12:0:2:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st6 
[12:0:3:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st7

As you can see there are two library media changer appeared in above output. and they are handled by Linux ch driver

Linux ch driver

# ls -l /dev/sch0
crw-rw---- 1 root cdrom 86, 0 Apr  3 11:27 /dev/sch0

However, mtx doesn’t seem to work with ch driver.

# mtx -f /dev/sch0 status
/dev/sch0 is not an sg device, or old sg driver

Question: How to use mtx to operate the media changer?

SCSI generic devices for media changer

Normally the tape drive operations use the mt-st package. While library operations use mtx, but mtx seems to expect a different driver than ch.

So, mtx functions only on “generic” SCSI devices. The /dev/sch0 device provided by the ch kernel driver is something of a red herring.

SCSI generic devices appear in /dev as sg*, to find out the one is for library media changer, run lsscsi command:

# lsscsi -g
[0:2:0:0]    disk    DELL     PERC H730 Mini   4.27  /dev/sda   /dev/sg0 
[0:2:1:0]    disk    DELL     PERC H730 Mini   4.27  /dev/sdb   /dev/sg1 
[10:0:0:0]   cd/dvd  PLDS     DVD-ROM DU-8D5LH 3D51  /dev/sr0   /dev/sg2 
[11:0:0:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st1   /dev/sg3 
[11:0:0:1]   mediumx IBM      03584L32         1304  /dev/sch0  /dev/sg4 
[11:0:1:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st0   /dev/sg5 
[11:0:1:1]   mediumx IBM      03584L32         1304  /dev/sch1  /dev/sg6 
[11:0:2:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st3   /dev/sg7 
[11:0:3:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st4   /dev/sg9 
[12:0:0:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st2   /dev/sg8 
[12:0:1:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st5   /dev/sg10
[12:0:2:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st6   /dev/sg11
[12:0:3:0]   tape    IBM      ULT3580-TD7      G9Q0  /dev/st7   /dev/sg12

So, as you can easily tell from above output, sg4 is the scsi generic device for the library changer

[11:0:0:1]   mediumx IBM      03584L32         1304  /dev/sch0  /dev/sg4

So as sg6

Take a try

# mtx -f /dev/sg4 status 
  Storage Changer /dev/changer:8 Drives, 1256 Slots ( 255 Import/Export )
Data Transfer Element 0:Full (Storage Element 2 Loaded):VolumeTag = S00001L7
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
Data Transfer Element 4:Empty
Data Transfer Element 5:Empty
Data Transfer Element 6:Empty
Data Transfer Element 7:Empty
      Storage Element 1:Full :VolumeTag=S00000L7
      Storage Element 2:Empty:VolumeTag=          

...

Usually you’d like to create a udev rule for the changer to have a persistant name for the media changer

KERNEL=="sg*", SUBSYSTEM=="scsi_generic", ATTRS{type}=="8", ENV{ID_SERIAL}=="<device Serial Number>", SYMLINK="changer"

You will see the library media changer appear like this

# ls -l /dev/changer
lrwxrwxrwx 1 root root 3 Apr  3 11:27 /dev/changer -> sg4

Then you are done.

 
Enjoyed this video?
How to identify which scsi device is the tape media changer on Linux
"No Thanks. Please Close This Box!"