Know your tape library with mtx and mt

These two commands are very useful to interact with your library and check its current status independently of the CTA layer. The mtx command controls single or multi-drive SCSI media changers such as tape libraries. The mt-st command performs tape operations on tape drives and can modify some of their settings.

The mtx command

First of all, let's find out the device number of our scsi medium changer (mediumx). The last column should be something like/dev/sgX:

lsscsi -g | grep mediumx

If you already configured the udev rules on your tapeserver (See: Udev rules), you can also use /dev/smc to refer to your scsi media changer instead, as it will be linked to your device. If not, all of the commands below work simply with /dev/sgX.

  • With the mtx command, we can check the basic information of our library (product type, vendor, ID...) with:

# mtx -f /dev/smc inquiry
  • We can also check status of the library:

# mtx -f /dev/smc status

This command reports how many drives and storage elements are contained in the device. For each drive, reports whether it has media loaded in it, and if so, from which storage slot the media originated. See the following output as an example:

mtx -f /dev/sg2 status
  Storage Changer /dev/sg2:2 Drives, 280 Slots ( 255 Import/Export )
Data Transfer Element 0:Full (Storage Element 4 Loaded):VolumeTag = V03650L8
Data Transfer Element 1:Empty
      Storage Element 1:Full :VolumeTag=V03648L8
      Storage Element 2:Full :VolumeTag=V03647L8
      Storage Element 3:Full :VolumeTag=V03646L8
      Storage Element 4:Empty:VolumeTag=                                    
      Storage Element 5:Full :VolumeTag=V03649L8

We can see two drives (or Data Transfer Elements". First one is loaded with the tape V03650, and the second one is empty. The Storage Elements are tape slots. The ones shown in the example are all full except slot 4, as this tape is currently loaded on one of the drives.

We can perform other tape operations with mtx:

  • Load a tape from an slot (storage element) into an empty drive (data transfer element). Note: Drive 0 is assumed if the drive number is ommited (as do all commands!)

# mtx -f  /dev/smc load <slotnum> <drivenum>
# mtx -f  /dev/smc load 1 0 #Load the tape of the storage element 1 into the first drive (data transfer element 0)
  • Unload a tape from a drive into an empty slot:

# mtx -f  /dev/smc unload <slotnum> <drivenum>
# mtx -f  /dev/smc unload 1 0 #Unload the drive 0, put the media into slot 1

The mt-st command

Your tape drives also have a scsi device name to refer to. Lists your devices, and it should be /dev/nstX. Note that if the tape drive is busy doing something else, this commands won't work.

  • You can check the status of the drive with:

# mt -f /dev/nst0 status
  • If there is a tape inside the drive, we can rewind the tape:

# mt -f /dev/nst0 rewind
  • And then read the first block from the tape:

# dd if=/dev/nst0 bs=262144 count=1
  • Finally we can eject the tape:

# mt -f /dev/nst0 eject
  • We can also modify some tape drive settings with this command. For example, set the default compression on/off. However, if you have an IBM library, I recommend you using the ITDT tool to change compression or other settings (See: The IBM Tape Diagnostic Tool):

mt -f /dev/nst0 defcompression [0-1]
  • You can check some of your current drive settings in the following directory: /sys/class/scsi_tape/nstX/

Useful links:

Last updated