Determine remaining capacity of LTO tape

ltotape

How can I determine how much space is remaining on an LTO tape?

If I seek to the end and check the status, I can see I am on file number 17, but what I do not know is how large each file was.

$ mt -f /dev/nst1 eod
$ mt -f /dev/nst1 status
SCSI 2 tape drive:
File number=17, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x44 (LTO-3).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN

Short of reading the entire strip, how can I determine the used / free capacity of the tape?

Best Answer

You can find the remaining tape capacity in the SCSI logs, along with many other interesting tidbits such as compression ratio, read/write failures, drive/tape history, etc.

sg_logs -a /dev/nst1

This utility is available in distro packages commonly named sg3-utils or sg3_utils.

You're looking for lines such as:

  • Main partition remaining capacity (in MiB)
  • Megabytes written to tape (subtract from uncompressed capacity)
  • Data bytes written to media by WRITE commands (subtract from uncompressed capacity)

Failing that, you can try vendor-specific tools. For example HP has HPE Library & Tape Tools, which works on all HP-compatible* drives. Buried in its menus you can find the ability to create and view a report of a drive which offers all the info found in sg_logs and more.


And failing all that, you can just write incompressible data until the end of tape and do the maths on the blocks written to figure what was remaining (goes without saying this is a bit nasty):

dd if=/dev/urandom of=/dev/nst1 bs=1M status=progress iflag=fullblock

or

openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero | dd of=/dev/nst1 bs=1M status=progress iflag=fullblock


I've used nst1 throughout this answer as that is the device in the original question, update as necessary.

Related Topic