15

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?

Matt Clark
  • 655
  • 1
  • 8
  • 24
  • 1
    Reading all of the data wouldn't help you much in determining the remaining capacity. Capacity varies depending on wear on the tape heads and quality of the tape. If you do read all the data you'd actually get a better estimate by measuring how much time it took to read rather than counting the number of bytes you read. – kasperd Jul 15 '17 at 16:13
  • 1
    And then there's the compression and fake capacity issue... – Overmind Jan 16 '18 at 13:55
  • @Overmind Compression is optional, but yes if it is turned on you will get an even less usable result by simply counting the bytes you read from the tape. Even in that case my advice still stands. Reading the entire tape and measuring how much time it took does give a reasonable estimate of how much of the tape capacity has been used. I don't know what you mean by fake capacity. – kasperd Feb 13 '18 at 23:19
  • I mean the actual declared-by-the-manufacturer capacity of the tape is fake (usually twice the actual one). They say a specific capacity (i.e. 1.6TB at 2:1 compression ratio, which practically means that the tape is 0.8TB). It's like saying my 10TB WD gold HDD is 20TB because I archived my data there at 2:1 compression ratio. – Overmind Feb 14 '18 at 06:17

5 Answers5

3

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.

Dark
  • 232
  • 1
  • 10
0

Here is one more software solution: https://github.com/Kevin-Nakamoto/LTO-CM-Read

This is an open-source Linux bash script which allows us to read MAM information via SCSI command. This is a kind of software wrapper for "READ ATTRIBUTE" command that Andreas has already suggested in the previous post. All you have to do is to install sg3-utils or sg3_utils, and then run the script. You will see "Remaining Capacity In Partition" as well as "Maximum Capacity In Partition" as a result.

0

On Linux all you need is sg3-utils or sg3_utils (the name depends on the distro).

sg_read_attr gives you everything you want, namely attribute:

0x0000:       8       binary  Remaining capacity in partition [MiB]
0x0001:       8       binary  Maximum capacity in partition [MiB]

You can get all available attributes using

$ sg_read_attr -e                  
Attribute ID    Length  Format  Name
------------------------------------------
  0x0000:       8       binary  Remaining capacity in partition [MiB]
  0x0001:       8       binary  Maximum capacity in partition [MiB]
  0x0002:       8       binary  TapeAlert flags
  0x0003:       8       binary  Load count
  0x0004:       8       binary  MAM space remaining [B]
  0x0005:       8       ascii   Assigning organization
  0x0006:       1       binary  Format density code
  0x0007:       2       binary  Initialization count
  0x0008:       32      ascii   Volume identifier
  0x0009:       -1      binary  Volume change reference
  0x020a:       40      ascii   Density vendor/serial number at last load
  0x020b:       40      ascii   Density vendor/serial number at load-1
  0x020c:       40      ascii   Density vendor/serial number at load-2
  0x020d:       40      ascii   Density vendor/serial number at load-3
  0x0220:       8       binary  Total MiB written in medium life
  0x0221:       8       binary  Total MiB read in medium life
  0x0222:       8       binary  Total MiB written in current/last load
  0x0223:       8       binary  Total MiB read in current/last load
  0x0224:       8       binary  Logical position of first encrypted block
  0x0225:       8       binary  Logical position of first unencrypted block
                                after first encrypted block
  0x0340:       90      binary  Medium usage history
  0x0341:       60      binary  Partition usage history
  0x0400:       8       ascii   Medium manufacturer
  0x0401:       32      ascii   Medium serial number
  0x0402:       4       binary  Medium length [m]
  0x0403:       4       binary  Medium width [0.1 mm]
  0x0404:       8       ascii   Assigning organization
  0x0405:       1       binary  Medium density code
  0x0406:       8       ascii   Medium manufacture date
  0x0407:       8       binary  MAM capacity [B]
  0x0408:       1       binary  Medium type
  0x0409:       2       binary  Medium type information
  0x040a:       -1      unknown Numeric medium serial number
  0x0800:       8       ascii   Application vendor
  0x0801:       32      ascii   Application name
  0x0802:       8       ascii   Application version
  0x0803:       160     text    User medium text label
  0x0804:       12      ascii   Date and time last written
  0x0805:       1       binary  Text localization identifier
  0x0806:       32      ascii   Barcode
  0x0807:       80      text    Owning host textual name
  0x0808:       160     text    Media pool
  0x0809:       16      ascii   Partition user text label
  0x080a:       1       binary  Load/unload at partition
  0x080a:       16      ascii   Application format version
  0x080c:       -1      binary  Volume coherency information
  0x0820:       36      binary  Medium globally unique identifier
  0x0821:       36      binary  Media pool globally unique identifier

SA_value        Acronym Description
------------------------------------------
  0:            av      attribute values
  1:            al      attribute list
  2:            lvl     logical volume list
  3:            pl      partition list
  4:            smc     SMC-2 should define this
  5:            sa      supported attributes

To read the attributes:

# sg_read_attr -f 0x0 /dev/sg0
Remaining capacity in partition [MiB]: 587625
# sg_read_attr -f 0x1 /dev/sg0
Maximum capacity in partition [MiB]: 2499053
Mathieu
  • 101
  • 1
0

First of all: this is not going to be easy.

There is a chip in the tape cartridge that offers a wide variety of information. That chip is called MAM (media auxiliary memory). The information can be read using SCSI command "READ ATTRIBUTE" on the tape drive while the tape is loaded. One of the attributes is "REMAINING CAPACITY IN PARTITION". This contains the amount of bytes that can be written to the current tape partition. Which leads to the question: what is a tape partition? Recent versions of LTO (LTO 5 and newer) tapes can be partitioned (LTFS uses two partitions).

If your tape was partitioned, each of your partitions will have an amount of free space and you will need to loop over all partitions to get each partitions free space information.

If you want to know more about MAM, take a look at IBM's LTO-8 SCSI Reference that explains this in detail (section 6.5 starting on page 355 contains the interesting stuff). If you need a starting point on how to implement this, maybe you should take a look at maminfo or this issue in sg3_utils issue tracker.

I'm not sure this information is updated immediately after a write to the tape. Maybe it is only update on unmount which would make retrieving accurate information even harder. I'm also not sure how this behaves when you overwrite the tape. You'll probably have to figure this out on your own.

Andreas Rogge
  • 2,670
  • 10
  • 24
0

I am not sure but maybe i can offer you to use ibm's software ITDT , it has a lot of abilities to do on tape libraries and lto tapes , maybe you can have a look around that software , it has such ability as Retrieve and display cartridge usage and health information.